public void LoadFile(string filename) { if (!File.Exists(filename)) { throw new Exception(filename + " not found"); } using (StreamReader sr = new StreamReader(new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.Default)) { sr.ReadLine(); int numVars = int.Parse(sr.ReadLine()); for (int count = 0; count < numVars; count++) { sr.ReadLine(); // throw away vars for now. } string[] wh = sr.ReadLine().Split(" \t".ToCharArray()); width = int.Parse(wh[1]); // y, x height = int.Parse(wh[0]); for (int count = 0; count < width * height; count++) { sr.ReadLine(); // throw away x coordinates } for (int count = 0; count < width * height; count++) { sr.ReadLine(); // throw away y coordinates } cellDefined = new int[width, height]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { cellDefined[x, y] = int.Parse(sr.ReadLine()); } } string[] timeStepLabel = sr.ReadLine().Split(" \t".ToCharArray()); while (timeStepLabel.Length > 1) { allHours.Add(new GridData(width, height)); GridData currentGrid = allHours[allHours.Count - 1]; currentGrid.cells = new CellData[width, height]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { currentGrid.cells[x, y] = new CellData(); currentGrid.cells[x, y].moisture = float.Parse(sr.ReadLine()); } } for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { currentGrid.cells[x, y].poreWaterPressure = float.Parse(sr.ReadLine()); } } for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { currentGrid.cells[x, y].soilType = int.Parse(sr.ReadLine()); } } string tempString = sr.ReadLine(); if (tempString != null) { timeStepLabel = tempString.Split(" \t".ToCharArray()); } else { timeStepLabel = new string[1]; } } sr.Close(); } // load the fos file. filename = filename.Replace(".results", ".fos"); if (!File.Exists(filename)) { throw new Exception(filename + " not found"); } using (StreamReader sr = new StreamReader(new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.Default)) { string line = sr.ReadLine(); string[] tokens = line.Split(" \t".ToCharArray()); int index = 0; while (tokens != null) { if (tokens[0] != "End") { } line = sr.ReadLine(); if (line != null) { // .fos file info tokens = line.Split(" \t".ToCharArray()); allHours[index].Fos = float.Parse(tokens[1]); allHours[index].CentreX = float.Parse(tokens[3]); allHours[index].CentreY = float.Parse(tokens[4]); allHours[index].Radius = float.Parse(tokens[5]); allHours[index].Mass = float.Parse(tokens[6]); allHours[index].Moisture = float.Parse(tokens[7]); allHours[index].Influx = float.Parse(tokens[8]); // conversion on this??? // convert from meters/second to millimeters/hour allHours[index].Rainfall = float.Parse(tokens[9]) * 3600 * 1000; allHours[index].Runout = float.Parse(tokens[10]); allHours[index].Seismicity = float.Parse(tokens[11]); } else { tokens = null; } index++; if (index >= this.NumTimes) { break; } } } // calculate pressure normalization across all time normalizeMin = float.MaxValue; normalizeMax = float.MinValue; for (int count = 0; count < NumTimes; count++) { float minTemp, maxTemp; allHours[count].CalcMinMaxPressure(out minTemp, out maxTemp); if (minTemp < 9999) { normalizeMin = Math.Min(normalizeMin, minTemp); normalizeMax = Math.Max(normalizeMax, maxTemp); } } }
public void DrawSoilType(Graphics g, GraphStyle graphStyle) { GridData currentGrid = allHours[currentTime]; currentGrid.DrawSoilType(g, graphStyle); }