//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 List<columns> column_def; private void load_srf(object sender, RoutedEventArgs e) { OpenFileDialog openfiledialog1 = new OpenFileDialog(); process_srf srf = new process_srf(); //openfiledialog1.InitialDirectory = dir; if (delim == ',') { openfiledialog1.Filter = "csv (*.csv)|*.csv|srf (*.srf)|*.srf|dat (*.dat)|*.dat|All Files (*.*)|*.*"; } else { openfiledialog1.Filter = "All Files (*.*)|*.*|csv (*.csv)|*.csv|srf (*.srf)|*.srf|dat (*.dat)|*.dat"; } openfiledialog1.FilterIndex = 1; openfiledialog1.Multiselect = true; openfiledialog1.RestoreDirectory = false; //leave it where the files actually are for reading the raw data files (03-27-2012) openfiledialog1.Title = "Select file(s) to be processed:"; openfiledialog1.ShowDialog(); //check that one or more files were selected. using (new WaitCursor()) { if (openfiledialog1.FileNames.Length > 0) { string outpath = System.IO.Path.GetDirectoryName(openfiledialog1.FileName) + "\\"; files = openfiledialog1.FileNames; srf.h1 = string_to_int(tb_h1_row.Text); srf.h2 = string_to_int(tb_h2_row.Text); srf.process_header(openfiledialog1.FileName, delim); if (srf.line_header1 == null) { files = null; return; } if (srf.h1.ToString() != tb_h1_row.Text) { tb_h1_row.Text = srf.h1.ToString(); } if (srf.h2.ToString() != tb_h2_row.Text) { tb_h2_row.Text = srf.h2.ToString(); } tb_fileName.Text = String.Join(Environment.NewLine, files); openfiledialog1 = null; header1 = srf.line_header1; header2 = srf.line_header2; // colSet.column_def = new List <columns>(); if (srf.line_header1 != null) { for (int i = 0; i < srf.line_header1.Length; i++) { columns temp = new columns(); temp.column_num = i + 1; //if (header2 != null && header2.Length > i) // temp.title = String.Format("{0} {1}", header1[i], header2[i]); //else // temp.title = header1[i]; temp.title = header1[i]; temp.definition = ""; temp.conv_factor = 1; if (ckbx_ci_pci.IsChecked == true) { temp.conv_factor = 1000000000000; } else if (ckbx_g_ug.IsChecked == true) { temp.conv_factor = 1000000; } else if (ckbx_custom.IsChecked == true) { temp.conv_factor = string_to_decimal(tb_custom.Text); } if (header1[i].ToLower() == "time") { temp.time = true; temp.definition = "year"; } else if (temp.title.Contains("modflow_")) { temp.definition = temp.title.Substring(8); } else { temp.definition = ""; } colSet.column_def.Add(temp); } } colSet.refresh(); if (tb_outdir.Text == null || tb_outdir.Text == "") { tb_outdir.Text = outpath + "\\"; } } } }