/// <summary> /// Loads data from fully qualified CSV file /// Exceptions are thrown if the column names are wrong /// </summary> /// <param name="?"></param> public void FromCSVFile(CSV_File csv) { SensorDescriptionFile sdf = new SensorDescriptionFile(); CSV_Channel index = csv.GetIndex(); if (index == null) { throw new Exception("File contains no valid data"); } CSV_Channel MD = CSVToChannel(csv, "MD"); CSV_Channel Northing = CSVToChannel(csv, "Northing"); CSV_Channel Easting = CSVToChannel(csv, "Easting"); CSV_Channel DepthSRD = CSVToChannel(csv, "Depth SRD"); CSV_Channel IsActive = CSVToChannel(csv, "Active"); CSV_Channel Type = CSVToChannel(csv, "Type"); CSV_Channel Gain = CSVToChannel(csv, "Gain"); CSV_Channel Sensitivity = CSVToChannel(csv, "Sensitivity"); CSV_Channel FullScale = CSVToChannel(csv, "Full Scale"); CSV_Channel LowFrequency = CSVToChannel(csv, "Filter Min"); CSV_Channel HighFrequency = CSVToChannel(csv, "Filter Max"); CSV_Channel iN = CSVToChannel(csv, "iN"); CSV_Channel iE = CSVToChannel(csv, "iE"); CSV_Channel iD = CSVToChannel(csv, "iD"); CSV_Channel Polarization = CSVToChannel(csv, "Polarity"); CSV_Channel PStationCorrection = CSVToChannel(csv, "P Static"); CSV_Channel SStationCorrection = CSVToChannel(csv, "S Static"); sdf.Metric = !DepthSRD.Unit.ToUpper().Contains("F"); for (int i = 0; i < index.Data.Count; i++) { SensorDescription sd = new SensorDescription(); sd.ChannelNumber = i + 1; sd.MD = MD.Data[i]; sd.Northing = Northing.Data[i]; sd.Easting = Easting.Data[i]; sd.DepthSRD = DepthSRD.Data[i]; sd.IsActive = IsActive.Data[i] > 0.0; sd.Type = Type.Data[i].ToString("0").PadLeft(5, '0'); sd.Gain = Gain.Data[i]; sd.Sensitivity = Sensitivity.Data[i]; sd.FullScale = FullScale.Data[i]; sd.LowFrequency = LowFrequency.Data[i]; sd.HighFrequency = HighFrequency.Data[i]; sd.iN = iN.Data[i]; sd.iE = iE.Data[i]; sd.iD = iD.Data[i]; sd.Polarization = (Polarization.Data[i] < 0.0) ? -1 : 1; sd.PStationCorrection = PStationCorrection.Data[i]; sd.SStationCorrection = SStationCorrection.Data[i]; sdf.Sensors.Add(sd); } if (sdf.Sensors.Count <= 0) { throw new Exception("CSV file contains no data."); } this.Sensors.Clear(); this.Metric = sdf.Metric; this.Sensors = sdf.Sensors; m_Modified = true; }
private CSV_Channel CSVToChannel(CSV_File csv, string name) { CSV_Channel c = csv.GetChannel(name); if (c == null) { throw new Exception("File does not contain channel " + name + "."); } return(c); }
private CSV_Channel ChannelToCSV(string name, string unit, string format) { CSV_Channel c = new CSV_Channel(name, unit); c.Format = format; switch (name) { case "Inst": for (int i = 0; i < Sensors.Count; i++) { double tmp = 0.0; try{ tmp = Convert.ToDouble(Sensors[i].Type.Substring(2)); } catch (Exception) {} c.Data.Add(tmp); } break; case "Axis": for (int i = 0; i < Sensors.Count; i++) { double tmp = 0.0; try{ tmp = Convert.ToDouble(Sensors[i].Type.Substring(1, 1)); } catch (Exception) {} c.Data.Add(tmp); } break; case "Chan": case "Sensor": for (int i = 0; i < Sensors.Count; i++) { c.Data.Add((double)Sensors[i].ChannelNumber); } break; case "MD": for (int i = 0; i < Sensors.Count; i++) { c.Data.Add(Sensors[i].MD); } break; case "Northing": for (int i = 0; i < Sensors.Count; i++) { c.Data.Add(Sensors[i].Northing); } break; case "Easting": for (int i = 0; i < Sensors.Count; i++) { c.Data.Add(Sensors[i].Easting); } break; case "Depth SRD": for (int i = 0; i < Sensors.Count; i++) { c.Data.Add(Sensors[i].DepthSRD); } break; case "Active": for (int i = 0; i < Sensors.Count; i++) { c.Data.Add(Sensors[i].IsActive? 1.0: 0.0); } break; case "Type": for (int i = 0; i < Sensors.Count; i++) { c.Data.Add(Convert.ToDouble(Sensors[i].Type)); } break; case "Gain": for (int i = 0; i < Sensors.Count; i++) { c.Data.Add(Sensors[i].Gain); } break; case "Sensitivity": for (int i = 0; i < Sensors.Count; i++) { c.Data.Add(Sensors[i].Sensitivity); } break; case "Full Scale": for (int i = 0; i < Sensors.Count; i++) { c.Data.Add(Sensors[i].FullScale); } break; case "Filter Min": for (int i = 0; i < Sensors.Count; i++) { c.Data.Add(Sensors[i].LowFrequency); } break; case "Filter Max": for (int i = 0; i < Sensors.Count; i++) { c.Data.Add(Sensors[i].HighFrequency); } break; case "iN": for (int i = 0; i < Sensors.Count; i++) { c.Data.Add(Sensors[i].iN); } break; case "iE": for (int i = 0; i < Sensors.Count; i++) { c.Data.Add(Sensors[i].iE); } break; case "iD": for (int i = 0; i < Sensors.Count; i++) { c.Data.Add(Sensors[i].iD); } break; case "Polarity": for (int i = 0; i < Sensors.Count; i++) { c.Data.Add(Sensors[i].Polarization); } break; case "P Static": for (int i = 0; i < Sensors.Count; i++) { c.Data.Add(Sensors[i].PStationCorrection); } break; case "S Static": for (int i = 0; i < Sensors.Count; i++) { c.Data.Add(Sensors[i].SStationCorrection); } break; default: break; } return(c); }