Exemplo n.º 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
Exemplo n.º 2
0
        // --Commented out by Inspection START (11/16/05 2:14 PM):
        //   public Grib2Product(){
        //   }
        // --Commented out by Inspection STOP (11/16/05 2:14 PM)

        /// <summary> Constructor.</summary>
        /// <param name="header">
        /// </param>
        /// <param name="is">
        /// </param>
        /// <param name="id">
        /// </param>
        /// <param name="gdsKey">
        /// </param>
        /// <param name="pds">
        /// </param>
        /// <param name="GdsOffset">
        /// </param>
        /// <param name="PdsOffset">PDS offset in Grib file
        /// </param>
        public Grib2Product(System.String header, Grib2IndicatorSection is_Renamed, Grib2IdentificationSection id, System.String gdsKey, Grib2ProductDefinitionSection pds, long GdsOffset, long PdsOffset)
        {
            this.header        = header;
            this.discipline    = is_Renamed.Discipline;
            this.id            = id;
            this.referenceTime = id.ReferenceTime;
            this.gdsKey        = gdsKey;
            this.pds           = pds;
            this.GdsOffset     = GdsOffset;
            this.PdsOffset     = PdsOffset;
        }
Exemplo n.º 3
0
 /// <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;
 }
Exemplo n.º 4
0
        /// <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;
        }
Exemplo n.º 5
0
        /// <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
Exemplo n.º 6
0
 /// <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;
 }
Exemplo n.º 7
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;
        }
Exemplo n.º 8
0
 // --Commented out by Inspection START (11/16/05 2:14 PM):
 //   public Grib2Product(){
 //   }
 // --Commented out by Inspection STOP (11/16/05 2:14 PM)
 /// <summary> Constructor.</summary>
 /// <param name="header">
 /// </param>
 /// <param name="is">
 /// </param>
 /// <param name="id">
 /// </param>
 /// <param name="gdsKey">
 /// </param>
 /// <param name="pds">
 /// </param>
 /// <param name="GdsOffset">
 /// </param>
 /// <param name="PdsOffset">PDS offset in Grib file
 /// </param>
 public Grib2Product(System.String header, Grib2IndicatorSection is_Renamed, Grib2IdentificationSection id, System.String gdsKey, Grib2ProductDefinitionSection pds, long GdsOffset, long PdsOffset)
 {
     this.header = header;
     this.discipline = is_Renamed.Discipline;
     this.id = id;
     this.referenceTime = id.ReferenceTime;
     this.gdsKey = gdsKey;
     this.pds = pds;
     this.GdsOffset = GdsOffset;
     this.PdsOffset = PdsOffset;
 }