using System.Collections.Generic; using System.IO; using LeafWeb.Core.Utility; namespace LeafWeb.Core.Charter { public class CurveParamSet { public List AnetMeasChloro1Data { get; } = new List(); // y=AnetMeas column, x=PCO2c, for PointLimitType=1 public List AnetMeasChloro2Data { get; } = new List(); // y=AnetMeas column, x=PCO2c, for PointLimitType=2 public List AnetMeasChloro3Data { get; } = new List(); // y=AnetMeas column, x=PCO2c, for PointLimitType=3 public List AnetMeasInter1Data { get; } = new List(); // y=AnetMeas column, x=PCO2i, for PointLimitType=1 public List AnetMeasInter2Data { get; } = new List(); // y=AnetMeas column, x=PCO2i, for PointLimitType=2 public List AnetMeasInter3Data { get; } = new List(); // y=AnetMeas column, x=PCO2i, for PointLimitType=3 public List AcChloroData { get; } = new List(); public List AjChloroData { get; } = new List(); public List AtChloroData { get; } = new List(); public List AcInterData { get; } = new List(); public List AjInterData { get; } = new List(); public List AtInterData { get; } = new List(); public CurveParamSet(TextReader sr, ref int lineNbr, ref string curveId) { bool curveIdSet = false, doneWithAnet = false; string line; List phrases; while (!doneWithAnet) { lineNbr++; line = sr.ReadLine(); if (line == null) { throw new ParseException("Unexpected end-of-file at line " + lineNbr); } phrases = SplitCsvLine(line); var firstField = phrases[0]; if (firstField.Equals("CO2i")) { doneWithAnet = true; } else { // The fields on the line: // Column Name // 0 CurveID // 1 ChlFlUse // 2 FitGi // 3 FitGamma // 4 FitKco // 5 FitRd // 6 FitAlpha // 7 LimitCombina // 8 PCO2i // 9 PCO2c // 10 AnetMeas // 11 AnetCal // 12 weitedrms // 13 PointLimitType if (!curveIdSet) { curveId = firstField; curveIdSet = true; } var xyPoint1 = new XyPoint(phrases[9], phrases[10]); // AnetMeas(y), PCO2c(x) var xyPoint2 = new XyPoint(phrases[8], phrases[10]); var pointLimitType = int.Parse(phrases[13]); switch (pointLimitType) { case 1: AnetMeasChloro1Data.Add(xyPoint1); AnetMeasInter1Data.Add(xyPoint2); break; case 2: AnetMeasChloro2Data.Add(xyPoint1); AnetMeasInter2Data.Add(xyPoint2); break; case 3: AnetMeasChloro3Data.Add(xyPoint1); AnetMeasInter3Data.Add(xyPoint2); break; } } } // The next set of lines will have three pairs of x,y-coordinates to save. // A blank line signals the end of the data. var moreData = true; while (moreData) { // The fields on the line: // Column Name // 0 CO2i // 1 CO2cc // 2 Ac // 3 CO2cj // 4 Aj // 5 CO2ct // 6 At lineNbr++; line = sr.ReadLine(); if (line == null) { throw new ParseException("Unexpected end-of-file at line " + lineNbr); } if (line.Length == 0) moreData = false; else { phrases = SplitCsvLine(line); var xyPoint1 = new XyPoint(phrases[1],phrases[2]); // Ac(y),CO2cc(x) if (xyPoint1.YIsInRange(-20.0, 50.0)) AcChloroData.Add(xyPoint1); xyPoint1 = new XyPoint(phrases[3], phrases[4]); // Aj(y),CO2cj(x) if (xyPoint1.YIsInRange(-20.0, 50.0)) AjChloroData.Add(xyPoint1); xyPoint1 = new XyPoint(phrases[5], phrases[6]); // At(y),CO2ct(x) if (xyPoint1.YIsInRange(-20.0, 50.0)) AtChloroData.Add(xyPoint1); xyPoint1 = new XyPoint(phrases[0], phrases[2]); // Ac(y),CO2i(x) if (xyPoint1.YIsInRange(-20.0, 50.0)) AcInterData.Add(xyPoint1); xyPoint1 = new XyPoint(phrases[0], phrases[4]); // Aj(y),CO2i(x) if (xyPoint1.YIsInRange(-20.0, 50.0)) AjInterData.Add(xyPoint1); xyPoint1 = new XyPoint(phrases[0], phrases[6]); // At(y),CO2i(x) if (xyPoint1.YIsInRange(-20.0, 50.0)) AtInterData.Add(xyPoint1); } } } /// /// This method assumes that the argument is a comma-, blank-, or /// tab-separated set of strings. It returns an ArrayList of those /// quantities. Consecutive commas will be returned as an empty string, /// but all empty strings at the end of the line will be thrown away. /// /// /// private static List SplitCsvLine(string line) { int i; var separator = new [] {',', ' ', '\t'}; var phrases = line.Split(separator); var retPhrases = new List(); for (i = 0; i < phrases.Length; i++) { var phrase = phrases[i].Trim(); if (phrase.Length > 0) retPhrases.Add(phrase); } return retPhrases; } } }