/// <summary> /// 导入CSV谱图数据 /// </summary> /// <param name="path"></param> private void _importRIP(string path) { //数据解析,获得数据矩阵(X+Y) StreamReader sr = new StreamReader(path, Encoding.Default); var lineList = new List <string>(); do { string s = sr.ReadLine().Trim(); if (s.IndexOf(" ") > 0) { s = s.Replace(" ", ","); s = s.Replace(" ", ","); lineList.Add(s); } }while (sr.Peek() != -1); sr.Close(); var x = new double[lineList.Count]; var y = new double[lineList.Count]; int i = 0; foreach (string s in lineList) { string[] split = s.Split(','); x[i] = double.Parse(split[0]); y[i] = double.Parse(split[1]); i++; } this._data = new SpectrumData(x, y); }
public SpecBase(string path = null) { if (String.IsNullOrWhiteSpace(path)) { return; } var db = Serialize.Read <SpecBase>(path); if (db == null) { return; } this._axis = db._axis; this._components = db._components; this._date = db._date; this._description = db._description; this._editor = db._editor; this._fullPath = path; this._specs = db._specs; this._title = db._title; this._x = db._x; this._y = db._y; // db.Dispose(); db = null; }
private void _import(string path) { StreamReader sr = new StreamReader(path, Encoding.Default); var lineList = new List <string>(); do { string s = sr.ReadLine().Trim(); if (!string.IsNullOrEmpty(s)) { if (s.IndexOf(",") > 1) { lineList.Add(s); } else { var reg = new Regex(@"\s{1,20}", RegexOptions.Singleline | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace); var rstr = reg.Replace(s, ","); if (rstr.IndexOf(",") > 1) { lineList.Add(rstr); } } } }while (sr.Peek() != -1); sr.Close(); var x = new double[lineList.Count]; var y = new double[lineList.Count]; int i = 0; foreach (string s in lineList) { string[] split = s.Split(','); x[i] = double.Parse(split[0]); y[i] = double.Parse(split[1]); i++; } this._data = new SpectrumData(x, y); }
private Spectrum _beforeAddOrInsert(Spectrum item) { if (this._axis == null) { this._axis = item.Data.Clone(); } //检查X轴 if ( !item.Data.X.Length.Equals(this._axis.X.Length) ) { throw new System.ArgumentException("数据点数或数据不一致"); } //检查重复名称 int i = 0; while (true) { string tmpname = item.Name; if (i > 0) { tmpname = string.Format("{0}({1})", item.Name, i); } bool tag = this._specs.Where(s => s.Name == tmpname).Count() == 0; if (tag) { item.Name = tmpname; break; } else { i++; } } return(item); }
private void _importASC(string path) { //数据解析,获得数据矩阵(X+Y) StreamReader sr = new StreamReader(path, Encoding.Default); var lineList = new List <string>(); do { string s = sr.ReadLine().Trim(); var reg = new Regex(@"\s{1,20}", RegexOptions.Singleline | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace); var rstr = reg.Replace(s, ","); if (rstr.IndexOf(",") > 1) { lineList.Add(rstr); } //if (s.IndexOf(" ") > 0) //{ // s = s.Replace(" ", ","); // lineList.Add(s); //} }while (sr.Peek() != -1); sr.Close(); var x = new double[lineList.Count]; var y = new double[lineList.Count]; int i = 0; foreach (string s in lineList) { string[] split = s.Split(','); y[i] = double.Parse(split[0]); x[i] = ++i; } this._data = new SpectrumData(x, y); }