Exemple #1
0
        public DprRdaData ReadData(string filePath, frmProgress frmpg)
        {
            //float[, ,] DBZ = DataInitial<float>.GetResult(11, 720, 1840, -999);
            //float[, ,] VEL = DataInitial<float>.GetResult(11, 720, 1200, -999);
            //float[, ,] SW = DataInitial<float>.GetResult(11, 720, 1200, -999);
            //float[, ,] ZDR = DataInitial<float>.GetResult(11, 720, 1200, -999);
            //float[, ,] PHI = DataInitial<float>.GetResult(11, 720, 1200, -999);
            //float[, ,] RHO = DataInitial<float>.GetResult(11, 720, 1200, -999);
            //float[, ,] KDP = DataInitial<float>.GetResult(9, 720, 1200, -999);
            //float[] ElevationData = DataInitial<float>.GetResult(11, -999);
            //float[, ,] dbz = DataInitial<float>.GetResult(9, 720, 1840, -999);
            //float[, ,] vel = DataInitial<float>.GetResult(9, 720, 1200, -999);
            //float[, ,] sw  = DataInitial<float>.GetResult(9, 720, 1200, -999);
            //float[, ,] zdr = DataInitial<float>.GetResult(9, 720, 1200, -999);
            //float[, ,] phi = DataInitial<float>.GetResult(9, 720, 1200, -999);
            //float[, ,] rho = DataInitial<float>.GetResult(9, 720, 1200, -999);
            //float[, ,] kdp = DataInitial<float>.GetResult(9, 720, 1200, -999);
            float[,,] DBZ = DataInitial(11, 720, 1200, -999);
            float[,,] VEL = DataInitial(11, 720, 1200, -999);
            float[,,] SW  = DataInitial(11, 720, 1200, -999);
            float[,,] ZDR = DataInitial(11, 720, 1200, -999);
            float[,,] PHI = DataInitial(11, 720, 1200, -999);
            float[,,] RHO = DataInitial(11, 720, 1200, -999);
            float[,,] KDP = DataInitial(9, 720, 1200, -999);
            float[] ElevationData = DataInitial(11, -999);
            float[,,] dbz = DataInitial(9, 720, 1200, -999);
            float[,,] vel = DataInitial(9, 720, 1200, -999);
            float[,,] sw  = DataInitial(9, 720, 1200, -999);
            float[,,] zdr = DataInitial(9, 720, 1200, -999);
            float[,,] phi = DataInitial(9, 720, 1200, -999);
            float[,,] rho = DataInitial(9, 720, 1200, -999);
            float[,,] kdp = DataInitial(9, 720, 1200, -999);

            float[] azimuthAngle  = new float[720];
            float   azimuthNumber = 0;

            string   dataSwitch = filePath.Substring(filePath.Length - 3);
            DateTime t1         = DateTime.Now;

            using (FileStream fs = new FileStream(filePath, FileMode.Open))
            {
                using (BZip2InputStream bzip2Stream = new BZip2InputStream(fs))
                {
                    float[,] azimuth = DataInitial <float> .GetResult(11, 720, 999);

                    bzip2Stream.Read(new byte[24 + 325888], 0, 24 + 325888);
                    try
                    {
                        int radialStatus = 0;
                        while (radialStatus != 4)
                        {
                            int azIndex = 0;
                            do
                            {
                                //*****Message Header Data *****///
                                MessageHeader sizeMessHeader =
                                    ReadStructure <MessageHeader>(bzip2Stream);

                                //*****Radar Data Generic Format Blocks ***//
                                GenericFormatBlock genericFormatBlock =
                                    ReadStructure <GenericFormatBlock>(bzip2Stream);

                                //****Volume Data Contant Type*****//
                                VolumeDataConstantType volumeDataConstantType =
                                    ReadStructure <VolumeDataConstantType>(bzip2Stream);

                                //****Elevation Data Constant Type *****//
                                ElevationDataConstantType elevationDataCostantType =
                                    ReadStructure <ElevationDataConstantType>(bzip2Stream);

                                //***Radial Data Block *****//
                                RadialDataConstantType radialDataConstantType =
                                    ReadStructure <RadialDataConstantType>(bzip2Stream);
                                int    elIndex      = genericFormatBlock.elevNum - 1;
                                double azResoultion = SwitchResolution(genericFormatBlock.azReSp);
                                azimuth[elIndex, azIndex] = genericFormatBlock.azAngle;
                                azimuthNumber             = genericFormatBlock.azimuthNum;
                                radialStatus           = genericFormatBlock.radStatus;
                                ElevationData[elIndex] = genericFormatBlock.elevAngle;

                                int momentCount =
                                    SwitchDataBlock(genericFormatBlock.dataBlockCount);

                                frmpg.nProgress = (int)(bzip2Stream.Position / (double)bzip2Stream.Length * 100 * 0.4);

                                for (int i = 0; i < momentCount; i++)
                                {
                                    DescripOfDataMomentType descripOfDataMomentType =
                                        ReadStructure <DescripOfDataMomentType>(bzip2Stream);
                                    string typeStr  = new string(descripOfDataMomentType.dataMomentName);
                                    uint   binGates = descripOfDataMomentType.numberOfDataMomentGates;
                                    float  scale    = descripOfDataMomentType.scaLe;
                                    float  offset   = descripOfDataMomentType.offset;
                                    int    nSize    = 0;
                                    switch (typeStr)
                                    {
                                    case "REF":
                                        nSize = (int)binGates;
                                        byte[] mDBZ = new byte[nSize];
                                        bzip2Stream.Read(mDBZ, 0, nSize);
                                        for (int binNum = 0; binNum < 1192; binNum++)
                                        {
                                            DBZ[elIndex, azIndex, binNum + 8] =
                                                Decode(mDBZ[binNum], scale, offset);
                                        }
                                        break;

                                    case "VEL":
                                        nSize = (int)binGates;
                                        byte[] mVEL = new byte[nSize];
                                        bzip2Stream.Read(mVEL, 0, nSize);
                                        for (int binNum = 0; binNum < binGates; binNum++)
                                        {
                                            VEL[elIndex, azIndex, binNum + 8] =
                                                Decode(mVEL[binNum], scale, offset);
                                        }
                                        break;

                                    case "SW ":
                                        nSize = (int)binGates;
                                        byte[] mSW = new byte[nSize];
                                        bzip2Stream.Read(mSW, 0, nSize);
                                        for (int binNum = 0; binNum < binGates; binNum++)
                                        {
                                            SW[elIndex, azIndex, binNum + 8] =
                                                Decode(mSW[binNum], scale, offset);
                                        }
                                        break;

                                    case "RHO":
                                        nSize = (int)binGates;
                                        byte[] mRHO = new byte[nSize];
                                        bzip2Stream.Read(mRHO, 0, nSize);
                                        for (int binNum = 0; binNum < binGates; binNum++)
                                        {
                                            RHO[elIndex, azIndex, binNum + 8] =
                                                Decode(mRHO[binNum], scale, offset);
                                        }
                                        break;

                                    case "PHI":
                                        nSize = (int)binGates * 2;
                                        byte[] mPHI = new byte[nSize];
                                        bzip2Stream.Read(mPHI, 0, nSize);
                                        for (int binNum = 0; binNum < binGates; binNum++)
                                        {
                                            PHI[elIndex, azIndex, binNum + 8] =
                                                DecodeUInt16(mPHI[binNum], scale, offset);
                                        }
                                        break;

                                    case "ZDR":
                                        nSize = (int)binGates;
                                        byte[] mZDR = new byte[nSize];
                                        bzip2Stream.Read(mZDR, 0, nSize);
                                        for (int binNum = 0; binNum < binGates; binNum++)
                                        {
                                            ZDR[elIndex, azIndex, binNum + 8] =
                                                Decode(mZDR[binNum], scale, offset);
                                        }
                                        break;

                                    default:
                                        break;
                                    }
                                }
                                azIndex = azIndex + 1;
                            } while (radialStatus != 2);
                        }
                    }
                    catch (System.IndexOutOfRangeException)
                    {
                        Console.WriteLine("雷达数据读取故障!!");
                    }
                    finally
                    {
                        bzip2Stream.Close();
                    }
                    //**************************内存空间占用490MB*********************************//
                    DateTime t2     = DateTime.Now;
                    var      sorted = Sort(azimuth);
                    //Console.WriteLine("ReadStructure函数耗时:" + dTimeTotal_ReadStructure);
                    //Console.WriteLine("ReadMoment函数耗时:" + dTimeTotal_ReadMoment);
                    //Console.WriteLine("以上耗时:" + (t2 - t1).TotalMilliseconds);
                    // 30MB
                    frmpg.nProgress = 40;
                    dbz             = Reset("REF", sorted, DBZ);
                    vel             = Reset("VEL", sorted, VEL);
                    sw              = Reset("SW ", sorted, SW);
                    zdr             = Reset("ZDR", sorted, ZDR);
                    rho             = Reset("RHO", sorted, RHO);
                    phi             = Reset("PHI", sorted, PHI);
                    frmpg.nProgress = 45;

                    DBZ = null;
                    VEL = null;
                    SW  = null;
                    ZDR = null;
                    RHO = null;
                    PHI = null;
                    System.GC.Collect();


                    //************************内存空间占用657.4*************************************//
                }
                fs.Close();
            }

            QualityControl qc = new QualityControl(phi, dbz, rho);

            KDP = qc.GetKdpData(frmpg);
            return(new DprRdaData(dbz, vel, sw, rho, phi, zdr, KDP, ElevationData));
        }
Exemple #2
0
        private float[,,] Reset(string str, List <List <int> > sorted, float[,,] val)
        {
            float[,,] sort = DataInitial <float> .GetResult(9, 720, val.GetLength(2), -999);

            List <int> layer = new List <int>()
            {
                0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
            };

            switch (str)
            {
            case "REF":
            case "PHI":
            case "RHO":
            case "ZDR":
                //int[] layer = {0,2,4,5,6,7,8,9,10};
                layer.Remove(1);
                layer.Remove(3);
                foreach (int i in layer)
                {
                    var list = sorted[i];
                    if (i == 0 || i == 2)
                    {
                        for (int j = 0; j < 720; j++)
                        {
                            for (int k = 0; k < val.GetLength(2); k++)
                            {
                                sort[i / 2, j, k] = val[i, list[j], k];
                            }
                        }
                    }
                    else if (i > 3)
                    {
                        for (int j = 0; j < 360; j++)
                        {
                            for (int k = 0; k < val.GetLength(2); k++)
                            {
                                sort[i - 2, j, k] = val[i, list[j], k];
                            }
                        }
                    }
                }
                break;

            case "VEL":
            case "SW ":
                layer.Remove(0);
                layer.Remove(2);
                foreach (int i in layer)
                {
                    var list = sorted[i];
                    if (i == 1 || i == 3)
                    {
                        for (int j = 0; j < 720; j++)
                        {
                            for (int k = 0; k < val.GetLength(2); k++)
                            {
                                sort[(i - 1) / 2, j, k] = val[i, list[j], k];
                            }
                        }
                    }
                    else if (i > 3)
                    {
                        for (int j = 0; j < 360; j++)
                        {
                            for (int k = 0; k < val.GetLength(2); k++)
                            {
                                sort[i - 2, j, k] = val[i, list[j], k];
                            }
                        }
                    }
                }
                break;

            default:
                break;
            }
            return(sort);
        }