示例#1
0
        public V5DataOnGrid(string filename)
        {
            /*
             * формат ввода:
             *
             * 1) информация для базового класса
             * 2) дата и время для базового класса
             *    формат dd.mm.yy h:m
             * 3) параметр сетки: кол-во шагов по Х
             * 4) параметр сетки: размер шага по Х
             * 5) параметр сетки: кол-во шагов по У
             * 6) параметр сетки: размер шага по У
             * 7) X*Y строк с данными для векторов э/м поля формата:
             *    величина_по_Х величина_по_У (параметры разделены пробелом)
             */

            StreamReader sr = null;

            //DataItems = new List<DataItem>();

            try
            {
                sr = new StreamReader(filename);

                InfoData = sr.ReadLine();

                Time = DateTime.Parse(sr.ReadLine());

                Grid2D grid = new Grid2D
                {
                    NodeNumX = int.Parse(sr.ReadLine()),
                    StepX    = float.Parse(sr.ReadLine()),
                    NodeNumY = int.Parse(sr.ReadLine()),
                    StepY    = float.Parse(sr.ReadLine()),
                };
                Net = grid;
                Vec = new Vector2[Net.NodeNumX, Net.NodeNumY];

                for (int i = 0; i < Net.NodeNumX; i++)
                {
                    for (int j = 0; j < Net.NodeNumY; j++)
                    {
                        string[] data = sr.ReadLine().Split(' ');

                        Vec[i, j] = new Vector2(
                            (float)Convert.ToDouble(data[0]),
                            (float)Convert.ToDouble(data[1]));

                        //Vector2 v = new Vector2(i * Net.StepX, j * Net.StepY);

                        //DataItem di = new DataItem(v, Vec[i, j]);
                        //DataItems.Add(di);
                    }
                }
            }
            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 override List<DataItem> DataItems { get; set; }
 public V5DataOnGrid(string id, DateTime t, Grid2D grid) : base(id, t)
 {
     Net = grid;
     Vec = new Vector2[Net.NodeNumX, Net.NodeNumY];
     //   DataItems = new List<DataItem>();
 }