예제 #1
0
        /// <summary>
        /// Read HYSPLIT trajectory data info
        /// </summary>
        /// <param name="TrajFiles">File paths</param>
        public void ReadDataInfo(string[] TrajFiles)
        {
            this.FileName = TrajFiles[0];
            string aLine;

            string[]      dataArray;
            List <string> dataList = new List <string>();
            int           i, j, t, LastNonEmpty;
            DateTime      aDateTime = new DateTime();

            InitVariables();
            List <double> times = new List <double>();

            for (t = 0; t < TrajFiles.Length; t++)
            {
                string aFile = TrajFiles[t];
                FileNames.Add(aFile);

                FileStream   fs = new FileStream(aFile, FileMode.Open, FileAccess.Read);
                StreamReader sr = new StreamReader(fs);

                //Record #1
                aLine        = sr.ReadLine();
                dataArray    = aLine.Split();
                LastNonEmpty = -1;
                dataList.Clear();
                for (i = 0; i < dataArray.Length; i++)
                {
                    if (dataArray[i] != string.Empty)
                    {
                        LastNonEmpty++;
                        dataList.Add(dataArray[i]);
                    }
                }
                MeteoFileNums.Add(int.Parse(dataList[0]));

                //Record #2
                for (i = 0; i < MeteoFileNums[t]; i++)
                {
                    aLine = sr.ReadLine();
                }

                //Record #3
                aLine        = sr.ReadLine();
                dataArray    = aLine.Split();
                LastNonEmpty = -1;
                dataList.Clear();
                for (i = 0; i < dataArray.Length; i++)
                {
                    if (dataArray[i] != string.Empty)
                    {
                        LastNonEmpty++;
                        dataList.Add(dataArray[i]);
                    }
                }
                TrajeoryNums.Add(int.Parse(dataList[0]));
                TrajeoryNumber += TrajeoryNums[t];
                TrajDirections.Add(dataList[1]);
                VerticalMotions.Add(dataList[2]);

                //Record #4
                TrajectoryInfo        aTrajInfo    = new TrajectoryInfo();
                List <TrajectoryInfo> trajInfoList = new List <TrajectoryInfo>();
                for (i = 0; i < TrajeoryNums[t]; i++)
                {
                    aLine        = sr.ReadLine();
                    dataArray    = aLine.Split();
                    LastNonEmpty = -1;
                    dataList.Clear();
                    for (j = 0; j < dataArray.Length; j++)
                    {
                        if (dataArray[j] != string.Empty)
                        {
                            LastNonEmpty++;
                            dataList.Add(dataArray[j]);
                        }
                    }
                    int y = int.Parse(dataList[0]);
                    if (y < 100)
                    {
                        if (y > 50)
                        {
                            y = 1900 + y;
                        }
                        else
                        {
                            y = 2000 + y;
                        }
                    }
                    aDateTime = new DateTime(y, int.Parse(dataList[1]),
                                             int.Parse(dataList[2]), int.Parse(dataList[3]), 0, 0);
                    //aDateTime = DateTime.Parse(dataList[0] + "-" + dataList[1] + "-" +
                    //    dataList[2] + " " + dataList[3] + ":00");
                    if (times.Count == 0)
                    {
                        times.Add(DataConvert.ToDouble(aDateTime));
                    }

                    aTrajInfo             = new TrajectoryInfo();
                    aTrajInfo.StartTime   = aDateTime;
                    aTrajInfo.StartLat    = Single.Parse(dataList[4]);
                    aTrajInfo.StartLon    = Single.Parse(dataList[5]);
                    aTrajInfo.StartHeight = Single.Parse(dataList[6]);
                    trajInfoList.Add(aTrajInfo);
                }
                TrajInfos.Add(trajInfoList);
                Dimension tdim = new Dimension(DimensionType.T);
                tdim.SetValues(times);

                //Record #5
                aLine        = sr.ReadLine();
                dataArray    = aLine.Split();
                LastNonEmpty = -1;
                dataList.Clear();
                for (i = 0; i < dataArray.Length; i++)
                {
                    if (dataArray[i] != string.Empty)
                    {
                        LastNonEmpty++;
                        dataList.Add(dataArray[i]);
                    }
                }
                VarNums.Add(int.Parse(dataList[0]));
                List <string> varNameList = new List <string>();
                for (i = 0; i < VarNums[t]; i++)
                {
                    varNameList.Add(dataList[i + 1]);
                }
                VarNames.Add(varNameList);

                Variable var = new Variable();
                var.Name      = "Traj";
                var.IsStation = true;
                var.SetDimension(tdim);
                List <Variable> variables = new List <Variable>();
                variables.Add(var);
                this.Variables = variables;

                sr.Close();
                fs.Close();
            }
        }
        /// <summary>
        /// Read MICAPS 7 data info
        /// </summary>
        /// <param name="TrajFiles">File paths</param>
        public void ReadDataInfo(string[] TrajFiles)
        {
            this.FileName = TrajFiles[0];
            string aLine;

            string[]      dataArray;
            List <string> dataList = new List <string>();
            int           j, t, LastNonEmpty;
            DateTime      aDateTime = new DateTime();

            InitVariables();
            List <double> times = new List <double>();

            for (t = 0; t < TrajFiles.Length; t++)
            {
                string aFile = TrajFiles[t];
                FileNames.Add(aFile);

                FileStream   fs = new FileStream(aFile, FileMode.Open, FileAccess.Read);
                StreamReader sr = new StreamReader(fs);

                //
                TrajectoryInfo        aTrajInfo    = new TrajectoryInfo();
                List <TrajectoryInfo> trajInfoList = new List <TrajectoryInfo>();
                aLine = sr.ReadLine();
                aLine = sr.ReadLine();
                int trajIdx = -1;
                int trajNum = 0;
                while (aLine != null)
                {
                    if (aLine.Trim() == String.Empty)
                    {
                        aLine = sr.ReadLine();
                        continue;
                    }

                    dataArray    = aLine.Split();
                    LastNonEmpty = -1;
                    dataList.Clear();
                    for (j = 0; j < dataArray.Length; j++)
                    {
                        if (dataArray[j] != string.Empty)
                        {
                            LastNonEmpty++;
                            dataList.Add(dataArray[j]);
                        }
                    }
                    switch (dataList.Count)
                    {
                    case 4:
                        aTrajInfo            = new TrajectoryInfo();
                        aTrajInfo.TrajName   = dataList[0];
                        aTrajInfo.TrajID     = dataList[1];
                        aTrajInfo.TrajCenter = dataList[2];
                        trajIdx  = -1;
                        trajNum += 1;
                        break;

                    case 13:
                        trajIdx += 1;
                        if (trajIdx == 0)
                        {
                            //aDateTime = DateTime.Parse(dataList[0] + "-" + dataList[1] + "-" +
                            //    dataList[2] + " " + dataList[3] + ":00");
                            //aDateTime = DateTime.ParseExact(dataList[0] + "-" + dataList[1] + "-" + dataList[2] +
                            //    " " + dataList[3] + ":00", "yy-MM-dd HH:mm", null);
                            int year = int.Parse(dataList[0]);
                            if (year < 100)
                            {
                                if (year < 50)
                                {
                                    year = 2000 + year;
                                }
                                else
                                {
                                    year = 1900 + year;
                                }
                            }
                            aDateTime = new DateTime(year, int.Parse(dataList[1]), int.Parse(dataList[2]), int.Parse(dataList[3]), 0, 0);
                            if (times.Count == 0)
                            {
                                times.Add(DataConvert.ToDouble(aDateTime));
                            }

                            aTrajInfo.StartTime = aDateTime;
                            aTrajInfo.StartLat  = Single.Parse(dataList[6]);
                            aTrajInfo.StartLon  = Single.Parse(dataList[5]);
                            //aTrajInfo.StartHeight = Single.Parse(dataList[6]);
                            trajInfoList.Add(aTrajInfo);
                        }
                        break;
                    }

                    aLine = sr.ReadLine();
                }
                TrajeoryNums.Add(trajNum);
                TrajeoryNumber += TrajeoryNums[t];
                TrajInfos.Add(trajInfoList);

                Dimension tdim = new Dimension(DimensionType.T);
                tdim.SetValues(times);
                this.TimeDimension = tdim;

                sr.Close();
                fs.Close();

                Variable var = new Variable();
                var.Name      = "Traj";
                var.IsStation = true;
                var.SetDimension(tdim);
                List <Variable> variables = new List <Variable>();
                variables.Add(var);
                this.Variables = variables;
            }
        }