Exemplo n.º 1
0
        /// <summary>
        /// Example on how to modify a custom block.
        /// <para>
        /// The method assumes that a dfs2 file with the "M21_Misc" custom block, alike
        /// the OresundHD.dfs2 test file, is the input file.
        /// </para>
        /// </summary>
        /// <param name="filename">path and name of dfs2 test file</param>
        public static void CustomBlockModify(string filename)
        {
            IDfsFile dfsFile = DfsFileFactory.DfsGenericOpenEdit(filename);

            IDfsFileInfo    fileInfo    = dfsFile.FileInfo;
            IDfsCustomBlock customBlock = fileInfo.CustomBlocks[0];

            customBlock[3] = 25;

            dfsFile.Close();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            int[] nodeNumber = new int[] { 899, 2686, 2856, 2866, 2331, 3806, 2231, 3831 };

            IDfsFile     resFile     = DfsFileFactory.DfsGenericOpenEdit(@"E:\FFWS\Model\MIKEHYDRO\GBM_MIKEHYDRO.mhydro - Result Files\RiverBasin_GBM.dfs0");
            IDfsFileInfo resfileInfo = resFile.FileInfo;
            int          noTimeSteps = resfileInfo.TimeAxis.NumberOfTimeSteps;

            DateTime[] date      = resFile.FileInfo.TimeAxis.GetDateTimes();
            DateTime   startDate = date[0];

            double[] timeSpan = new double[noTimeSteps];
            for (int j = 0; j < noTimeSteps; j++)
            {
                timeSpan[j] = resFile.ReadItemTimeStep(899, j).Time;
            }
            foreach (int element in nodeNumber)
            {
                IDfsItemData <float> data;
                float[] QSimvalues = new float[noTimeSteps];

                for (int j = 0; j < noTimeSteps; j++)
                {
                    data          = (IDfsItemData <float>)resFile.ReadItemTimeStep(element, j);
                    QSimvalues[j] = Convert.ToSingle(data.Data[0]);
                }

                DfsFactory factory     = new DfsFactory();
                string     filename    = @"E:\FFWS\Model\BrahmaputraHD\Boundary\" + element + ".dfs0";
                DfsBuilder filecreator = DfsBuilder.Create(element.ToString(), element.ToString(), 2014);
                filecreator.SetDataType(1);
                filecreator.SetGeographicalProjection(factory.CreateProjectionUndefined());
                filecreator.SetTemporalAxis(factory.CreateTemporalNonEqCalendarAxis(eumUnit.eumUsec, new DateTime(startDate.Year, startDate.Month, startDate.Day, startDate.Hour, startDate.Minute, startDate.Second)));
                filecreator.SetItemStatisticsType(StatType.RegularStat);
                DfsDynamicItemBuilder item = filecreator.CreateDynamicItemBuilder();
                item.Set(element.ToString(), eumQuantity.Create(eumItem.eumIDischarge, eumUnit.eumUm3PerSec), DfsSimpleType.Float);
                item.SetValueType(DataValueType.Instantaneous);
                item.SetAxis(factory.CreateAxisEqD0());
                item.SetReferenceCoordinates(1f, 2f, 3f);
                filecreator.AddDynamicItem(item.GetDynamicItemInfo());

                filecreator.CreateFile(filename);
                IDfsFile     file     = filecreator.GetFile();
                IDfsFileInfo fileinfo = file.FileInfo;

                for (int j = 0; j < noTimeSteps; j++)
                {
                    file.WriteItemTimeStepNext(timeSpan[j], new float[] { QSimvalues[j] });
                }
                file.Close();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Updates the temporal axis of a file with an <see cref="IDfsEqCalendarAxis"/>
        /// type time axis.
        /// <para>
        /// The method will work on a file like the OresundHD.dfs2 test file, which has
        /// an <see cref="IDfsEqCalendarAxis"/> type time axis.
        /// </para>
        /// </summary>
        /// <param name="filename">path and name of test file</param>
        public static void TemporalAxisModify(string filename)
        {
            IDfsFile           dfsFile  = DfsFileFactory.DfsGenericOpenEdit(filename);
            IDfsEqCalendarAxis timeAxis = (IDfsEqCalendarAxis)dfsFile.FileInfo.TimeAxis;

            // Update values
            timeAxis.FirstTimeStepIndex = 3;
            timeAxis.StartTimeOffset    = 6;
            timeAxis.StartDateTime      = new DateTime(2009, 2, 2, 21, 43, 00);
            timeAxis.TimeUnit           = eumUnit.eumUminute;
            timeAxis.TimeStep           = 1;

            dfsFile.Close();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Updates the item info.
        /// <para>
        /// The method assumes that the OresundHD.dfs2 test file
        /// (or preferably a copy of it) is the input file.
        /// </para>
        /// </summary>
        /// <param name="filename">path and name of OresundHD.dfs2 test file</param>
        public static void DynamicItemInfoModify(string filename)
        {
            IDfsFile dfsFile = DfsFileFactory.DfsGenericOpenEdit(filename);

            IDfsDynamicItemInfo itemInfo = dfsFile.ItemInfo[2];

            // Update the values
            // old name: "Q Flux m^3/s/m". New name: "ShortD        " (padded with spaces)
            // old quantity: (eumItem.eumIFlowFlux, eumUnit.eumUm3PerSecPerM)
            // old ValueType: Instantaneous
            itemInfo.Name      = "ShortD";
            itemInfo.Quantity  = eumQuantity.Create(eumItem.eumIDischarge, eumUnit.eumUm3PerSec);
            itemInfo.ValueType = DataValueType.MeanStepBackward;

            // Old reference coordinates and orientation is -1.00000002e-35f
            itemInfo.SetReferenceCoordinates(1, 2, 3);
            itemInfo.SetOrientation(4, 5, 6);

            dfsFile.Close();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Updates information in the header - <see cref="IDfsFileInfo"/>.
        /// <para>
        /// The method assumes that the OresundHD.dfs2 test file
        /// (or preferably a copy of it) is the input file.
        /// </para>
        /// <para>
        /// Strings are padded with zeros, when too short, and truncated when too long.
        /// </para>
        /// </summary>
        /// <param name="filename">path and name of OresundHD.dfs2 test file</param>
        public static void FileInfoModify(string filename)
        {
            IDfsFile dfsFile = DfsFileFactory.DfsGenericOpenEdit(filename);

            IDfsFileInfo fileInfo = dfsFile.FileInfo;

            // Modify values
            fileInfo.FileTitle          = "ups";
            fileInfo.ApplicationTitle   = "Short title";
            fileInfo.ApplicationVersion = 12;
            fileInfo.DataType           = 10101;

            fileInfo.DeleteValueFloat       = -5.5e-25f;
            fileInfo.DeleteValueByte        = 7;
            fileInfo.DeleteValueDouble      = -7.7e-114;
            fileInfo.DeleteValueInt         = -123456;
            fileInfo.DeleteValueUnsignedInt = 123456;

            dfsFile.Close();
        }
Exemplo n.º 6
0
        private void btnLoadNAM_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter = "Mike NAM Result Files|*.RES11";

            if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.Cancel)
            {
                fileName = dialog.FileName;
            }


            var filepath = fileName.Split('\\');

            dfs0Path = filepath[0];
            for (int i = 1; i < filepath.Length - 1; i++)
            {
                dfs0Path = dfs0Path + @"\" + filepath[i];
            }

            IDfsFile     resFile     = DfsFileFactory.DfsGenericOpenEdit(fileName);
            IDfsFileInfo resfileInfo = resFile.FileInfo;

            DateTime[] date      = resFile.FileInfo.TimeAxis.GetDateTimes();
            DateTime   startDate = date[0];

            IDfsItemData <float> data;
            int noTimeSteps = resfileInfo.TimeAxis.NumberOfTimeSteps;

            float[] values = new float[noTimeSteps];
            for (int i = 0; i < noTimeSteps; i++)
            {
                dfsDate.Add(startDate.AddHours(resFile.ReadItemTimeStep(1, i).Time));
            }

            for (int j = 0; j < resFile.ItemInfo.Count; j++)
            {
                IDfsSimpleDynamicItemInfo dynamicItemInfo = resFile.ItemInfo[j];
                string nameOftDynamicItem = dynamicItemInfo.Name;
                string checkname          = nameOftDynamicItem.Substring(0, 6);
                if (checkname == "RunOff")
                {
                    string     filename    = dfs0Path + @"\" + nameOftDynamicItem + ".dfs0";
                    DfsFactory factory     = new DfsFactory();
                    DfsBuilder filecreator = DfsBuilder.Create(nameOftDynamicItem, nameOftDynamicItem, 2014);
                    filecreator.SetDataType(1);
                    filecreator.SetGeographicalProjection(factory.CreateProjectionUndefined());
                    //filecreator.SetTemporalAxis(factory.CreateTemporalEqCalendarAxis(eumUnit.eumUsec, new DateTime(2010, 01, 01, 06, 00, 00), 0, 10800));
                    filecreator.SetTemporalAxis(factory.CreateTemporalNonEqCalendarAxis(eumUnit.eumUsec, new DateTime(dfsDate[0].Year, dfsDate[0].Month, dfsDate[0].Day, dfsDate[0].Hour, dfsDate[0].Minute, dfsDate[0].Second)));
                    filecreator.SetItemStatisticsType(StatType.RegularStat);
                    DfsDynamicItemBuilder item = filecreator.CreateDynamicItemBuilder();
                    item.Set(nameOftDynamicItem, eumQuantity.Create(eumItem.eumIDischarge, eumUnit.eumUm3PerSec), DfsSimpleType.Float);
                    item.SetValueType(DataValueType.Instantaneous);
                    item.SetAxis(factory.CreateAxisEqD0());
                    item.SetReferenceCoordinates(1f, 2f, 3f);
                    filecreator.AddDynamicItem(item.GetDynamicItemInfo());

                    filecreator.CreateFile(filename);
                    IDfsFile file = filecreator.GetFile();

                    for (int i = 0; i < noTimeSteps; i++)
                    {
                        data      = (IDfsItemData <float>)resFile.ReadItemTimeStep(j + 1, i);
                        values[i] = Convert.ToSingle(data.Data[0]);
                        file.WriteItemTimeStepNext((dfsDate[i] - dfsDate[0]).TotalSeconds, new float[] { values[i] });
                    }
                    file.Close();
                }
            }
        }