//build columns and initiate interpolation process for a give file. public void process_file(configCols rec)//string units, string dir, string file, decimal conv_factor, //int first_header, int last_header, char delim, bool use_cumulative, //bool consolidate_file, string path_out) { //MessageBox.Show("data: \n" + fileName); process_srf srf = new process_srf(); srf.h1 = rec.first_header; srf.h2 = rec.last_header; srf.process_header(rec.file, rec.delim); List <columns> cols = new List <columns>(); if (rec.columns.Count > 0) { //MessageBox.Show("data: using custom column names"); cols = build_custom_cols(rec.columns, rec.conv_factor); } else { //MessageBox.Show("data: using file defined column names"); cols = build_orig_cols(srf.line_header1, rec.conv_factor); } interpolate_data interp = new interpolate_data(); outputs outfile = new outputs(rec.units); srf.process_file(rec.file, rec.delim); interp.convert_time_yearly(srf.data, cols, rec.use_cumulative, rec.step_wise); if (rec.consolidate_file == false) { outfile.build_yearly_csv_by_def(interp.year_data, rec.path_out, ",", rec.file); outfile.build_cum_csv_by_def(interp.c_data, rec.path_out, rec.file); } else { outfile.build_yearly_csv_single_file(interp.year_data, rec.path_out, ",", rec.file); outfile.build_cum_csv_by_single_file(interp.c_data, rec.path_out, rec.file); } }
private void UpdateFileList(configCols rec) { colSet.column_def.Add(rec); colSet.refresh(); }
public void process_config(string config) { string units = "1/year"; string dir = "--"; string fileName = "--"; string conv_factor = "1"; string first_header = "1"; string last_header = "1"; string delim = ","; string use_cumulative = "true"; string consolidate_file = "true"; string path_out = ""; string step_wise = "false"; Dictionary <int, string> cols = new Dictionary <int, string>(); //string cols; using (XmlReader reader = XmlReader.Create(@config)) { while (reader.Read()) { string node = reader.Name.ToString().ToLower(); switch (node) { case "dir": // dir = reader.GetAttribute("name"); break; case "file": //file will be found twice, the beginning of the element (<file name="XXXX">) //in which case it will have a value for attribute 'name' and the end of the //element (<\file>) in which case it wont have a 'name' attribute string t_fileName = reader.GetAttribute("name"); if (t_fileName == null) { //process_file(units, dir, fileName, conv_factor, first_header, last_header, delim, use_cumulative, // consolidate_file, path_out); List <string> files = new List <string>(); if (fileName.ToLower() == "all") { foreach (string file in Directory.GetFiles(dir)) { files.Add(file); } } else { string fullPath = Path.Combine(dir, fileName); files.Add(fullPath); } foreach (string file in files) { configCols temp = new configCols(); temp.dir = dir; temp.file = file; temp.units = units; temp.conv_factor = Convert.ToDecimal(conv_factor); temp.first_header = Convert.ToInt32(first_header); temp.last_header = Convert.ToInt32(last_header); temp.delim = Convert.ToChar(delim); temp.use_cumulative = Convert.ToBoolean(use_cumulative); temp.consolidate_file = Convert.ToBoolean(consolidate_file); temp.step_wise = Convert.ToBoolean(step_wise); temp.path_out = path_out; temp.columns = cols; cols = new Dictionary <int, string>(); proc_files.Add(temp); } units = "1/year"; conv_factor = "1"; first_header = "1"; last_header = "1"; delim = ","; use_cumulative = "true"; consolidate_file = "true"; path_out = ""; step_wise = "false"; cols = new Dictionary <int, string>(); } else { fileName = t_fileName; } break; case "units": units = reader.ReadString(); Console.WriteLine("Units: " + reader.ReadString()); break; case "conv_factor": decimal cf = 0; conv_factor = reader.ReadString(); if (!Decimal.TryParse(conv_factor, out cf)) { MessageBox.Show("Error: \nInvalid conv_factor (" + reader.ReadString() + ") for file" + fileName); Environment.Exit(1); } break; case "first_header": first_header = reader.ReadString(); break; case "last_header": last_header = reader.ReadString(); break; case "delim": delim = reader.ReadString(); break; case "use_cumulative": use_cumulative = reader.ReadString(); break; case "consolidate_file": consolidate_file = reader.ReadString(); break; case "path_out": path_out = reader.ReadString(); break; case "step_wise": step_wise = reader.ReadString(); break; case "col": string t_col = reader.GetAttribute("index"); int index = -1; if (t_col != null && int.TryParse(t_col, out index)) { cols[index] = reader.ReadString(); } break; } } //process_file(units, dir, fileName, conv_factor, first_header,last_header, delim, use_cumulative,consolidate_file,path_out); } }