コード例 #1
0
ファイル: ExamplesMisc.cs プロジェクト: DHI/MIKECore-Examples
        /// <summary>
        /// Example of how to append data from one file to another. It is assumed that:
        /// <list type="bullet">
        /// <item>The files has identical dynamic and static items</item>
        /// <item>The last time step of the target file is equal to the first
        ///       timestep of the sourceFile, and therefor the first time step
        ///       from the source file is not added to the target file</item>
        /// </list>
        /// <para>
        /// This example uses the generic DFS functionality, and will work for any type
        /// of DFS file.
        /// </para>
        /// </summary>
        public static void AppendToFile(string targetFile, string sourceFile)
        {
            // Open target for appending and source for reading
            IDfsFile target = DfsFileFactory.DfsGenericOpenAppend(targetFile);
            IDfsFile source = DfsFileFactory.DfsGenericOpen(sourceFile);

            // Time of last time step of file, in the time unit of the time axis.
            // This is sufficient as long as TimeAxis.StartTimeOffset equals in
            // source and target file (it is zero for most files)
            double targetEndTime = target.FileInfo.TimeAxis.TimeSpan();

            // Do not add initial time step 0 of source to target file,
            // so go directly to time step 1 in source
            source.FindTimeStep(1);

            // Copy over data
            IDfsItemData sourceData2;

            while (null != (sourceData2 = source.ReadItemTimeStepNext()))
            {
                target.WriteItemTimeStepNext(targetEndTime + sourceData2.Time, sourceData2.Data);
            }

            // Close the files
            target.Close();
            source.Close();
        }