public DataSerie2D Read_DS2(string fileName) { DataSerie2D ds2 = new DataSerie2D(); try { if (fileName == string.Empty) { return(null); } if (File.Exists(fileName)) { FileStream fs = File.Open(fileName, FileMode.Open); BinaryReader bnryReader = new BinaryReader(fs); int dCount = 0; ds2.Name = bnryReader.ReadString(); ds2.Description = bnryReader.ReadString(); ds2.X_Title = bnryReader.ReadString(); ds2.Y_Title = bnryReader.ReadString(); dCount = bnryReader.ReadInt32(); if (dCount > 0) { double x, y; string z; for (int i = 0; i < dCount; i++) { z = bnryReader.ReadString(); x = bnryReader.ReadDouble(); y = bnryReader.ReadDouble(); ds2.Add(z, x, y); } } bnryReader.Close(); fs.Close(); } else { throw new FileNotFoundException("File not found", fileName); } } catch (Exception ex) { throw ex; } return(ds2); }
public void ReadXML(string filepath) { try { XDocument xdoc = XDocument.Load(filepath); var prj = xdoc.Root; string version = (string)prj.Attribute("Version"); string fileVersion = (string)prj.Attribute("FileVersion"); this.Name = (string)prj.Attribute("ProjectName"); this.Description = (string)prj.Attribute("Description"); this.CreateDate = (DateTime)prj.Attribute("CreateDate"); if (fileVersion == "1.0") { this.Reservoir = new IOReservoir(); var resrvr = prj.Element("Reservoir"); this.Reservoir.Name = (string)resrvr.Attribute("Name"); this.Reservoir.Description = (string)resrvr.Attribute("Description"); this.Reservoir.MinCapacity = (double)resrvr.Attribute("MinCapacity"); this.Reservoir.MaxCapacity = (double)resrvr.Attribute("MaxCapacity"); this.Reservoir.MinRelease = (double)resrvr.Attribute("MinRelease"); this.Reservoir.MaxRelease = (double)resrvr.Attribute("MaxRelease"); //-- Elevation_Area------------------------------------------------------- DataSerie2D ds2 = new DataSerie2D(); var xhs = resrvr.Element("Curve_Elevation_Area"); int count = (int)xhs.Attribute("Count"); if (count > 0) { ds2.Name = (string)xhs.Attribute("Name"); ds2.Description = (string)xhs.Attribute("Description"); ds2.Title = (string)xhs.Attribute("Title"); ds2.X_Title = (string)xhs.Attribute("X_Title"); ds2.Y_Title = (string)xhs.Attribute("Y_Title"); // Data : var items = from dt in xhs.Elements() select new { T = (string)dt.Attribute("Title"), x = (double)dt.Attribute("x"), y = (double)dt.Attribute("y") }; foreach (var dt in items) { ds2.Add(dt.T, dt.x, dt.y); } } this.Reservoir.Elevation_Area = ds2; //-- Curve_Elevation_Volume : ------------------------------------------------------- ds2 = new DataSerie2D(); var xvs = resrvr.Element("Curve_Elevation_Volume"); count = (int)xvs.Attribute("Count"); if (count > 0) { ds2.Name = (string)xvs.Attribute("Name"); ds2.Description = (string)xvs.Attribute("Description"); ds2.Title = (string)xvs.Attribute("Title"); ds2.X_Title = (string)xvs.Attribute("X_Title"); ds2.Y_Title = (string)xvs.Attribute("Y_Title"); // Data : var items = from dt in xvs.Elements() select new { T = (string)dt.Attribute("Title"), x = (double)dt.Attribute("x"), y = (double)dt.Attribute("y") }; foreach (var dt in items) { ds2.Add(dt.T, dt.x, dt.y); } } this.Reservoir.Elevation_Volume = ds2; //---------Evaporation : ds2 = new DataSerie2D(); var xev = resrvr.Element("Evaporation"); count = (int)xev.Attribute("Count"); if (count > 0) { ds2.Name = (string)xev.Attribute("Name"); ds2.Description = (string)xev.Attribute("Description"); ds2.Title = (string)xev.Attribute("Title"); ds2.X_Title = (string)xev.Attribute("X_Title"); ds2.Y_Title = (string)xev.Attribute("Y_Title"); // Data : var items = from dt in xev.Elements() select new { T = (string)dt.Attribute("Title"), x = (double)dt.Attribute("x"), y = (double)dt.Attribute("y") }; foreach (var dt in items) { ds2.Add(dt.T, dt.x, dt.y); } } this.Reservoir.Evaporation = ds2; //---------Infiltration : ds2 = new DataSerie2D(); var xinf = resrvr.Element("Infiltration"); count = (int)xinf.Attribute("Count"); if (count > 0) { ds2.Name = (string)xinf.Attribute("Name"); ds2.Description = (string)xinf.Attribute("Description"); ds2.Title = (string)xinf.Attribute("Title"); ds2.X_Title = (string)xinf.Attribute("X_Title"); ds2.Y_Title = (string)xinf.Attribute("Y_Title"); // Data : var items = from dt in xinf.Elements() select new { T = (string)dt.Attribute("Title"), x = (double)dt.Attribute("x"), y = (double)dt.Attribute("y") }; foreach (var dt in items) { ds2.Add(dt.T, dt.x, dt.y); } } this.Reservoir.Infiltration = ds2; //------------Inflow : DataSerie1D ds1 = new DataSerie1D(); var xq = resrvr.Element("Inflow"); count = (int)xq.Attribute("Count"); if (count > 0) { ds1.Name = (string)xq.Attribute("Name"); ds1.Description = (string)xq.Attribute("Description"); ds1.Title = (string)xq.Attribute("Title"); ds1.X_Title = (string)xq.Attribute("X_Title"); // Data : var items = from dt in xq.Elements() select new { T = (string)dt.Attribute("Title"), x = (double)dt.Attribute("x"), }; foreach (var dt in items) { ds1.Add(dt.T, dt.x); } } this.Reservoir.Inflow = ds1; //-------------------------Downstream : ds1 = new DataSerie1D(); var xd = resrvr.Element("Downstream"); count = (int)xd.Attribute("Count"); if (count > 0) { ds1.Name = (string)xd.Attribute("Name"); ds1.Description = (string)xd.Attribute("Description"); ds1.Title = (string)xd.Attribute("Title"); ds1.X_Title = (string)xd.Attribute("X_Title"); // Data : var items = from dt in xd.Elements() select new { T = (string)dt.Attribute("Title"), x = (double)dt.Attribute("x"), }; foreach (var dt in items) { ds1.Add(dt.T, dt.x); } } this.Reservoir.Downstream = ds1; } } catch (Exception ex) { throw ex; } this.FileName = filepath; }
public DataSerie2D Read_DS2() { DataSerie2D ds2 = null; try { if (File.Exists(this.mFileName)) { ds2 = new DataSerie2D(); using (FileStream fs = File.Open(this.mFileName, FileMode.Open)) { using (StreamReader sReader = new StreamReader(fs)) { ds2.Name = sReader.ReadLine().Replace(";", ""); ds2.Description = sReader.ReadLine().Replace(";", ""); string title = sReader.ReadLine(); string[] titles = title.Split(';'); if (titles.Count() == 3) { ds2.Title = titles[0]; ds2.X_Title = titles[1]; ds2.Y_Title = titles[2]; } double xx, yy; bool tryResult_X = true; bool tryResult_Y = true; xx = 0; yy = 0; while (sReader.EndOfStream == false) { title = sReader.ReadLine(); titles = title.Split(';'); if (titles.Count() == 3) { tryResult_X = double.TryParse(titles[1], out xx); tryResult_Y = double.TryParse(titles[2], out yy); if (tryResult_X == false) { ds2.Add(titles[0], double.NaN, yy); } else if (tryResult_Y == false) { ds2.Add(titles[0], xx, double.NaN); } else { ds2.Add(titles[0], xx, yy); } } } } } } } catch (Exception ex) { throw ex; } return(ds2); }
public List <DataSerie2D> Read_DS2List(string fileName) { List <DataSerie2D> d2Series = new List <DataSerie2D>(); try { if (fileName == string.Empty) { return(null); } if (File.Exists(fileName)) { using (FileStream fs = File.Open(fileName, FileMode.Open)) { using (BinaryReader bnryReader = new BinaryReader(fs)) { int dCount = 0; dCount = bnryReader.ReadInt32(); if (dCount > 0) { DataSerie2D ds2; int itmCount = 0; for (int i = 0; i < dCount; i++) { ds2 = new DataSerie2D(); ds2.Name = bnryReader.ReadString(); ds2.Description = bnryReader.ReadString(); ds2.Title = bnryReader.ReadString(); ds2.X_Title = bnryReader.ReadString(); ds2.Y_Title = bnryReader.ReadString(); itmCount = bnryReader.ReadInt32(); if (itmCount > 0) { string title; double xx, yy; for (int j = 0; j < itmCount; j++) { title = bnryReader.ReadString(); xx = bnryReader.ReadDouble(); yy = bnryReader.ReadDouble(); ds2.Add(title, xx, yy); } } d2Series.Add(ds2); } } } } } else { throw new FileNotFoundException("File not found", fileName); } } catch (Exception ex) { throw ex; } return(d2Series); }