/// <summary> /// Returns a list of paths with dates (part D ) removed /// </summary> /// <param name="dssFilename"></param> /// <returns></returns> public static string[] GetCatalog(string dssFilename) { string dir = Path.GetDirectoryName(dssFilename); string fnScript = FileUtility.GetTempFileNameInDirectory(dir, ".txt"); StreamWriter sw = new StreamWriter(fnScript); if (Path.GetFileName(dssFilename).IndexOf(" ") >= 0) { System.Windows.Forms.MessageBox.Show("Warning: The dss filename has a space. "); } sw.WriteLine(Path.GetFileName(dssFilename)); sw.WriteLine("CA");// create (N)ew (C)ondenced catalog (F)ull batch mode. sw.Close(); string dssutl = HecDssSeries.GetPathToDssUtl(); ProgramRunner pr = new ProgramRunner(); pr.Run(dssutl, "input=" + Path.GetFileName(fnScript), dir); pr.WaitForExit(); return(ParseRawCatalog(pr.Output)); }
public double[] ComputeCoefficients(ForecastEquation eq, string pathToR) { var tbl = eq.ComputeHistoricalCoefficients(eq.StartYear, eq.EndYear); // perf.Report("done."); // 1.2 seconds with cache/ 33 seconds without dataFile = FileUtility.GetTempFileName(".csv"); CsvFile.WriteToCSV(tbl, dataFile, false); dataFile = dataFile.Replace("\\", "/"); var rInput = new List <string>(); rInput.Add("# Forecast " + eq.Name); rInput.Add("a <- read.csv(\"" + dataFile + "\")"); rInput.Add("b <- subset(a, select=-Year)"); rInput.Add("cor(b)"); rInput.Add("summary(b)"); string s = "fit <- lm(Y1 ~ "; for (int i = 1; i < tbl.Columns.Count - 1; i++) { s += " + X" + i; } s += ", data=a)"; rInput.Add(s); rInput.Add("options(width=240)"); rInput.Add("summary(fit)"); rInput.Add("coefficients(fit)"); string rFile = FileUtility.GetTempFileName(".txt"); TextFile rtf = new TextFile(rInput.ToArray()); rtf.SaveAs(rFile); rFile = rFile.Replace("\\", "/"); var exe = Path.Combine(pathToR, "R\\bin\\R.exe"); if (!File.Exists(exe)) { throw new Exception("Could not find the R statistic program. It should be in a sub directory R"); } ProgramRunner pr = new ProgramRunner(); pr.Run(exe, "--no-restore --no-save --quiet < \"" + rFile); pr.WaitForExit(); Coefficients = GetCoefficients(pr.Output); Output = pr.Output; return(Coefficients); }
private static bool RunPscp(string passwd, string args) { string dir = Path.GetDirectoryName(Application.ExecutablePath); var exe = Path.Combine(dir, "pscp.exe"); if (!File.Exists(exe)) { exe = "pscp.exe"; } if (!File.Exists(exe)) { throw new FileNotFoundException(exe); } pr = new ProgramRunner(); pr.Run(exe, args); pr.SendCommand("y"); int exitCode = pr.WaitForExit(); var output = pr.Output; foreach (var item in pr.Output) { Logger.WriteLine(item); } if (exitCode != 0) { throw new IOException("Error copying with PSCP " + args.Replace(passwd, "xxxxx")); } return(exitCode == 0); // var output = ProgramRunner.RunExecutable(exe, args); //TextFile tf = new TextFile(output); //if (tf.IndexOf("The server's host key is not cached in the registry.") >= 0) //{ // // try again. // pr = new ProgramRunner(); // // pr.WriteLine += new ProgramRunner.InfoEventHandler(pr_WriteLine); // pr.Run("pscp", args.Replace("-batch","")); // pr.SendCommand("y"); // exitCode = pr.WaitForExit(); // // tf = new TextFile(pr.Output); //} }
private void DumpPathToTempFile(string fnOut) { string fnScript = FileUtility.GetTempFileNameInDirectory(PathToFile, ".txt"); StreamWriter sw = new StreamWriter(fnScript); sw.WriteLine(Path.GetFileName(m_filename)); sw.WriteLine("CA.NCF");// create (N)ew (C)ondenced catalog (F)ull batch mode. sw.WriteLine("fo f12.3"); sw.WriteLine("wr.t to=" + Path.GetFileName(fnOut) + " " + " A=" + path.A + " B=" + path.B + " C=" + path.C // +" d="+path.D skip part d (dates...) we want all dates.. + " E=" + path.E + " F=" + path.F); if (!path.IsValid) { MessageBox.Show("Warning: Path'" + path.CondensedName + "' contains invalid characters"); } sw.Close(); string dssutl = GetPathToDssUtl(); ProgramRunner pr = new ProgramRunner(); pr.Run(dssutl, "input=" + Path.GetFileName(fnScript), PathToFile); pr.WaitForExit(); string[] stdout = pr.Output; //string[] stdout = HecDssProgramRunner.Run(dssutl, "input=" + fnScript, PathToFile); Console.WriteLine("---ReadTimeSeries() "); Console.WriteLine(String.Join("\n", stdout)); File.Delete(fnScript); }