Esempio n. 1
0
        /// <summary>
        /// Generate data info text of MICAPS 4
        /// </summary>
        /// <param name="aDataInfo"></param>
        /// <returns></returns>
        public string GenerateInfoText_M4(MICAPS4DataInfo aDataInfo)
        {
            string dataInfo;

            dataInfo  = "File Name: " + aDataInfo.FileName;
            dataInfo += Environment.NewLine + "Description: " + aDataInfo.Description;
            dataInfo += Environment.NewLine + "Time: " + aDataInfo.DateTime.ToString("yyyy-MM-dd HH:00");
            dataInfo += Environment.NewLine + "Forecast Hours = " + aDataInfo.hours.ToString() +
                        "  Level = " + aDataInfo.level.ToString();
            dataInfo += Environment.NewLine + "Xsize = " + aDataInfo.XNum.ToString() +
                        "  Ysize = " + aDataInfo.YNum.ToString();

            return(dataInfo);
        }
Esempio n. 2
0
        /// <summary>
        /// Read MICAPS 4 data info
        /// </summary>
        /// <param name="aFile"></param>
        /// <returns></returns>
        public MICAPS4DataInfo ReadMicaps4(string aFile)
        {
            StreamReader sr = new StreamReader(aFile, Encoding.Default);
            string       aLine;

            string[]        dataArray;
            int             i, j, n, LastNonEmpty;
            ArrayList       dataList    = new ArrayList();
            ArrayList       disDataList = new ArrayList();
            MICAPS4DataInfo aM4DataInfo = new MICAPS4DataInfo();

            aM4DataInfo.FileName = aFile;
            aLine = sr.ReadLine();
            aM4DataInfo.Description = aLine;
            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]);
                }
            }
            for (n = 0; n <= 10; n++)
            {
                if (dataList.Count < 19)
                {
                    aLine        = sr.ReadLine();
                    dataArray    = aLine.Split();
                    LastNonEmpty = -1;
                    for (i = 0; i < dataArray.Length; i++)
                    {
                        if (dataArray[i] != string.Empty)
                        {
                            LastNonEmpty++;
                            dataList.Add(dataArray[i]);
                        }
                    }
                }
                else
                {
                    break;
                }
            }
            aM4DataInfo.DateTime = Convert.ToDateTime(dataList[0] + "-" + dataList[1] + "-" + dataList[2] +
                                                      " " + dataList[3] + ":00");
            aM4DataInfo.hours         = Convert.ToInt32(dataList[4]);
            aM4DataInfo.level         = Convert.ToInt32(dataList[5]);
            aM4DataInfo.XDelt         = Convert.ToSingle(dataList[6]);
            aM4DataInfo.YDelt         = Convert.ToSingle(dataList[7]);
            aM4DataInfo.XMin          = Convert.ToSingle(dataList[8]);
            aM4DataInfo.XMax          = Convert.ToSingle(dataList[9]);
            aM4DataInfo.YMin          = Convert.ToSingle(dataList[10]);
            aM4DataInfo.YMax          = Convert.ToSingle(dataList[11]);
            aM4DataInfo.XNum          = Convert.ToInt32(dataList[12]);
            aM4DataInfo.YNum          = Convert.ToInt32(dataList[13]);
            aM4DataInfo.contourDelt   = Convert.ToSingle(dataList[14]);
            aM4DataInfo.contourSValue = Convert.ToSingle(dataList[15]);
            aM4DataInfo.contourEValue = Convert.ToSingle(dataList[16]);
            aM4DataInfo.smoothCo      = Convert.ToSingle(dataList[17]);
            aM4DataInfo.boldValue     = Convert.ToSingle(dataList[18]);
            if ((string)dataList[16] == "-1" || (string)dataList[16] == "-2" || (string)dataList[16] == "-3")
            {
                aM4DataInfo.isLonLat = false;
            }
            else
            {
                aM4DataInfo.isLonLat = true;
            }
            aM4DataInfo.X = new double[aM4DataInfo.XNum];
            for (i = 0; i < aM4DataInfo.XNum; i++)
            {
                aM4DataInfo.X[i] = aM4DataInfo.XMin + i * aM4DataInfo.XDelt;
            }
            aM4DataInfo.Y = new double[aM4DataInfo.YNum];
            for (i = 0; i < aM4DataInfo.YNum; i++)
            {
                aM4DataInfo.Y[i] = aM4DataInfo.YMin + i * aM4DataInfo.YDelt;
            }

            string dataStr = sr.ReadToEnd();

            sr.Close();
            dataArray    = dataStr.Split();
            LastNonEmpty = -1;
            dataList.Clear();
            for (i = 0; i < dataArray.Length; i++)
            {
                if (dataArray[i] != string.Empty)
                {
                    LastNonEmpty++;
                    dataList.Add(dataArray[i]);
                }
            }

            double[,] gridData = new double[aM4DataInfo.YNum, aM4DataInfo.XNum];
            for (i = 0; i < aM4DataInfo.YNum; i++)
            {
                for (j = 0; j < aM4DataInfo.XNum; j++)
                {
                    gridData[i, j] = Convert.ToDouble(dataList[i * aM4DataInfo.XNum + j]);
                }
            }

            aM4DataInfo.GridData = new double[aM4DataInfo.YNum, aM4DataInfo.XNum];
            for (i = 0; i < aM4DataInfo.YNum; i++)
            {
                for (j = 0; j < aM4DataInfo.XNum; j++)
                {
                    aM4DataInfo.GridData[i, j] = gridData[i, j];
                }
            }

            return(aM4DataInfo);
        }