Views:
 

Question
How can I change the start time of an existing dfs file?

Answer
You can edit the start time by opening the file in the related file editor, or open the file in MzDataUtility - see Fig. 1.

 

Fig. 1 - Time editing

 

If you need to change several files it may be feasible to use MIKE Core SDK to create a small tool that can update the start time for a given dfs file (dfs0/dfs1/dfs2/dfs3/dfsu).
This requires an input of 7 parameters: the filename of dfs file to be modified and the new start date and time (YYYY, MM, DD, hh, mm, ss).

 

An example of the source code for such a tool looks as follows:

 

using System;
using DHI.Generic.MikeZero.DFS;

namespace DHI.Generic.MikeZero.DFSTest
{  
   class Program
  {
      /// <summary>
      /// Static constructor, setting up search paths for MIKE assemblies
      /// </summary>
      static Program()
      {
          // The setup method will make your application find the MIKE assemblies at runtime.
          if (!DHI.Mike.Install.MikeImport.Setup(22, DHI.Mike.Install.MikeProducts.Mike1D))
               throw new Exception("Could not find a MIKE installation");
      }

      /// <summary>
      /// Updates the start time of a file with an <see cref="IDfsEqCalendarAxis"/> type time axis.
      /// </summary>
      /// <param name="filename path" and date and time information (YYYY, MM, DD, hh, mm, ss)</param>
      public static void Main(string[] args)
      {
         string filename = args[0];
         IDfsFile dfsFile = DfsFileFactory.DfsGenericOpenEdit(filename);
         IDfsEqCalendarAxis timeAxis = (IDfsEqCalendarAxis)dfsFile.FileInfo.TimeAxis;

         // Update values
         int year  = Int32.Parse(args[1]);
         int month = Int32.Parse(args[2]);
         int day = Int32.Parse(args[3]);
         int hour = Int32.Parse(args[4]);
         int min = Int32.Parse(args[5]);
         int sec = Int32.Parse(args[6]);
         timeAxis.StartDateTime = new DateTime(year, month, day, hour, min, sec);

         dfsFile.Close();
      }
    }
}

 

The build statement to create the executionable ‘ChangeStartTime.exe’ looks as follows:

 

set csc=C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe
set sdkBin=C:\Program Files (x86)\DHI\MIKE Core SDK\2024\\bin\x64
%csc% /r:"%sdkBin%\DHI.Generic.MikeZero.DFS.dll" /r:"%sdkBin%\DHI.Generic.MikeZero.EUM.dll" /r:"%sdkBin%\DHI.Mike.Install.dll" /r:"netstandard.dll"  ChangeStartTime.cs
pause

 

NOTE: This exe-file can be used to change the start date for a file via a simple command. E.g. to change the start date for the file “tide.dfsu” to February 24, 2016 12:30:00 the command would be:

ChangeStartDate.exe tide.dfsu 2016 2 24 12 30 0


FURTHER INFORMATION & USEFUL LINKS

Manuals and User Guides
MIKE Core SDK Documentation Index
MZ Data Utility Online help

Release Notes
MIKE Core SDK Release Note