/// <summary> /// Writes timestep and starttime /// </summary> protected void WriteTime() { if (!_initializedForWriting) { InitializeForWriting(); } switch (_timeAxis) { case TimeAxisType.CalendarEquidistant: DfsDLLWrapper.dfsSetEqCalendarAxis(_headerPointer, TimeSteps.First().ToString("yyyy-MM-dd"), TimeSteps.First().ToString("HH:mm:ss"), (int)timeStepUnit, 0, _timeStep.TotalSeconds, 0); break; case TimeAxisType.CalendarNonEquidistant: DfsDLLWrapper.dfsSetNeqCalendarAxis(_headerPointer, TimeSteps.First().ToString("yyyy-MM-dd"), TimeSteps.First().ToString("HH:mm:ss"), (int)timeStepUnit, 0, 0); break; case TimeAxisType.TimeEquidistant: break; case TimeAxisType.TimeNonEquidistant: break; case TimeAxisType.Undefined: break; default: break; } }
/// <summary> /// Returns the zero-based index of the TimeStep closest to the TimeStamp. If the timestamp falls exactly between two timestep the smallest is returned. /// If the TimeStamp is before the first timestep 0 is returned. /// If the TimeStamp is after the last timestep the index of the last timestep is returned /// </summary> /// <param name="TimeStamp"></param> /// <returns></returns> public int GetTimeStep(DateTime TimeStamp) { if (TimeStamp < TimeSteps.First() || NumberOfTimeSteps == 1) { return(0); } int TimeStep; //fixed timestep if (_timeAxis == TimeAxisType.CalendarEquidistant) { TimeStep = (int)Math.Round(TimeStamp.Subtract(TimeSteps.First()).TotalSeconds / _timeStep.TotalSeconds, 0); } //Variabale timestep else { //Last timestep is known if (TimeStamp >= TimeSteps[NumberOfTimeSteps - 1]) { return(NumberOfTimeSteps - 1); } int i = 1; //Loop the timesteps while (TimeStamp > TimeSteps[i]) { i++; } //Check if last one was actually closer if (TimeSteps[i].Subtract(TimeStamp) < TimeStamp.Subtract(TimeSteps[i - 1])) { return(i); } else { return(i - 1); } } return(Math.Min(NumberOfTimeSteps - 1, TimeStep)); }
/// <summary> /// Starts the export while suppressing the output and opens the first /// exported file in an external viewer. /// </summary> public void AndOpenYouMust() { Process process = PrepareProcess(CreateConfiguration(), PlotDirPath); process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardOutput = true; Console.Write("Starting export (this may take a while)..."); process.Start(); // Try to find out when process stops writing data (without // resorting to threads...) bool probablyFinished = false; while (true) { Thread.Sleep(300); if (process.StandardOutput.Peek() == -1) { if (probablyFinished) { break; } else { probablyFinished = true; } } else { process.StandardOutput.ReadLine(); probablyFinished = false; } } // Automated key-press process.StandardInput.WriteLine(true); if (process.WaitForExit(2000)) { Console.WriteLine("Done."); } else { process.Kill(); Console.WriteLine("The process did not end as expected and has been aborted"); } if (process.ExitCode != 0) { return; } DirectoryInfo dir = new DirectoryInfo(PlotDirPath); FileInfo[] matchingFiles = dir.GetFiles("state_" + TimeSteps.First() + "*"); if (matchingFiles.IsNullOrEmpty()) { throw new Exception( "Could not find plot file. This should not have happened"); } FileInfo file = matchingFiles.OrderBy(f => f.CreationTime).Last(); Console.WriteLine("Opening file in external viewer."); process = new Process(); process.StartInfo.FileName = Path.Combine(file.DirectoryName, file.Name); process.Start(); }