コード例 #1
0
        /// <summary> Reads the Grib data with a certain offsets in the file.
        ///
        /// </summary>
        /// <param name="GdsOffset">
        /// </param>
        /// <param name="PdsOffset">
        /// </param>
        /// <throws>  IOException  if raf does not contain a valid GRIB record. </throws>
        /// <returns> float[]
        /// </returns>
        public float[] getData(long GdsOffset, long PdsOffset)
        {
            if (raf == null)
            {
                throw new ApplicationException("Grib2Input.scan called without file");
            }

            long start = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;

            raf.Seek(GdsOffset, System.IO.SeekOrigin.Begin);

            // Need section 3, 4, 5, 6, and 7 to read/interpet the data
            Grib2GridDefinitionSection gds = new Grib2GridDefinitionSection(raf, false);  // Section 3 no checksum

            raf.Seek(PdsOffset, System.IO.SeekOrigin.Begin);                              // could have more than one pds for a gds
            Grib2ProductDefinitionSection pds = new Grib2ProductDefinitionSection(raf);   // Section 4

            Grib2DataRepresentationSection drs = new Grib2DataRepresentationSection(raf); // Section 5

            Grib2BitMapSection bms = new Grib2BitMapSection(raf, gds);                    // Section 6

            Grib2DataSection ds = new Grib2DataSection(true, raf, gds, drs, bms);         // Section 7

            //System.out.println("DS offset=" + ds.getOffset() );

            return(ds.Data);
        } // end getData
コード例 #2
0
ファイル: Grib2DataSection.cs プロジェクト: talanta/GribCsPcl
        private int Xlength; // length of the x axis

        #endregion Fields

        #region Constructors

        // *** constructors *******************************************************
        /// <summary> Constructor for a Grib2 Data Section.</summary>
        /// <param name="getData">
        /// </param>
        /// <param name="raf">
        /// </param>
        /// <param name="gds">
        /// </param>
        /// <param name="drs">
        /// </param>
        /// <param name="bms">
        /// </param>
        /// <throws>  IOException </throws>
        //UPGRADE_TODO: Class 'java.io.RandomAccessFile' was converted to 'Stream' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioRandomAccessFile'"
        public Grib2DataSection(bool getData, Stream raf, Grib2GridDefinitionSection gds, Grib2DataRepresentationSection drs, Grib2BitMapSection bms)
        {
            //System.out.println( "raf.FilePointer=" + raf.FilePointer() );
            // octets 1-4 (Length of DS)
            length = GribNumbers.int4(raf);
            //System.out.println( "DS length=" + length );
            //System.out.println( "DS calculated end=" + ( raf.getFilePointer() + length -4 ));
            // octet 5  section 7
            section = raf.ReadByte();
            //System.out.println( "DS is 7, section=" + section );
            if (!getData)
            {
                // skip data read
                //System.out.println( "raf.position before reposition="+raf.getFilePointer());
                //System.out.println( "raf.length=" + raf.length() );
                // sanity check for erronous ds length
                if (length > 0 && length < raf.Length)
                {
                    SupportClass.Skip(raf, length - 5);
                    //System.out.println( "raf.skipBytes = " + (length -5) );
                }
                else
                {
                    length = 5; // only read length and section
                }
                //System.out.println( "raf.position after skip=" + raf.getFilePointer() );
                return ;
            }
            int dtn = drs.DataTemplateNumber;
            //System.out.println( "DS dtn=" + dtn );
            if (dtn == 0 || dtn == 1)
            {
                // 0: Grid point data - simple packing
                // 1: Matrix values - simple packing
                simpleUnpacking(raf, gds, drs, bms);
            }
            else if (dtn == 2)
            {
                // 2:Grid point data - complex packing
                complexUnpacking(raf, gds, drs);
            }
            else if (dtn == 3)
            {
                // 3: complex packing with spatial differencing
                complexUnpackingWithSpatial(raf, gds, drs);
            }
            else if (dtn == 40 || dtn == 40000)
            {
                throw new NotImplementedException ("JPEG 2000 Stream Format");
                // JPEG 2000 Stream Format
                //jpeg2000Unpacking(raf, gds, drs, bms);
            }
        }
コード例 #3
0
ファイル: Grib2Record.cs プロジェクト: baks/GribCS
 /// <summary> Construction for Grib2Record.</summary>
 /// <param name="header">
 /// </param>
 /// <param name="is">
 /// </param>
 /// <param name="id">
 /// </param>
 /// <param name="gds">
 /// </param>
 /// <param name="pds">
 /// </param>
 /// <param name="drs">
 /// </param>
 /// <param name="bms">
 /// </param>
 /// <param name="GdsOffset">
 /// </param>
 /// <param name="PdsOffset">PDS offset in Grib file
 /// </param>
 public Grib2Record(System.String header, Grib2IndicatorSection is_Renamed,
                    Grib2IdentificationSection id, Grib2GridDefinitionSection gds,
                    Grib2ProductDefinitionSection pds, Grib2DataRepresentationSection drs,
                    Grib2BitMapSection bms, long GdsOffset, long PdsOffset,
                    Grib2LocalUseSection lus)
 {
     this.header     = header;
     this.is_Renamed = is_Renamed;
     this.id         = id;
     this.gds        = gds;
     this.pds        = pds;
     this.drs        = drs;
     //this.bms = bms;
     this.GdsOffset = GdsOffset;
     this.PdsOffset = PdsOffset;
     this.lus       = lus;
 }
コード例 #4
0
ファイル: Grib2Input.cs プロジェクト: rzee7/WeatherConsole
        /// <summary> scans the Grib2 file obtaining Products or Records that contain all 
        /// needed information for data extraction later. For most purposes, 
        /// getProductsOnly should be set to true, it's lightweight of getRecords.
        /// </summary>
        /// <param name="getProductsOnly">
        /// </param>
        /// <param name="oneRecord">
        /// </param>
        /// <returns> success
        /// </returns>
        /// <throws>  NotSupportedException </throws>
        /// <throws>  IOException </throws>
        public bool scan(bool getProductsOnly, bool oneRecord)
        {
            if (raf == null)
            {
                throw new ApplicationException("Grib2Input.scan called without file");
            }

            long start = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;

            Grib2IndicatorSection is_Renamed = null;
            Grib2IdentificationSection id = null;
            Grib2LocalUseSection lus = null;
            Grib2GridDefinitionSection gds = null;
            // if raf.getFilePointer() != 0 then called from Grib2IndexExtender
            if (raf.Position > 4)
            {
                raf.Seek(raf.Position - 4, System.IO.SeekOrigin.Begin);
                Grib2EndSection es = new Grib2EndSection(raf);
                if (!es.EndFound)
                {
                    // ending found somewhere in file
                    throw new NoValidGribException("Grib2Input.scan failed to find end of record");
                }
                //System.out.println( "Scan succeeded to find end of record");
            }
            //System.out.println("Scan file pointer =" + raf.getFilePointer());
            long GdsOffset = 0; // GDS offset from start of file
            bool startAtHeader = true; // otherwise skip to GDS
            bool processGDS = true;
            while (raf.Position < raf.Length)
            {
                if (startAtHeader)
                {
                    // begining of record
                    if (!seekHeader(raf, raf.Length))
                    {
                        //System.out.println( "Scan seekHeader failed" );
                        throw new NoValidGribException("Grib2Input.scan failed to find header");
                    }

                    // Read Section 0 Indicator Section
                    is_Renamed = new Grib2IndicatorSection(raf); // section 0
                    //System.out.println( "Grib record length=" + is.getGribLength());

                    // Read other Sections
                    id = new Grib2IdentificationSection(raf); // Section 1
                } // end startAtHeader
                if (processGDS)
                {
                    // check for Local Use Section 2
                    lus = new Grib2LocalUseSection(raf);

                    // obtain GDS offset in the file for this record
                    GdsOffset = raf.Position;

                    // Section 3
                    gds = new Grib2GridDefinitionSection(raf, getProductsOnly);
                    //System.out.println( "GDS length=" + gds.getLength() );
                } // end processGDS

                // obtain PDS offset in the file for this record
                long PdsOffset = raf.Position;

                Grib2ProductDefinitionSection pds = new Grib2ProductDefinitionSection(raf); // Section 4

                Grib2DataRepresentationSection drs = null;
                Grib2BitMapSection bms = null;
                Grib2DataSection ds = null;
                drs = new Grib2DataRepresentationSection(raf); // Section 5

                bms = new Grib2BitMapSection(raf, gds); // Section 6

                //ds =  new Grib2DataSection( getData, raf, gds, drs, bms ); //Section 7
                ds = new Grib2DataSection(false, raf, gds, drs, bms); //Section 7

                // assume scan ok
                if (getProductsOnly)
                {
                    Grib2Product gp = new Grib2Product(header, is_Renamed, id, getGDSkey(gds), pds, GdsOffset, PdsOffset);
                    products.Add(gp);
                }
                else
                {
                    Grib2Record gr = new Grib2Record(header, is_Renamed, id, gds, pds, drs, bms, GdsOffset, PdsOffset, lus);
                    records.Add(gr);
                }
                if (oneRecord)
                    return true;

                // early return because ending "7777" missing
                if (raf.Position > raf.Length)
                {
                    raf.Seek(0, System.IO.SeekOrigin.Begin);
                    return true;
                }

                // EndSection processing section 8
                int ending = GribNumbers.int4(raf);
                //System.out.println( "ending = " + ending );
                if (ending == 926365495)
                {
                    // record ending string 7777 as a number
                    startAtHeader = true;
                    processGDS = true;
                }
                else
                {
                    int section = raf.ReadByte(); // check if GDS or PDS section, 3 or 4
                    //System.out.println( "section = " + section );
                    //reset back to begining of section
                    raf.Seek(raf.Position - 5, System.IO.SeekOrigin.Begin);

                    if (section == 3)
                    {
                        // start processing at GDS
                        startAtHeader = false;
                        processGDS = true;
                    }
                    else if (section == 4)
                    {
                        // start processing at PDS
                        startAtHeader = false;
                        processGDS = false;
                    }
                    else
                    {
                        // error
                        Grib2EndSection es = new Grib2EndSection(raf);
                        if (es.EndFound)
                        {
                            // ending found somewhere in file
                            startAtHeader = true;
                            processGDS = true;
                        }
                        else
                        {
                            //System.err.println( "Grib2Input: possible file corruption");
                            throw new NoValidGribException("Grib2Input.scan failed to find end of record");
                        }
                    }
                }
                //System.out.println( "raf.getFilePointer=" + raf.getFilePointer() );
                //System.out.println( "raf.length()=" + raf.length() );
            } // end raf.getFilePointer() < raf.length()
            //System.out.println("GribInput: processed in " +
            //   (System.currentTimeMillis()- start) + " milliseconds");
            return true;
        }
コード例 #5
0
ファイル: Grib2Input.cs プロジェクト: baks/GribCS
        /// <summary> scans the Grib2 file obtaining Products or Records that contain all
        /// needed information for data extraction later. For most purposes,
        /// getProductsOnly should be set to true, it's lightweight of getRecords.
        /// </summary>
        /// <param name="getProductsOnly">
        /// </param>
        /// <param name="oneRecord">
        /// </param>
        /// <returns> success
        /// </returns>
        /// <throws>  NotSupportedException </throws>
        /// <throws>  IOException </throws>
        public bool scan(bool getProductsOnly, bool oneRecord)
        {
            if (raf == null)
            {
                throw new ApplicationException("Grib2Input.scan called without file");
            }

            long start = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;

            Grib2IndicatorSection      is_Renamed = null;
            Grib2IdentificationSection id         = null;
            Grib2LocalUseSection       lus        = null;
            Grib2GridDefinitionSection gds        = null;

            // if raf.getFilePointer() != 0 then called from Grib2IndexExtender
            if (raf.Position > 4)
            {
                raf.Seek(raf.Position - 4, System.IO.SeekOrigin.Begin);
                Grib2EndSection es = new Grib2EndSection(raf);
                if (!es.EndFound)
                {
                    // ending found somewhere in file
                    throw new NoValidGribException("Grib2Input.scan failed to find end of record");
                }
                //System.out.println( "Scan succeeded to find end of record");
            }
            //System.out.println("Scan file pointer =" + raf.getFilePointer());
            long GdsOffset     = 0;         // GDS offset from start of file
            bool startAtHeader = true;      // otherwise skip to GDS
            bool processGDS    = true;

            while (raf.Position < raf.Length)
            {
                if (startAtHeader)
                {
                    // begining of record
                    if (!seekHeader(raf, raf.Length))
                    {
                        //System.out.println( "Scan seekHeader failed" );
                        throw new NoValidGribException("Grib2Input.scan failed to find header");
                    }

                    // Read Section 0 Indicator Section
                    is_Renamed = new Grib2IndicatorSection(raf);                     // section 0
                    //System.out.println( "Grib record length=" + is.getGribLength());

                    if (is_Renamed.GribEdition != 2)
                    {
                        throw new NoValidGribException("Grib2Input.scan expected GRIB2 file");
                    }

                    // Read other Sections
                    id = new Grib2IdentificationSection(raf); // Section 1
                }                                             // end startAtHeader
                if (processGDS)
                {
                    // check for Local Use Section 2
                    lus = new Grib2LocalUseSection(raf);

                    // obtain GDS offset in the file for this record
                    GdsOffset = raf.Position;

                    // Section 3
                    gds = new Grib2GridDefinitionSection(raf, getProductsOnly);
                    //System.out.println( "GDS length=" + gds.getLength() );
                }                 // end processGDS

                // obtain PDS offset in the file for this record
                long PdsOffset = raf.Position;

                Grib2ProductDefinitionSection pds = new Grib2ProductDefinitionSection(raf);                 // Section 4

                Grib2DataRepresentationSection drs = null;
                Grib2BitMapSection             bms = null;
                Grib2DataSection ds = null;
                drs = new Grib2DataRepresentationSection(raf);          // Section 5

                bms = new Grib2BitMapSection(raf, gds);                 // Section 6

                //ds =  new Grib2DataSection( getData, raf, gds, drs, bms ); //Section 7
                ds = new Grib2DataSection(false, raf, gds, drs, bms);                 //Section 7

                // assume scan ok
                if (getProductsOnly)
                {
                    Grib2Product gp = new Grib2Product(header, is_Renamed, id, getGDSkey(gds), pds, GdsOffset, PdsOffset);
                    products.Add(gp);
                }
                else
                {
                    Grib2Record gr = new Grib2Record(header, is_Renamed, id, gds, pds, drs, bms, GdsOffset, PdsOffset, lus);
                    records.Add(gr);
                }
                if (oneRecord)
                {
                    return(true);
                }

                // early return because ending "7777" missing
                if (raf.Position > raf.Length)
                {
                    raf.Seek(0, System.IO.SeekOrigin.Begin);
                    return(true);
                }

                // EndSection processing section 8
                int ending = GribNumbers.int4(raf);
                //System.out.println( "ending = " + ending );
                if (ending == 926365495)
                {
                    // record ending string 7777 as a number
                    startAtHeader = true;
                    processGDS    = true;
                }
                else
                {
                    int section = raf.ReadByte();                     // check if GDS or PDS section, 3 or 4
                    //System.out.println( "section = " + section );
                    //reset back to begining of section
                    raf.Seek(raf.Position - 5, System.IO.SeekOrigin.Begin);

                    if (section == 3)
                    {
                        // start processing at GDS
                        startAtHeader = false;
                        processGDS    = true;
                    }
                    else if (section == 4)
                    {
                        // start processing at PDS
                        startAtHeader = false;
                        processGDS    = false;
                    }
                    else
                    {
                        // error
                        Grib2EndSection es = new Grib2EndSection(raf);
                        if (es.EndFound)
                        {
                            // ending found somewhere in file
                            startAtHeader = true;
                            processGDS    = true;
                        }
                        else
                        {
                            //System.err.println( "Grib2Input: possible file corruption");
                            throw new NoValidGribException("Grib2Input.scan failed to find end of record");
                        }
                    }
                }
                //System.out.println( "raf.getFilePointer=" + raf.getFilePointer() );
                //System.out.println( "raf.length()=" + raf.length() );
            }             // end raf.getFilePointer() < raf.length()
            //System.out.println("GribInput: processed in " +
            //   (System.currentTimeMillis()- start) + " milliseconds");
            return(true);
        }         // end scan
コード例 #6
0
ファイル: Grib2Record.cs プロジェクト: rzee7/WeatherConsole
 /// <summary> Construction for Grib2Record.</summary>
 /// <param name="header">
 /// </param>
 /// <param name="is">
 /// </param>
 /// <param name="id">
 /// </param>
 /// <param name="gds">
 /// </param>
 /// <param name="pds">
 /// </param>
 /// <param name="drs">
 /// </param>
 /// <param name="bms">
 /// </param>
 /// <param name="GdsOffset">
 /// </param>
 /// <param name="PdsOffset">PDS offset in Grib file
 /// </param>
 public Grib2Record(System.String header, Grib2IndicatorSection is_Renamed, 
     Grib2IdentificationSection id, Grib2GridDefinitionSection gds,
     Grib2ProductDefinitionSection pds, Grib2DataRepresentationSection drs,
     Grib2BitMapSection bms, long GdsOffset, long PdsOffset,
     Grib2LocalUseSection lus)
 {
     this.header = header;
     this.is_Renamed = is_Renamed;
     this.id = id;
     this.gds = gds;
     this.pds = pds;
     this.drs = drs;
     //this.bms = bms;
     this.GdsOffset = GdsOffset;
     this.PdsOffset = PdsOffset;
     this.lus = lus;
 }
コード例 #7
0
ファイル: Grib2Data.cs プロジェクト: rzee7/WeatherConsole
        /// <summary> Reads the Grib data with a certain offsets in the file.
        /// 
        /// </summary>
        /// <param name="GdsOffset">
        /// </param>
        /// <param name="PdsOffset">
        /// </param>
        /// <throws>  IOException  if raf does not contain a valid GRIB record. </throws>
        /// <returns> float[]
        /// </returns>
        public float[] getData(long GdsOffset, long PdsOffset)
        {
            if (raf == null)
            {
                throw new ApplicationException("Grib2Input.scan called without file");
            }

            long start = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;

            raf.Seek(GdsOffset, System.IO.SeekOrigin.Begin);

            // Need section 3, 4, 5, 6, and 7 to read/interpet the data
            Grib2GridDefinitionSection gds = new Grib2GridDefinitionSection(raf, false); // Section 3 no checksum

            raf.Seek(PdsOffset, System.IO.SeekOrigin.Begin); // could have more than one pds for a gds
            Grib2ProductDefinitionSection pds = new Grib2ProductDefinitionSection(raf); // Section 4

            Grib2DataRepresentationSection drs = new Grib2DataRepresentationSection(raf); // Section 5

            Grib2BitMapSection bms = new Grib2BitMapSection(raf, gds); // Section 6

            Grib2DataSection ds = new Grib2DataSection(true, raf, gds, drs, bms); // Section 7
            //System.out.println("DS offset=" + ds.getOffset() );

            return ds.Data;
        }
コード例 #8
0
        }         // end complexUnpackingWithSpatial

        /// <summary> Jpeg2000 unpacking method for Grib2 data.</summary>
        /// <param name="raf">
        /// </param>
        /// <param name="gds">
        /// </param>
        /// <param name="drs">
        /// </param>
        /// <param name="bms">bit-map section object
        /// </param>
        //UPGRADE_TODO: Class 'java.io.RandomAccessFile' was converted to 'System.IO.FileStream' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioRandomAccessFile'"
        private void  jpeg2000Unpacking(System.IO.FileStream raf, Grib2GridDefinitionSection gds, Grib2DataRepresentationSection drs, Grib2BitMapSection bms)
        {
            // 6-xx  jpeg2000 data block to decode

            // dataPoints are number of points encoded, it could be less than the
            // numberPoints in the grid record if bitMap is used, otherwise equal
            int dataPoints = drs.DataPoints;
            //System.out.println( "DS DRS dataPoints=" + drs.getDataPoints() );
            //System.out.println( "DS length=" + length );

            float pmv = drs.PrimaryMissingValue;
            //System.out.println( "DS pmv=" + pmv );
            int nb = drs.NumberOfBits;
            //System.out.println( "DS nb = " + nb );

            int D = drs.DecimalScaleFactor;
            //System.out.println( "DS D=" + D );
            //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
            float DD = (float)System.Math.Pow((double)10, (double)D);
            //System.out.println( "DS DD=" + DD );

            float R = drs.ReferenceValue;
            //System.out.println( "DS R=" + R );

            int E = drs.BinaryScaleFactor;
            //System.out.println( "DS E=" + E );
            //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
            float EE = (float)System.Math.Pow((double)2.0, (double)E);
            //System.out.println( "DS EE=" + EE );

            /*Grib2JpegDecoder g2j = null;
             * if (nb != 0)
             * {
             *      // there's data to decode
             *      System.String[] argv = new System.String[4];
             *      argv[0] = "-rate";
             *      argv[1] = System.Convert.ToString(nb);
             *      argv[2] = "-verbose";
             *      argv[3] = "off";
             *      //argv[ 2 ] = "-nocolorspace" ;
             *      //argv[ 3 ] = "-Rno_roi" ;
             *      //argv[ 4 ] = "-cdstr_info" ;
             *      //argv[ 5 ] = "-verbose" ;
             *      //argv[ 6 ] = "-debug" ;
             *      g2j = new Grib2JpegDecoder(argv);
             *      g2j.decode(raf, length - 5);
             * }
             */

            Jpeg2000Decoder decoder = new Jpeg2000Decoder();

            byte[] buf = new byte[length - 5];
            // TODO Check cast
            int res = raf.Read(buf, 0, length - 5);

            int[] values = null;
            if (res == length - 5)
            {
                values = decoder.Decode(buf, dataPoints);
            }
            else
            {
                // TODO Error handling
            }

            int numberPoints = gds.NumberPoints;

            //System.out.println( "DS GDS NumberPoints=" +  gds.getNumberPoints() );
            data = new float[numberPoints];
            bool[] bitmap = bms.Bitmap;

            if (bitmap == null)
            {
                if (nb == 0)
                {
                    // no data decoded, set to primaryMissingValue
                    for (int i = 0; i < numberPoints; i++)
                    {
                        data[i] = pmv;
                    }
                }
                else
                {
                    //System.out.println( "DS jpeg data length ="+ g2j.data.length );
                    // record has missing bitmap
                    if (values.Length != numberPoints)
                    {
                        data = null;
                        return;
                    }
                    for (int i = 0; i < numberPoints; i++)
                    {
                        //Y = (R + ( 0 + X2) * EE)/DD ;
                        data[i] = (R + values[i] * EE) / DD;
                        //System.out.println( "DS data[ " + i +"  ]=" + data[ i ] );
                    }
                }
            }
            else
            {
                for (int i = 0, j = 0; i < bitmap.Length; i++)
                {
                    if (bitmap[i])
                    {
                        data[i] = (R + values[j++] * EE) / DD;
                    }
                    else
                    {
                        data[i] = pmv;
                    }
                }
            }
            scanMode = gds.ScanMode;
            scanningModeCheck();
        }         // end jpeg2000Unpacking
コード例 #9
0
        private int Xlength;       // length of the x axis

        // *** constructors *******************************************************

        /// <summary> Constructor for a Grib2 Data Section.</summary>
        /// <param name="getData">
        /// </param>
        /// <param name="raf">
        /// </param>
        /// <param name="gds">
        /// </param>
        /// <param name="drs">
        /// </param>
        /// <param name="bms">
        /// </param>
        /// <throws>  IOException </throws>
        //UPGRADE_TODO: Class 'java.io.RandomAccessFile' was converted to 'System.IO.FileStream' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioRandomAccessFile'"
        public Grib2DataSection(bool getData, System.IO.FileStream raf, Grib2GridDefinitionSection gds, Grib2DataRepresentationSection drs, Grib2BitMapSection bms)
        {
            //System.out.println( "raf.FilePointer=" + raf.FilePointer() );
            // octets 1-4 (Length of DS)
            length = GribNumbers.int4(raf);
            //System.out.println( "DS length=" + length );
            //System.out.println( "DS calculated end=" + ( raf.getFilePointer() + length -4 ));
            // octet 5  section 7
            section = raf.ReadByte();
            //System.out.println( "DS is 7, section=" + section );
            if (!getData)
            {
                // skip data read
                //System.out.println( "raf.position before reposition="+raf.getFilePointer());
                //System.out.println( "raf.length=" + raf.length() );
                // sanity check for erronous ds length
                if (length > 0 && length < raf.Length)
                {
                    SupportClass.Skip(raf, length - 5);
                    //System.out.println( "raf.skipBytes = " + (length -5) );
                }
                else
                {
                    length = 5;                     // only read length and section
                }
                //System.out.println( "raf.position after skip=" + raf.getFilePointer() );
                return;
            }
            int dtn = drs.DataTemplateNumber;

            //System.out.println( "DS dtn=" + dtn );
            if (dtn == 0 || dtn == 1)
            {
                // 0: Grid point data - simple packing
                // 1: Matrix values - simple packing
                simpleUnpacking(raf, gds, drs, bms);
            }
            else if (dtn == 2)
            {
                // 2:Grid point data - complex packing
                complexUnpacking(raf, gds, drs);
            }
            else if (dtn == 3)
            {
                // 3: complex packing with spatial differencing
                complexUnpackingWithSpatial(raf, gds, drs);
            }
            else if (dtn == 40 || dtn == 40000)
            {
                // JPEG 2000 Stream Format
                jpeg2000Unpacking(raf, gds, drs, bms);
            }
        }         // end Grib2DataSection
コード例 #10
0
        }         // end Grib2DataSection

        /// <summary> simple Unpacking method for Grib2 data.</summary>
        /// <param name="raf">
        /// </param>
        /// <param name="gds">
        /// </param>
        /// <param name="drs">
        /// </param>
        /// <param name="bms">
        /// </param>
        /// <throws>  IOException </throws>
        //UPGRADE_TODO: Class 'java.io.RandomAccessFile' was converted to 'System.IO.FileStream' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioRandomAccessFile'"
        private void  simpleUnpacking(System.IO.FileStream raf, Grib2GridDefinitionSection gds, Grib2DataRepresentationSection drs, Grib2BitMapSection bms)
        {
            int dtn = drs.DataTemplateNumber;

            //System.out.println( "DS dtn=" + dtn );

            if (dtn == 1)
            {
                // Matrix values
                System.Console.Out.WriteLine("DS Matrix values not supported yet");
                return;
            }
            // dataPoints are number of points encoded, it could be less than the
            // numberPoints in the grid record if bitMap is used, otherwise equal
            int dataPoints = drs.DataPoints;
            //System.out.println( "DS DRS dataPoints=" + drs.getDataPoints() );
            float pmv = drs.PrimaryMissingValue;
            //System.out.println( "DS pmv=" + pmv );
            int nb = drs.NumberOfBits;
            //System.out.println( "DS nb=" + nb );
            int D = drs.DecimalScaleFactor;
            //System.out.println( "DS D=" + D );
            //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
            float DD = (float)System.Math.Pow((double)10, (double)D);
            //System.out.println( "DS DD=" + DD );
            float R = drs.ReferenceValue;
            //System.out.println( "DS R=" + R );
            int E = drs.BinaryScaleFactor;
            //System.out.println( "DS E=" + E );
            //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
            float EE = (float)System.Math.Pow((double)2.0, (double)E);
            //System.out.println( "DS EE=" + EE );

            int numberPoints = gds.NumberPoints;

            //System.out.println( "DS GDS NumberPoints=" +  gds.getNumberPoints() );
            data = new float[numberPoints];

            bool[] bitmap = bms.Bitmap;

            //  Y * 10**D = R + (X1 + X2) * 2**E
            //   E = binary scale factor
            //   D = decimal scale factor
            //   R = reference value
            //   X1 = 0
            //   X2 = scaled encoded value
            //   data[ i ] = (R + ( X1 + X2) * EE)/DD ;

            if (bitmap == null)
            {
                for (int i = 0; i < numberPoints; i++)
                {
                    //data[ i ] = (R + ( X1 + X2) * EE)/DD ;
                    data[i] = (R + bits2UInt(nb, raf) * EE) / DD;
                }
            }
            else
            {
                bitPos = 0;
                bitBuf = 0;
                for (int i = 0; i < bitmap.Length; i++)
                {
                    if (bitmap[i])
                    {
                        //data[ i ] = (R + ( X1 + X2) * EE)/DD ;
                        data[i] = (R + bits2UInt(nb, raf) * EE) / DD;
                    }
                    else
                    {
                        data[i] = pmv;
                    }
                }
            }
            scanMode = gds.ScanMode;
            Xlength  = gds.Nx; // needs some smarts for different type Grids
            //scanningModeCheck();
        }                      // end simpleUnpacking
コード例 #11
0
        /// <summary> simple Unpacking method for Grib2 data.</summary>
        /// <param name="raf">
        /// </param>
        /// <param name="gds">
        /// </param>
        /// <param name="drs">
        /// </param>
        /// <param name="bms">
        /// </param>
        /// <throws>  IOException </throws>
        //UPGRADE_TODO: Class 'java.io.RandomAccessFile' was converted to 'System.IO.FileStream' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioRandomAccessFile'"
        private void simpleUnpacking(System.IO.FileStream raf, Grib2GridDefinitionSection gds, Grib2DataRepresentationSection drs, Grib2BitMapSection bms)
        {
            int dtn = drs.DataTemplateNumber;
            //System.out.println( "DS dtn=" + dtn );

            if (dtn == 1)
            {
                // Matrix values
                System.Console.Out.WriteLine("DS Matrix values not supported yet");
                return ;
            }
            // dataPoints are number of points encoded, it could be less than the
            // numberPoints in the grid record if bitMap is used, otherwise equal
            int dataPoints = drs.DataPoints;
            //System.out.println( "DS DRS dataPoints=" + drs.getDataPoints() );
            float pmv = drs.PrimaryMissingValue;
            //System.out.println( "DS pmv=" + pmv );
            int nb = drs.NumberOfBits;
            //System.out.println( "DS nb=" + nb );
            int D = drs.DecimalScaleFactor;
            //System.out.println( "DS D=" + D );
            //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
            float DD = (float) System.Math.Pow((double) 10, (double) D);
            //System.out.println( "DS DD=" + DD );
            float R = drs.ReferenceValue;
            //System.out.println( "DS R=" + R );
            int E = drs.BinaryScaleFactor;
            //System.out.println( "DS E=" + E );
            //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
            float EE = (float) System.Math.Pow((double) 2.0, (double) E);
            //System.out.println( "DS EE=" + EE );

            int numberPoints = gds.NumberPoints;
            //System.out.println( "DS GDS NumberPoints=" +  gds.getNumberPoints() );
            data = new float[numberPoints];

            bool[] bitmap = bms.Bitmap;

            //  Y * 10**D = R + (X1 + X2) * 2**E
            //   E = binary scale factor
            //   D = decimal scale factor
            //   R = reference value
            //   X1 = 0
            //   X2 = scaled encoded value
            //   data[ i ] = (R + ( X1 + X2) * EE)/DD ;

            if (bitmap == null)
            {
                for (int i = 0; i < numberPoints; i++)
                {
                    //data[ i ] = (R + ( X1 + X2) * EE)/DD ;
                    data[i] = (R + bits2UInt(nb, raf) * EE) / DD;
                }
            }
            else
            {
                bitPos = 0;
                bitBuf = 0;
                for (int i = 0; i < bitmap.Length; i++)
                {
                    if (bitmap[i])
                    {
                        //data[ i ] = (R + ( X1 + X2) * EE)/DD ;
                        data[i] = (R + bits2UInt(nb, raf) * EE) / DD;
                    }
                    else
                    {
                        data[i] = pmv;
                    }
                }
            }
            scanMode = gds.ScanMode;
            Xlength = gds.Nx; // needs some smarts for different type Grids
            //scanningModeCheck();
        }
コード例 #12
0
        /// <summary> Jpeg2000 unpacking method for Grib2 data.</summary>
        /// <param name="raf">
        /// </param>
        /// <param name="gds">
        /// </param>
        /// <param name="drs">
        /// </param>
        /// <param name="bms">bit-map section object
        /// </param>
        //UPGRADE_TODO: Class 'java.io.RandomAccessFile' was converted to 'System.IO.FileStream' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioRandomAccessFile'"
        private void jpeg2000Unpacking(System.IO.FileStream raf, Grib2GridDefinitionSection gds, Grib2DataRepresentationSection drs, Grib2BitMapSection bms)
        {
            // 6-xx  jpeg2000 data block to decode

            // dataPoints are number of points encoded, it could be less than the
            // numberPoints in the grid record if bitMap is used, otherwise equal
            int dataPoints = drs.DataPoints;
            //System.out.println( "DS DRS dataPoints=" + drs.getDataPoints() );
            //System.out.println( "DS length=" + length );

            float pmv = drs.PrimaryMissingValue;
            //System.out.println( "DS pmv=" + pmv );
            int nb = drs.NumberOfBits;
            //System.out.println( "DS nb = " + nb );

            int D = drs.DecimalScaleFactor;
            //System.out.println( "DS D=" + D );
            //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
            float DD = (float) System.Math.Pow((double) 10, (double) D);
            //System.out.println( "DS DD=" + DD );

            float R = drs.ReferenceValue;
            //System.out.println( "DS R=" + R );

            int E = drs.BinaryScaleFactor;
            //System.out.println( "DS E=" + E );
            //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
            float EE = (float) System.Math.Pow((double) 2.0, (double) E);
            //System.out.println( "DS EE=" + EE );

            /*Grib2JpegDecoder g2j = null;
            if (nb != 0)
            {
                // there's data to decode
                System.String[] argv = new System.String[4];
                argv[0] = "-rate";
                argv[1] = System.Convert.ToString(nb);
                argv[2] = "-verbose";
                argv[3] = "off";
                //argv[ 2 ] = "-nocolorspace" ;
                //argv[ 3 ] = "-Rno_roi" ;
                //argv[ 4 ] = "-cdstr_info" ;
                //argv[ 5 ] = "-verbose" ;
                //argv[ 6 ] = "-debug" ;
                g2j = new Grib2JpegDecoder(argv);
                g2j.decode(raf, length - 5);
            }
             */

            Jpeg2000Decoder decoder = new Jpeg2000Decoder();
            byte[] buf = new byte[length-5];
            // TODO Check cast
            int res = raf.Read(buf, 0, length-5);
            int[] values = null;
            if( res == length-5 )
            {
                values = decoder.Decode(buf, dataPoints);
            }
            else
            {
                // TODO Error handling
            }

            int numberPoints = gds.NumberPoints;
            //System.out.println( "DS GDS NumberPoints=" +  gds.getNumberPoints() );
            data = new float[numberPoints];
            bool[] bitmap = bms.Bitmap;

            if (bitmap == null)
            {
                if (nb == 0)
                {
                    // no data decoded, set to primaryMissingValue
                    for (int i = 0; i < numberPoints; i++)
                    {
                        data[i] = pmv;
                    }
                }
                else
                {
                    //System.out.println( "DS jpeg data length ="+ g2j.data.length );
                    // record has missing bitmap
                    if (values.Length != numberPoints)
                    {
                        data = null;
                        return ;
                    }
                    for (int i = 0; i < numberPoints; i++)
                    {
                        //Y = (R + ( 0 + X2) * EE)/DD ;
                        data[i] = (R + values[i] * EE) / DD;
                        //System.out.println( "DS data[ " + i +"  ]=" + data[ i ] );
                    }
                }
            }
            else
            {
                for (int i = 0, j = 0; i < bitmap.Length; i++)
                {
                    if (bitmap[i])
                    {
                        data[i] = (R + values[j++] * EE) / DD;
                    }
                    else
                    {
                        data[i] = pmv;
                    }
                }
            }
            scanMode = gds.ScanMode;
            scanningModeCheck();
        }