示例#1
0
        /// <summary>
        /// Example of how to create a M21 Dfs2 Bathymetry from scratch. This method
        /// creates a file matching the OresundBathy900.dfs2 test file.
        /// </summary>
        /// <param name="bathyDataArray">Array of bathymetry data, 1D array with 2D data, size n x m</param>
        /// <param name="filename">Path and name of the new file to create</param>
        public static void CreateM21Bathymetry(float[] bathyDataArray, string filename)
        {
            DfsFactory  factory = new DfsFactory();
            Dfs2Builder builder = Dfs2Builder.Create(@"C:\0\Training\Bat1_0.dfs2", @"Grid editor", 1);

            // Set up the header
            builder.SetDataType(0);
            builder.SetGeographicalProjection(factory.CreateProjectionGeoOrigin("UTM-33", 12.438741600559911, 55.2257078424238, 327));
            builder.SetTemporalAxis(factory.CreateTemporalEqCalendarAxis(eumUnit.eumUsec, new DateTime(2003, 01, 01, 0, 0, 0), 0, 1));
            builder.SetSpatialAxis(factory.CreateAxisEqD2(eumUnit.eumUmeter, 72, 0, 900, 94, 0, 900));
            builder.DeleteValueFloat = -1e-30f;

            builder.AddCustomBlock(factory.CreateCustomBlock("Display Settings", new int[] { 1, 0, 0 }));
            builder.AddCustomBlock(factory.CreateCustomBlock("M21_Misc", new float[] { 327f, 0f, -900f, 10f, 0f, 0f, 0f }));

            // Set up dynamic items
            builder.AddDynamicItem("Bathymetry", eumQuantity.Create(eumItem.eumIWaterLevel, eumUnit.eumUmeter),
                                   DfsSimpleType.Float, DataValueType.Instantaneous);

            // Create and get file
            builder.CreateFile(filename);
            Dfs2File file = builder.GetFile();

            // Add bathymetry data
            file.WriteItemTimeStepNext(0, bathyDataArray);

            file.Close();
        }
示例#2
0
        /// <summary>
        /// Example of how to create a Dfs2 file from scratch. This method
        /// creates a copy of the OresundHD.dfs2 test file.
        /// <para>
        /// Data for static and dynamic item is taken from a source dfs file,
        /// which here is the OresundHD.dfs2 test file. The data could come
        /// from any other source.
        /// </para>
        /// </summary>
        /// <param name="sourceFilename">Path and name of the OresundHD.dfs2 test file</param>
        /// <param name="filename">Path and name of the new file to create</param>
        public static void CreateDfs2File(string sourceFilename, string filename)
        {
            IDfs2File source = DfsFileFactory.Dfs2FileOpen(sourceFilename);

            DfsFactory  factory = new DfsFactory();
            Dfs2Builder builder = Dfs2Builder.Create("", @"C:\Program Files\DHI\2010\bin\nmodel.exe", 0);

            // Set up the header
            builder.SetDataType(1);
            builder.SetGeographicalProjection(factory.CreateProjectionGeoOrigin("UTM-33", 12.438741600559766, 55.225707842436385, 326.99999999999955));
            builder.SetTemporalAxis(factory.CreateTemporalEqCalendarAxis(eumUnit.eumUsec, new DateTime(1993, 12, 02, 0, 0, 0), 0, 86400));
            builder.SetSpatialAxis(factory.CreateAxisEqD2(eumUnit.eumUmeter, 71, 0, 900, 91, 0, 900));
            builder.DeleteValueFloat = -1e-30f;

            // Add custom block
            // M21_Misc : {orientation (should match projection), drying depth, -900=has projection, land value, 0, 0, 0}
            builder.AddCustomBlock(factory.CreateCustomBlock("M21_Misc", new float[] { 327f, 0.2f, -900f, 10f, 0f, 0f, 0f }));

            // Set up dynamic items
            builder.AddDynamicItem("H Water Depth m", eumQuantity.Create(eumItem.eumIWaterLevel, eumUnit.eumUmeter), DfsSimpleType.Float, DataValueType.Instantaneous);
            builder.AddDynamicItem("P Flux m^3/s/m", eumQuantity.Create(eumItem.eumIFlowFlux, eumUnit.eumUm3PerSecPerM), DfsSimpleType.Float, DataValueType.Instantaneous);
            builder.AddDynamicItem("Q Flux m^3/s/m", eumQuantity.Create(eumItem.eumIFlowFlux, eumUnit.eumUm3PerSecPerM), DfsSimpleType.Float, DataValueType.Instantaneous);

            // Create file
            builder.CreateFile(filename);

            // Add static items containing bathymetri data, use data from source
            IDfsStaticItem sourceStaticItem = source.ReadStaticItemNext();

            builder.AddStaticItem("Static item", eumQuantity.UnDefined, sourceStaticItem.Data);

            // Get the file
            Dfs2File file = builder.GetFile();

            // Loop over all time steps
            for (int i = 0; i < source.FileInfo.TimeAxis.NumberOfTimeSteps; i++)
            {
                // Loop over all items
                for (int j = 0; j < source.ItemInfo.Count; j++)
                {
                    // Add data for all item-timesteps, copying data from source file.

                    // Read data from source file
                    IDfsItemData2D <float> sourceData = (IDfsItemData2D <float>)source.ReadItemTimeStepNext();

                    // Create empty item data, and copy over data from source
                    // The IDfsItemData2D can handle 2D indexing, on the form data2D[k,l].
                    // An ordinary array, float[], can also be used, though indexing from 2D to 1D must be
                    // handled by user code i.e. using data1D[k + l*xCount] compared to data2D[k,l]
                    IDfsItemData2D <float> itemData2D = (IDfsItemData2D <float>)file.CreateEmptyItemData(j + 1);
                    for (int k = 0; k < 71; k++)
                    {
                        for (int l = 0; l < 91; l++)
                        {
                            itemData2D[k, l] = sourceData[k, l];
                        }
                    }
                    // the itemData2D.Data is a float[], so any float[] of the correct size is valid here.
                    file.WriteItemTimeStep(j + 1, i, sourceData.Time, itemData2D.Data);
                }
            }

            source.Close();
            file.Close();
        }
示例#3
0
        /// <summary> Write dfs2 file </summary>
        private void Write(string dfsFilename, string projectionString)
        {
            DfsFactory  factory = new DfsFactory();
            Dfs2Builder builder = new Dfs2Builder();

            // Data type
            builder.SetDataType(0);

            // Projection and spatial axis
            double lon0; double lat0; double dx; double dy;
            int    flip;

            FindAxisProperties(out lon0, out lat0, out dx, out dy, out flip);
            builder.SetGeographicalProjection(factory.CreateProjectionGeoOrigin(projectionString, lon0, lat0, 0));
            builder.SetSpatialAxis(factory.CreateAxisEqD2(eumUnit.eumUdegree, _dimensions[0], 0, dx, _dimensions[1], 0, dy));

            // Time axis
            eumUnit  timeUnit;
            DateTime startDateTime;
            double   timeStep;

            FindTimeProperties(out timeUnit, out startDateTime, out timeStep);
            builder.SetTemporalAxis(factory.CreateTemporalEqCalendarAxis(timeUnit, startDateTime, 0, timeStep));

            // Add dynamic items
            foreach (Variable item in _items)
            {
                eumQuantity quantity = GetQuantityFromItem(item);
                builder.AddDynamicItem(item.Name, quantity, DfsSimpleType.Float, DataValueType.Instantaneous);
            }

            // Create and get file (no static items there)
            builder.CreateFile(dfsFilename);
            Dfs2File dfs2File = builder.GetFile();

            // Write data to file
            int itemSize = _dimensions[0] * _dimensions[1];

            float[] values        = new float[itemSize];
            float[] valuesFlipped = new float[itemSize];
            for (int i = 0; i < _time.Array.Length; i++)
            {
                for (int j = 0; j < _items.Count; j++)
                {
                    // Time of time step
                    double time = (double)_time.Array.GetValue(i);
                    // Values for all time steps
                    float[] allfloats = (float[])_items[j].Array;
                    // Copy single time step data from allFloats to values
                    Array.Copy(allfloats, i * itemSize, values, 0, itemSize);
                    // Flip values, if necessary
                    float[] actual;
                    if (flip == 0)
                    {
                        actual = values;
                    }
                    else
                    {
                        PerformFlip(flip, values, valuesFlipped);
                        actual = valuesFlipped;
                    }
                    // Save values to file
                    dfs2File.WriteItemTimeStepNext(time, actual);
                }
            }
            dfs2File.Close();
        }
示例#4
0
        /// <summary>
        /// Creates a dfs0 file, with an equidistant time axis and one dynamic item.
        /// <para>
        /// It uses the generic <see cref="DfsBuilder"/>, since currently no specialized
        /// builder exists for the dfs0 files.
        /// </para>
        /// </summary>
        /// <param name="filename">Name of new file</param>
        /// <param name="calendarAxis">boolean specifying whether the temporal axis should be a calendar axis or a time axis</param>
        public static void CreateDfs0FileFromArray(string filename, bool calendarAxis)
        {
            DfsFactory factory = new DfsFactory();
            DfsBuilder builder = DfsBuilder.Create("TemporalAxisTest", "dfs Timeseries Bridge", 10000);

            // Set up file header
            builder.SetDataType(1);
            builder.SetGeographicalProjection(factory.CreateProjectionUndefined());
            if (calendarAxis)
            {
                builder.SetTemporalAxis(factory.CreateTemporalEqCalendarAxis(eumUnit.eumUsec, new DateTime(2010, 01, 04, 12, 34, 00), 4, 10));
            }
            else
            {
                builder.SetTemporalAxis(factory.CreateTemporalEqTimeAxis(eumUnit.eumUsec, 3, 10));
            }
            builder.SetItemStatisticsType(StatType.RegularStat);

            // Set up first item
            DfsDynamicItemBuilder item1 = builder.CreateDynamicItemBuilder();

            item1.Set("WaterLevel item", eumQuantity.Create(eumItem.eumIWaterLevel, eumUnit.eumUmeter),
                      DfsSimpleType.Float);
            item1.SetValueType(DataValueType.Instantaneous);
            item1.SetAxis(factory.CreateAxisEqD0());
            item1.SetReferenceCoordinates(1f, 2f, 3f);
            builder.AddDynamicItem(item1.GetDynamicItemInfo());

            DfsDynamicItemBuilder item2 = builder.CreateDynamicItemBuilder();

            item2.Set("WaterDepth item", eumQuantity.Create(eumItem.eumIWaterDepth, eumUnit.eumUmeter),
                      DfsSimpleType.Float);
            item2.SetValueType(DataValueType.Instantaneous);
            item2.SetAxis(factory.CreateAxisEqD0());
            item2.SetReferenceCoordinates(1f, 2f, 3f);
            builder.AddDynamicItem(item2.GetDynamicItemInfo());

            // Create file
            builder.CreateFile(filename);
            IDfsFile file = builder.GetFile();

            // Time is not important, since it is equidistant
            double[] times = new double[10];
            double[,] values = new double[10, 2];

            // Write data to file
            values[0, 0] = 0f;   // water level
            values[0, 1] = 100f; // water depth
            values[1, 0] = 1f;   // water level
            values[1, 1] = 101f; // water depth
            values[2, 0] = 2f;   // water level
            values[2, 1] = 102f; // water depth
            values[3, 0] = 3f;   // etc...
            values[3, 1] = 103f;
            values[4, 0] = 4f;
            values[4, 1] = 104f;
            values[5, 0] = 5f;
            values[5, 1] = 105f;
            values[6, 0] = 10f;
            values[6, 1] = 110f;
            values[7, 0] = 11f;
            values[7, 1] = 111f;
            values[8, 0] = 12f;
            values[8, 1] = 112f;
            values[9, 0] = 13f;
            values[9, 1] = 113f;

            DHI.Generic.MikeZero.DFS.dfs0.Dfs0Util.WriteDfs0DataDouble(file, times, values);

            file.Close();
        }
示例#5
0
        /// <summary>
        /// Creates a dfs0 file, with an equidistant time axis and one dynamic item.
        /// <para>
        /// It uses the generic <see cref="DfsBuilder"/>, since currently no specialized
        /// builder exists for the dfs0 files.
        /// </para>
        /// </summary>
        /// <param name="filename">Name of new file</param>
        /// <param name="calendarAxis">boolean specifying whether the temporal axis should be a calendar axis or a time axis</param>
        public static void CreateDfs0File(string filename, bool calendarAxis)
        {
            DfsFactory factory = new DfsFactory();
            DfsBuilder builder = DfsBuilder.Create("TemporalAxisTest", "dfs Timeseries Bridge", 10000);

            // Set up file header
            builder.SetDataType(1);
            builder.SetGeographicalProjection(factory.CreateProjectionUndefined());
            if (calendarAxis)
            {
                builder.SetTemporalAxis(factory.CreateTemporalEqCalendarAxis(eumUnit.eumUsec, new DateTime(2010, 01, 04, 12, 34, 00), 4, 10));
            }
            else
            {
                builder.SetTemporalAxis(factory.CreateTemporalEqTimeAxis(eumUnit.eumUsec, 3, 10));
            }
            builder.SetItemStatisticsType(StatType.RegularStat);

            // Set up first item
            DfsDynamicItemBuilder item1 = builder.CreateDynamicItemBuilder();

            item1.Set("WaterLevel item", eumQuantity.Create(eumItem.eumIWaterLevel, eumUnit.eumUmeter),
                      DfsSimpleType.Float);
            item1.SetValueType(DataValueType.Instantaneous);
            item1.SetAxis(factory.CreateAxisEqD0());
            item1.SetReferenceCoordinates(1f, 2f, 3f);
            builder.AddDynamicItem(item1.GetDynamicItemInfo());

            DfsDynamicItemBuilder item2 = builder.CreateDynamicItemBuilder();

            item2.Set("WaterDepth item", eumQuantity.Create(eumItem.eumIWaterDepth, eumUnit.eumUmeter),
                      DfsSimpleType.Float);
            item2.SetValueType(DataValueType.Instantaneous);
            item2.SetAxis(factory.CreateAxisEqD0());
            item2.SetReferenceCoordinates(1f, 2f, 3f);
            builder.AddDynamicItem(item2.GetDynamicItemInfo());

            // Create file
            builder.CreateFile(filename);
            IDfsFile file = builder.GetFile();

            // Write data to file
            file.WriteItemTimeStepNext(0, new float[] { 0f });   // water level
            file.WriteItemTimeStepNext(0, new float[] { 100f }); // water depth
            file.WriteItemTimeStepNext(0, new float[] { 1f });   // water level
            file.WriteItemTimeStepNext(0, new float[] { 101f }); // water depth
            file.WriteItemTimeStepNext(0, new float[] { 2f });   // water level
            file.WriteItemTimeStepNext(0, new float[] { 102f }); // water depth
            file.WriteItemTimeStepNext(0, new float[] { 3f });   // etc...
            file.WriteItemTimeStepNext(0, new float[] { 103f });
            file.WriteItemTimeStepNext(0, new float[] { 4f });
            file.WriteItemTimeStepNext(0, new float[] { 104f });
            file.WriteItemTimeStepNext(0, new float[] { 5f });
            file.WriteItemTimeStepNext(0, new float[] { 105f });
            file.WriteItemTimeStepNext(0, new float[] { 10f });
            file.WriteItemTimeStepNext(0, new float[] { 110f });
            file.WriteItemTimeStepNext(0, new float[] { 11f });
            file.WriteItemTimeStepNext(0, new float[] { 111f });
            file.WriteItemTimeStepNext(0, new float[] { 12f });
            file.WriteItemTimeStepNext(0, new float[] { 112f });
            file.WriteItemTimeStepNext(0, new float[] { 13f });
            file.WriteItemTimeStepNext(0, new float[] { 113f });

            file.Close();
        }
示例#6
0
        /// <summary>
        /// Example on how to extract dfs0 data from a 2D dfsu file for certain elements. All items
        /// from dfsu file are extracted.
        /// </summary>
        /// <param name="dfsuFileNamePath">Name, including path, of 2D dfsu file</param>
        /// <param name="elmtsIndices">Indices of elements to extract data from</param>
        /// <param name="useStream">Use stream when writing dfs0 files - then more than 400 files can be created simultaneously</param>
        public static void ExtractDfs0FromDfsu(string dfsuFileNamePath, IList <int> elmtsIndices, bool useStream)
        {
            // If not using stream approach, at most 400 elements at a time can be processed.
            // There is a limit on how many files you can have open at the same time using
            // the standard approach. It will fail in a nasty way, if the maximum number of
            // file handles are exceeded. This is not an issue when using .NET streams.
            if (!useStream && elmtsIndices.Count > 400)
            {
                throw new ArgumentException("At most 400 elements at a time");
            }

            // Open source dfsu file
            IDfsuFile source;
            Stream    stream = null;

            if (useStream)
            {
                stream = new FileStream(dfsuFileNamePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                source = DfsuFile.Open(stream);
            }
            else
            {
                source = DfsuFile.Open(dfsuFileNamePath);
            }

            // Figure out "basic" dfs0 file name
            string dfsuFilename     = Path.GetFileNameWithoutExtension(dfsuFileNamePath);
            string path             = Path.GetDirectoryName(dfsuFileNamePath);
            string dfs0BaseFilename = Path.Combine(path, "test_" + dfsuFilename + "-");

            // Factory for creating dfs objects
            DfsFactory factory = new DfsFactory();

            // Create a dfs0 file for each element in elmtsIndices
            DfsFile[] dfs0Files   = new DfsFile[elmtsIndices.Count];
            Stream[]  dfs0Streams = new Stream [elmtsIndices.Count];
            double    timeSpan    = source.TimeStepInSeconds * source.NumberOfTimeSteps;

            for (int k = 0; k < elmtsIndices.Count; k++)
            {
                // Index of element to create dfs0 for
                int elmtsIndex = elmtsIndices[k];

                // Calculate element center coordinates, to be stored in dfs0 items.
                // Stored as float in dfs0, hence possible loss of precision...
                float x = 0, y = 0, z = 0;
                int[] nodeNumbers = source.ElementTable[elmtsIndex];
                for (int i = 0; i < nodeNumbers.Length; i++)
                {
                    int nodeIndex = nodeNumbers[i] - 1; // from number to index
                    x += (float)source.X[nodeIndex];
                    y += (float)source.Y[nodeIndex];
                    z += source.Z[nodeIndex];
                }
                x /= nodeNumbers.Length;
                y /= nodeNumbers.Length;
                z /= nodeNumbers.Length;

                // Start building dfs0 file header
                DfsBuilder builder = DfsBuilder.Create("fileTitle", "appTitle", 1);
                builder.SetDataType(1); // standard dfs0 value
                builder.SetGeographicalProjection(source.Projection);
                builder.SetTemporalAxis(factory.CreateTemporalEqCalendarAxis(eumUnit.eumUsec, source.StartDateTime, 0, source.TimeStepInSeconds));

                // Add all dynamic items from dfsu file to dfs0 file
                for (int j = 0; j < source.ItemInfo.Count; j++)
                {
                    IDfsSimpleDynamicItemInfo sourceItem  = source.ItemInfo[j];
                    DfsDynamicItemBuilder     itemBuilder = builder.CreateDynamicItemBuilder();
                    itemBuilder.Set(sourceItem.Name, sourceItem.Quantity, sourceItem.DataType);
                    itemBuilder.SetAxis(factory.CreateAxisEqD0());
                    itemBuilder.SetValueType(sourceItem.ValueType);
                    itemBuilder.SetReferenceCoordinates(x, y, z); // optional
                    builder.AddDynamicItem(itemBuilder.GetDynamicItemInfo());
                }


                // Create and get file, store them in dfs0s array
                string dfs0Filename = dfs0BaseFilename + (elmtsIndex).ToString("000000") + ".dfs0";
                if (useStream)
                {
                    // Create file using C# streams - necessary to provie number of time steps and timespan of data
                    builder.SetNumberOfTimeSteps(source.NumberOfTimeSteps);
                    builder.SetTimeInfo(0, timeSpan);
                    Stream dfs0FileStream = new FileStream(dfs0Filename, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
                    builder.CreateStream(dfs0FileStream);
                    dfs0Streams[k] = dfs0FileStream;
                }
                else
                {
                    // Create file in the ordinary way. Will include statistics (of delete values etc).
                    builder.CreateFile(dfs0Filename);
                }
                dfs0Files[k] = builder.GetFile();
            }

            // For performance, use predefined itemdata objects when reading data from dfsu
            IDfsItemData <float>[] dfsuItemDatas = new IDfsItemData <float> [source.ItemInfo.Count];
            for (int j = 0; j < source.ItemInfo.Count; j++)
            {
                dfsuItemDatas[j] = (IDfsItemData <float>)source.ItemInfo[j].CreateEmptyItemData();
            }

            // Read data from dfsu and store in dfs0
            float[] dfs0Data = new float[1];
            for (int i = 0; i < source.NumberOfTimeSteps; i++)
            {
                for (int j = 0; j < source.ItemInfo.Count; j++)
                {
                    // Read data from dfsu
                    IDfsItemData <float> dfsuItemData = dfsuItemDatas[j];
                    bool    ok     = source.ReadItemTimeStep(dfsuItemData, i);
                    float[] floats = dfsuItemData.Data;

                    // write data to dfs0's
                    for (int k = 0; k < elmtsIndices.Count; k++)
                    {
                        int elmtsIndex = elmtsIndices[k];
                        dfs0Data[0] = floats[elmtsIndex];
                        dfs0Files[k].WriteItemTimeStepNext(0, dfs0Data);
                    }
                }
            }

            // Close dfsu files
            source.Close();
            if (stream != null)
            {
                stream.Close();
            }
            // Close all dfs0 files
            for (int k = 0; k < elmtsIndices.Count; k++)
            {
                dfs0Files[k].Close();
                if (dfs0Streams[k] != null)
                {
                    dfs0Streams[k].Close();
                }
            }
        }
示例#7
0
        public bool GenerateWebTideNode(TVFileModel TVFileModelBC, int WebTideNodeNumb, List <Coord> CoordList, List <TVFileModel> tvFileModelList, int BoundaryConditionCodeNumber, List <List <WaterLevelResult> > AllWLResults, List <IEnumerable <CurrentResult> > AllCurrentResults)
        {
            List <eumItem> eumItemList = new List <eumItem>();

            DfsFactory factory = new DfsFactory();

            IDfsFile dfsOldFile = DfsFileFactory.DfsGenericOpen(TVFileModelBC.ServerFilePath + TVFileModelBC.ServerFileName);

            DfsBuilder dfsNewFile = DfsBuilder.Create(dfsOldFile.FileInfo.FileTitle, dfsOldFile.FileInfo.ApplicationTitle, dfsOldFile.FileInfo.ApplicationVersion);

            double WebTideStepsInMinutes = ((double)((IDfsEqCalendarAxis)((dfsOldFile.FileInfo).TimeAxis)).TimeStep / 60);

            DateTime?dateTimeTemp      = null;
            int?     NumberOfTimeSteps = null;
            int?     TimeStepInterval  = null;

            using (PFS pfs = new PFS(base.fi))
            {
                dateTimeTemp = pfs.GetVariableDateTime("FemEngineHD/TIME", "start_time");
                if (dateTimeTemp == null)
                {
                    dfsOldFile.Close();
                    return(false);
                }

                NumberOfTimeSteps = pfs.GetVariable <int>("FemEngineHD/TIME", "number_of_time_steps", 1);
                if (NumberOfTimeSteps == null)
                {
                    dfsOldFile.Close();
                    return(false);
                }

                TimeStepInterval = pfs.GetVariable <int>("FemEngineHD/TIME", "time_step_interval", 1);
                if (TimeStepInterval == null)
                {
                    dfsOldFile.Close();
                    return(false);
                }
            }

            DateTime StartDate = ((DateTime)dateTimeTemp).AddHours(-1);
            DateTime EndDate   = ((DateTime)dateTimeTemp).AddSeconds((int)NumberOfTimeSteps * (int)TimeStepInterval).AddHours(1);

            dfsNewFile.SetDataType(dfsOldFile.FileInfo.DataType);
            dfsNewFile.SetGeographicalProjection(dfsOldFile.FileInfo.Projection);
            dfsNewFile.SetTemporalAxis(factory.CreateTemporalEqCalendarAxis(eumUnit.eumUsec, StartDate, 0, WebTideStepsInMinutes * 60));
            dfsNewFile.SetItemStatisticsType(StatType.RegularStat);

            foreach (IDfsDynamicItemInfo di in dfsOldFile.ItemInfo)
            {
                DfsDynamicItemBuilder ddib = dfsNewFile.CreateDynamicItemBuilder();
                ddib.Set(di.Name, eumQuantity.Create(di.Quantity.Item, di.Quantity.Unit), di.DataType);
                ddib.SetValueType(di.ValueType);
                ddib.SetAxis(factory.CreateAxisEqD1(eumUnit.eumUsec, CoordList.Count, 0, 1));
                ddib.SetReferenceCoordinates(di.ReferenceCoordinateX, di.ReferenceCoordinateY, di.ReferenceCoordinateZ);
                dfsNewFile.AddDynamicItem(ddib.GetDynamicItemInfo());
                eumItemList.Add(di.Quantity.Item);
            }

            dfsOldFile.Close();

            string[]      NewFileErrors = dfsNewFile.Validate();
            StringBuilder sbErr         = new StringBuilder();

            foreach (string s in NewFileErrors)
            {
                sbErr.AppendLine(s);
            }

            if (NewFileErrors.Count() > 0)
            {
                ErrorMessage = string.Format(CSSPDHIRes.CouldNotCreate_, TVFileModelBC.ServerFileName.Replace(".dfs0", "dfs1"));
                OnCSSPDHIChanged(new CSSPDHIEventArgs(new CSSPDHIMessage("Error", -1, false, ErrorMessage)));
                return(false);
            }

            string NewFileNameBC = TVFileModelBC.ServerFileName;

            if (CoordList.Count == 0)
            {
                ErrorMessage = CSSPDHIRes.NumberOfWebTideNodesIsZero;
                OnCSSPDHIChanged(new CSSPDHIEventArgs(new CSSPDHIMessage("Error", -1, false, ErrorMessage)));
                return(false);
            }

            if (eumItemList.Count == 1)
            {
                if (eumItemList[0] == eumItem.eumIWaterLevel || eumItemList[0] == eumItem.eumIWaterDepth)
                {
                    List <WaterLevelResult> WLResults = null;

                    dfsNewFile.CreateFile(TVFileModelBC.ServerFilePath + NewFileNameBC);
                    IDfsFile file = dfsNewFile.GetFile();
                    for (int i = 0; i < WLResults.ToList().Count; i++)
                    {
                        float[] floatArray = new float[AllWLResults.Count];

                        for (int j = 0; j < AllWLResults.Count; j++)
                        {
                            floatArray[j] = ((float)((List <WaterLevelResult>)AllWLResults[j].ToList())[i].WaterLevel);
                        }



                        file.WriteItemTimeStepNext(0, floatArray);  // water level array
                    }
                    file.Close();
                }
                else
                {
                    ErrorMessage = string.Format(CSSPDHIRes.FileContainsOneParamButItsNotOfTypeWLOrWDItIs_, eumItemList[0].ToString());
                    OnCSSPDHIChanged(new CSSPDHIEventArgs(new CSSPDHIMessage("Error", -1, false, ErrorMessage)));
                    return(false);
                }
            }
            else if (eumItemList.Count == 2)
            {
                if (eumItemList[0] == eumItem.eumIuVelocity && eumItemList[1] == eumItem.eumIvVelocity)
                {
                    // read web tide for the required time
                    List <CurrentResult> CurrentResults = null;

                    dfsNewFile.CreateFile(TVFileModelBC.ServerFilePath + NewFileNameBC);
                    IDfsFile file = dfsNewFile.GetFile();
                    for (int i = 0; i < CurrentResults.ToList().Count; i++)
                    {
                        float[] floatArrayX = new float[AllCurrentResults.Count];
                        float[] floatArrayY = new float[AllCurrentResults.Count];

                        for (int j = 0; j < AllCurrentResults.Count; j++)
                        {
                            floatArrayX[j] = ((float)((List <CurrentResult>)AllCurrentResults[j].ToList())[i].x_velocity);
                            floatArrayY[j] = ((float)((List <CurrentResult>)AllCurrentResults[j].ToList())[i].y_velocity);
                        }

                        file.WriteItemTimeStepNext(0, floatArrayX);  // Current xVelocity
                        file.WriteItemTimeStepNext(0, floatArrayY);  // Current yVelocity
                    }
                    file.Close();
                }
                else
                {
                    ErrorMessage = string.Format(CSSPDHIRes.FileContains2ParamButItsNotOfUVAndVVItIs_And_, eumItemList[0].ToString(), eumItemList[1].ToString());
                    OnCSSPDHIChanged(new CSSPDHIEventArgs(new CSSPDHIMessage("Error", -1, false, ErrorMessage)));
                    return(false);
                }
            }
            else
            {
                // this is not a file that is used for Water Level or Currents
            }

            return(false);
        }