/// <summary> /// Computes daily average /// returns new path saved in hec dss file /// </summary> public HecDssPath DailyAverage(string dssPathname, DateTime t1, DateTime t2) { // create data input file. string filename = cbp.Utility.GetTempFileName(PathToFile); StreamWriter sw = new StreamWriter(PathToFile + "\\" + filename); sw.WriteLine("ti " + t1.ToString("ddMMMyyyy") + " " + t2.ToString("ddMMMyyyy")); sw.WriteLine("get aaa=" + dssFilename + ":" + dssPathname); sw.WriteLine("co bbb=ts2(aaa,1DAY,0M)"); string newPath = dssPathname.Trim().Substring(0, dssPathname.Length - 1) + "dailyAvg/"; newPath = newPath.Replace("IR-DAY", "1day"); sw.WriteLine("put bbb=" + dssFilename + ":" + newPath); sw.WriteLine("cl all"); sw.Close(); /* Example.. * ti 02feb1996 02feb1997 * get aaa=site28:/cbp/site28/flow/01Feb1996/IR-DAY/site28 flows/ * co bbb=ts2(aaa,1DAY,0M) * put bbb=site28:/cbp/site28/flow/01feb1996/1day/site28 daily flows/ * cl all */ string[] rval = HecDssProgramRunner.Run("dssmath.exe", "input=" + filename, PathToFile); Console.WriteLine(String.Join("\n", rval)); HecDssPath hp = new HecDssPath(newPath); File.Delete(PathToFile + "\\" + filename); return(hp); }
/// <summary> /// Writes time series to dss file. /// </summary> public void WriteTimeSeries(Series series, HecDssPath path) { int sz = series.Count; string DssTimeFormat = "ddMMMyyyy, HHmm"; // seconds are ignored. string fn = cbp.Utility.GetTempFileName(PathToFile); StreamWriter sw = new StreamWriter(PathToFile + "\\" + fn); sw.WriteLine(Path.GetFileName(dssFilename)); sw.WriteLine(path.CondensedName); sw.WriteLine(series.Units); sw.WriteLine("inst-val"); string prevDate = "xxxxx"; for (int i = 0; i < sz; i++) { string date = series[i].DateTime.ToString(DssTimeFormat); double val = series[i].Value; if (prevDate == date) {// delete duplicates withing same minute. Console.WriteLine("skipping duplicate date " + date); continue; } sw.WriteLine(date + ", " + val); prevDate = date; } sw.WriteLine("end"); sw.Close(); string workingDir = Path.GetDirectoryName(PathToFile); Console.WriteLine("about to import using " + fn); string[] stdout = HecDssProgramRunner.Run("dssits.exe", "input=" + fn, PathToFile); //Console.WriteLine(String.Join("\n",stdout)); File.Delete(PathToFile + "\\" + fn); // remove temporary script file. }