/// <summary> /// Reads in head observations from txt file with this format. /// "WellID X Y Z Head Date Layer". Separated with tabs. Layer is optional /// </summary> /// <param name="LSFileName"></param> public Dictionary <string, MikeSheWell> ReadFromLSText(string LSFileName) { Dictionary <string, MikeSheWell> Wells = new Dictionary <string, MikeSheWell>(); //Sets the output file name for subsequent writing string path = Path.GetDirectoryName(LSFileName); string FileName = Path.GetFileNameWithoutExtension(LSFileName); _baseOutPutFileName = Path.Combine(path, FileName); //Now read the input using (StreamReader SR = new StreamReader(LSFileName)) { //Reads the HeadLine string line = SR.ReadLine(); string[] s; MikeSheWell OW; while ((line = SR.ReadLine()) != null) { s = line.Split('\t'); //Check that s has correct lengt and does not consist of empty entries if (s.Length > 5 & s.Aggregate <string>((a, b) => a + b) != "") { try { LsIntake I = null; //If the well has not already been read in create a new one if (!Wells.TryGetValue(s[0], out OW)) { OW = new MikeSheWell(s[0]); I = new LsIntake(OW, 1); OW.AddIntake(I); Wells.Add(OW.ID, OW); OW.X = double.Parse(s[1]); OW.Y = double.Parse(s[2]); //Layer is provided directly. Calculate Z if (s.Length >= 7 && s[6] != "") { OW.Layer = _numberOfLayers - int.Parse(s[6]); } //Use the Z-coordinate else { OW.Depth = double.Parse(s[3]); OW.Layer = -3; } } if (I == null) { I = OW.Intakes.First() as LsIntake; } //Now add the observation I.Observations.Add(new Observation(DateTime.ParseExact(s[5], new string[] { "dd-MM-yyyy", "d-MM-yyyy", "d-M-yyyy", "dd-M-yyyy" }, null, System.Globalization.DateTimeStyles.None), double.Parse(s[4]), OW)); } catch (FormatException e) { MessageBox.Show("Error reading this line:\n\n" + line + "\n\nFrom file: " + LSFileName + "\n\nLine skipped!", "Format error!"); } } } } //End of streamreader return(Wells); }
/// <summary> /// Reads in head observations from txt file with this format. /// "WellID X Y Z Head Date Layer". Separated with tabs. Layer is optional /// </summary> /// <param name="LSFileName"></param> public Dictionary<string, MikeSheWell> ReadFromLSText(string LSFileName) { Dictionary<string, MikeSheWell> Wells = new Dictionary<string, MikeSheWell>(); //Sets the output file name for subsequent writing string path = Path.GetDirectoryName(LSFileName); string FileName = Path.GetFileNameWithoutExtension(LSFileName); _baseOutPutFileName = Path.Combine(path, FileName); //Now read the input using (StreamReader SR = new StreamReader(LSFileName)) { //Reads the HeadLine string line = SR.ReadLine(); string[] s; MikeSheWell OW; while ((line = SR.ReadLine()) != null) { s = line.Split('\t'); //Check that s has correct lengt and does not consist of empty entries if (s.Length > 5 & s.Aggregate<string>((a,b)=>a+b)!="") { try { LsIntake I = null; //If the well has not already been read in create a new one if (!Wells.TryGetValue(s[0], out OW)) { OW = new MikeSheWell(s[0]); I = new LsIntake(OW, 1); OW.AddIntake(I); Wells.Add(OW.ID, OW); OW.X = double.Parse(s[1]); OW.Y = double.Parse(s[2]); //Layer is provided directly. Calculate Z if (s.Length >= 7 && s[6] != "") { OW.Layer = _numberOfLayers - int.Parse(s[6]); } //Use the Z-coordinate else { OW.Depth = double.Parse(s[3]); OW.Layer = -3; } } if (I == null) I = OW.Intakes.First() as LsIntake; //Now add the observation I.Observations.Add(new Observation(DateTime.ParseExact(s[5], new string[] {"dd-MM-yyyy", "d-MM-yyyy", "d-M-yyyy", "dd-M-yyyy"},null, System.Globalization.DateTimeStyles.None), double.Parse(s[4]),OW)); } catch (FormatException e) { MessageBox.Show("Error reading this line:\n\n" + line +"\n\nFrom file: "+ LSFileName + "\n\nLine skipped!", "Format error!"); } } } } //End of streamreader return Wells; }