248 lines
6.8 KiB
C#
248 lines
6.8 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.IO;
|
|
using System.Text;
|
|
|
|
namespace LeafWeb.Web.Charter
|
|
{
|
|
[Serializable]
|
|
public class CurveParamSet
|
|
{
|
|
private readonly ArrayList anetMeasChloro1Data; // y=AnetMeas column, x=PCO2c, for PointLimitType=1
|
|
private readonly ArrayList anetMeasChloro2Data; // y=AnetMeas column, x=PCO2c, for PointLimitType=2
|
|
private readonly ArrayList anetMeasChloro3Data; // y=AnetMeas column, x=PCO2c, for PointLimitType=3
|
|
private readonly ArrayList anetMeasInter1Data; // y=AnetMeas column, x=PCO2i, for PointLimitType=1
|
|
private readonly ArrayList anetMeasInter2Data; // y=AnetMeas column, x=PCO2i, for PointLimitType=2
|
|
private readonly ArrayList anetMeasInter3Data; // y=AnetMeas column, x=PCO2i, for PointLimitType=3
|
|
private readonly ArrayList acChloroData; // y=Ac column, x=CO2cc column
|
|
private readonly ArrayList ajChloroData; // y=Aj column, x=CO2cj column
|
|
private readonly ArrayList atChloroData; // y=At column, x=CO2ct column
|
|
private readonly ArrayList acInterData; // y=Ac column, x=CO2i column
|
|
private readonly ArrayList ajInterData; // y=Aj column, x=CO2i column
|
|
private readonly ArrayList atInterData; // y=At column, x=CO2i column
|
|
|
|
public CurveParamSet()
|
|
{
|
|
}
|
|
|
|
public CurveParamSet(StreamReader sr, ref String errMsg, ref int lineNbr, ref String curveID)
|
|
{
|
|
bool curveIDSet = false, doneWithAnet = false;
|
|
String line, firstField;
|
|
var errorMsg = new StringBuilder("");
|
|
ArrayList phrases;
|
|
XYPoint xyPoint1, xyPoint2;
|
|
int pointLimitType;
|
|
anetMeasChloro1Data = new ArrayList();
|
|
anetMeasChloro2Data = new ArrayList();
|
|
anetMeasChloro3Data = new ArrayList();
|
|
anetMeasInter1Data = new ArrayList();
|
|
anetMeasInter2Data = new ArrayList();
|
|
anetMeasInter3Data = new ArrayList();
|
|
acChloroData = new ArrayList();
|
|
ajChloroData = new ArrayList();
|
|
atChloroData = new ArrayList();
|
|
acInterData = new ArrayList();
|
|
ajInterData = new ArrayList();
|
|
atInterData = new ArrayList();
|
|
|
|
while (!doneWithAnet)
|
|
{
|
|
lineNbr++;
|
|
line = sr.ReadLine();
|
|
if (line == null)
|
|
{
|
|
errorMsg.Append("Unexpected end-of-file at line " + lineNbr);
|
|
sr.Close();
|
|
errMsg = errorMsg.ToString();
|
|
return;
|
|
}
|
|
|
|
phrases = splitCSVLine(line);
|
|
|
|
firstField = (String) 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;
|
|
}
|
|
xyPoint1 = new XYPoint((String) phrases[9], (String) phrases[10]); // AnetMeas(y), PCO2c(x)
|
|
xyPoint2 = new XYPoint((String) phrases[8], (String) phrases[10]); // AnetMeas(y), PCO2i(x)
|
|
pointLimitType = Int32.Parse((String) 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)
|
|
{
|
|
errorMsg.Append("Unexpected end-of-file at line " + lineNbr);
|
|
sr.Close();
|
|
errMsg = errorMsg.ToString();
|
|
return;
|
|
}
|
|
|
|
if (line.Length == 0)
|
|
moreData = false;
|
|
else
|
|
{
|
|
phrases = splitCSVLine(line);
|
|
xyPoint1 = new XYPoint((String) phrases[1], (String) phrases[2]); // Ac(y),CO2cc(x)
|
|
if (xyPoint1.yIsInRange(-20.0, 50.0))
|
|
acChloroData.Add(xyPoint1);
|
|
xyPoint1 = new XYPoint((String) phrases[3], (String) phrases[4]); // Aj(y),CO2cj(x)
|
|
if (xyPoint1.yIsInRange(-20.0, 50.0))
|
|
ajChloroData.Add(xyPoint1);
|
|
xyPoint1 = new XYPoint((String) phrases[5], (String) phrases[6]); // At(y),CO2ct(x)
|
|
if (xyPoint1.yIsInRange(-20.0, 50.0))
|
|
atChloroData.Add(xyPoint1);
|
|
|
|
xyPoint1 = new XYPoint((String) phrases[0], (String) phrases[2]); // Ac(y),CO2i(x)
|
|
if (xyPoint1.yIsInRange(-20.0, 50.0))
|
|
acInterData.Add(xyPoint1);
|
|
xyPoint1 = new XYPoint((String) phrases[0], (String) phrases[4]); // Aj(y),CO2i(x)
|
|
if (xyPoint1.yIsInRange(-20.0, 50.0))
|
|
ajInterData.Add(xyPoint1);
|
|
xyPoint1 = new XYPoint((String) phrases[0], (String) phrases[6]); // At(y),CO2i(x)
|
|
if (xyPoint1.yIsInRange(-20.0, 50.0))
|
|
atInterData.Add(xyPoint1);
|
|
}
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
/// <param name="line"></param>
|
|
/// <returns></returns>
|
|
private ArrayList splitCSVLine(String line)
|
|
{
|
|
int i;
|
|
char[] separator;
|
|
separator = new char[3];
|
|
separator[0] = ',';
|
|
separator[1] = ' ';
|
|
separator[2] = '\t';
|
|
var phrases = line.Split(separator);
|
|
String phrase;
|
|
|
|
//int lastNonBlank = -1;
|
|
var retPhrases = new ArrayList();
|
|
for (i = 0; i < phrases.Length; i++)
|
|
{
|
|
phrase = phrases[i].Trim();
|
|
if (phrase.Length > 0)
|
|
// lastNonBlank = i;
|
|
retPhrases.Add(phrase);
|
|
}
|
|
|
|
//int firstBlankToRemove = lastNonBlank + 1;
|
|
//if( firstBlankToRemove <= phrases.Length - 1 )
|
|
// retPhrases.RemoveRange(firstBlankToRemove, phrases.Length - firstBlankToRemove);
|
|
|
|
return retPhrases;
|
|
}
|
|
|
|
public ArrayList getAnetMeasData()
|
|
{
|
|
var list = new ArrayList();
|
|
list.Add(anetMeasChloro1Data);
|
|
list.Add(anetMeasChloro2Data);
|
|
list.Add(anetMeasChloro3Data);
|
|
list.Add(anetMeasInter1Data);
|
|
list.Add(anetMeasInter2Data);
|
|
list.Add(anetMeasInter3Data);
|
|
|
|
return list;
|
|
}
|
|
|
|
public ArrayList getAcChloroData()
|
|
{
|
|
return acChloroData;
|
|
}
|
|
|
|
public ArrayList getAjChloroData()
|
|
{
|
|
return ajChloroData;
|
|
}
|
|
|
|
public ArrayList getAtChloroData()
|
|
{
|
|
return atChloroData;
|
|
}
|
|
|
|
public ArrayList getAcInterData()
|
|
{
|
|
return acInterData;
|
|
}
|
|
|
|
public ArrayList getAjInterData()
|
|
{
|
|
return ajInterData;
|
|
}
|
|
|
|
public ArrayList getAtInterData()
|
|
{
|
|
return atInterData;
|
|
}
|
|
}
|
|
} |