Пример #1
0
        public V5DataOnGrid(string filename)
        {
            StreamReader sr = null;

            try
            {
                sr   = new StreamReader(filename);
                Info = sr.ReadLine();
                Date = DateTime.Parse(sr?.ReadLine() ?? string.Empty);

                var grid = new Grid2D
                {
                    XnPoints = int.Parse(sr.ReadLine() ?? string.Empty),
                    XStep    = float.Parse(sr.ReadLine() ?? string.Empty),
                    YnPoints = int.Parse(sr.ReadLine() ?? string.Empty),
                    YStep    = float.Parse(sr.ReadLine() ?? string.Empty),
                };
                Grid      = grid;
                NetValues = new Vector2[Grid.XnPoints, Grid.YnPoints];

                for (var i = 0; i < Grid.XnPoints; i++)
                {
                    for (var j = 0; j < Grid.YnPoints; j++)
                    {
                        string[] data = sr.ReadLine()?.Split(' ');
                        NetValues[i, j] = new Vector2(
                            (float)Convert.ToDouble(data[0]),
                            (float)Convert.ToDouble(data[1]));
                    }
                }
            }
            catch (ArgumentException)
            {
                Console.WriteLine("Filename is empty string");
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("File is not found");
            }
            catch (DirectoryNotFoundException)
            {
                Console.WriteLine("Directory is not found");
            }
            catch (IOException)
            {
                Console.WriteLine("Unacceptable filename");
            }
            catch (FormatException)
            {
                Console.WriteLine("String could not be parsed");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (sr != null)
                {
                    sr.Dispose();
                }
            }
        }
Пример #2
0
 public V5DataOnGrid(string info, DateTime date, Grid2D grid) : base(info, date)
 {
     Date      = DateTime.Now;
     Grid      = grid;
     NetValues = new Vector2[grid.XnPoints, grid.YnPoints];
 }