public V5DataOnGrid(string filename) : base("", new DateTime()) { /* * The data in file looks like this: * serviceInfo (string) * measurementTime (DateTime) * grid: nodesNumberX (int) grid: nodesNumberY (int) * grid: StepSizeX (float) grid: StepSizeY (float) * ValuesGrid[0, 0] ValuesGrid[0, 1] ... ValuesGrid[0, nodesNumberY] * ... * ValuesGrid[nodesNumberX, 0] ... ValuesGrid[nodesNumberX, nodesNumberY] * (ValuesGrid[i, j] looks like float, float) */ try { using (System.IO.StreamReader sr = new System.IO.StreamReader(filename)) { ServiceInfo = sr.ReadLine(); MeasurementTime = Convert.ToDateTime(sr.ReadLine()); string[] first_str = sr.ReadLine().Split(' '); string[] second_str = sr.ReadLine().Split(' '); CultureInfo ru_culture_info = new CultureInfo("ru-RU"); Grid = new Grid2D(int.Parse(first_str[0]), int.Parse(first_str[1]), float.Parse(second_str[0], ru_culture_info), float.Parse(second_str[1], ru_culture_info)); ValuesGrid = new Vector2[Grid.NodesNumberX, Grid.NodesNumberY]; for (int i = 0; i < Grid.NodesNumberX; ++i) { string[] read_str = sr.ReadLine().Split(' '); for (int j = 0; j < Grid.NodesNumberY; ++j) { ValuesGrid[i, j] = new Vector2( float.Parse(read_str[2 * j], ru_culture_info), float.Parse(read_str[2 * j + 1], ru_culture_info)); } } } } catch (Exception exception) { if (exception is System.IO.FileNotFoundException) { Console.WriteLine("File not found"); } else if (exception is FormatException || exception is NullReferenceException || exception is IndexOutOfRangeException) { Console.WriteLine("Incorrect file format"); } else { Console.WriteLine("Unexpected error"); } throw exception; } }
public V5DataOnGrid(string serviceInfo, DateTime measurementTime, Grid2D grid) : base(serviceInfo, measurementTime) { Grid = grid; }