public static void ProcessFile(string filename) { ControlFile cf = new ControlFile(filename); for (int i = 0; i < cf.Length; i++) { double val = 0.0; if (cf.OptionExists(i, "static_file")) { // nothing to do for static files } else if (cf.TryParse(i, "data", out val, 0)) { string outFilename = ""; cf.TryParse(i, "file", out outFilename); File.WriteAllText(outFilename, val.ToString() + "\n"); } else { Console.WriteLine("Error parsing '" + cf[i]); } } }
public void ExportTextFiles(DateTime t1, DateTime t2, int traceNumber) { this.traceNumber = traceNumber; usingTraces = traceNumber > 0; this.t1 = t1; this.t2 = t2; TimeSpan ts = new TimeSpan(t2.Ticks - t1.Ticks); maxCount = ts.Days + 1 + 60; // get two extra months if (!File.Exists(excelName)) { Console.WriteLine("Could not find file '" + excelName + "'"); return; } //Console.WriteLine("Found "+tbl.Rows.Count + " rows in "+excelName); // cbp.TextFile controlFile = new cbp.TextFile(controlFilename); for (int i = 0; i < controlFile1.Length; i++) { string filename = ""; controlFile1.TryParse(i, "file", out filename); File.Delete(filename); if (controlFile1.OptionExists(i, "WaterYear")) { // echo water year to file if (usingTraces) { int wy = _importDate.Year; if (t1.Month >= 10) { wy++; } //Console.WriteLine("saving " + wy + " to file " + filename); File.WriteAllText(filename, wy.ToString() + "\n"); } continue; } string sheetName = ""; controlFile1.TryParse(i, "excel_sheet", out sheetName); string excelColumn = ""; controlFile1.TryParse(i, "excel_data_column", out excelColumn); string dateColumn = ""; controlFile1.TryParse(i, "excel_date_column", out dateColumn, "Date"); if (sheetName == "" || excelColumn == "") { continue; } DataTable tbl = GetTable(excelName, sheetName); if (IndexToColumn(tbl, dateColumn) < 0) { Console.WriteLine("Error: the date column '" + dateColumn + " could not be found\n please enter !excel_date_column in the control file\n " + controlFile1[i]); continue; } startDate = Convert.ToDateTime(tbl.Rows[0][dateColumn]); _importDate = new DateTime(traceNumber - 1 + startDate.Year, startDate.Month, startDate.Day); //Reclamation.TimeSeries.Series s = new Reclamation.TimeSeries.Series(tbl, "unknown", Reclamation.TimeSeries.TimeInterval.Daily, true); int count = SaveTimeSeries(tbl, filename, excelColumn, dateColumn); if (count == 0) { Console.WriteLine("Warning: {0} there are {1} days exported from excel but Riverware requested {2} days", excelColumn, count, maxCount); } } }