Esempio n. 1
0
 /// <summary> Constructor.</summary>
 /// <param name="header">
 /// </param>
 /// <param name="pds">
 /// </param>
 /// <param name="gdsKey">
 /// </param>
 /// <param name="offset">
 /// </param>
 /// <param name="size">endRecordOffset in file
 /// </param>
 public Grib1Product(System.String header, Grib1ProductDefinitionSection pds, System.String gdsKey, long offset, long size)
 {
     this.header = header;
     this.gdsKey = gdsKey;
     this.pds = pds;
     this.dataOffset = offset;
     this.endRecordOffset = size;
 }
Esempio n. 2
0
 /// <summary> Constructor.</summary>
 /// <param name="header">
 /// </param>
 /// <param name="pds">
 /// </param>
 /// <param name="gdsKey">
 /// </param>
 /// <param name="offset">
 /// </param>
 /// <param name="size">endRecordOffset in file
 /// </param>
 public Grib1Product(System.String header, Grib1ProductDefinitionSection pds, System.String gdsKey, long offset, long size)
 {
     this.header          = header;
     this.gdsKey          = gdsKey;
     this.pds             = pds;
     this.dataOffset      = offset;
     this.endRecordOffset = size;
 }
Esempio n. 3
0
 /// <summary> Constructor.</summary>
 /// <param name="hdr">record header
 /// </param>
 /// <param name="aIs">IS section
 /// </param>
 /// <param name="aPds">PDS section
 /// </param>
 /// <param name="aGds">GDS section
 /// </param>
 /// <param name="offset">to the BMS/BDS section of file
 /// </param>
 /// <param name="recOffset">to the EndOfRecord
 /// </param>
 public Grib1Record(System.String hdr, Grib1IndicatorSection aIs, Grib1ProductDefinitionSection aPds, Grib1GridDefinitionSection aGds, long offset, long recOffset)
 {
     header          = hdr;
     is_Renamed      = aIs;
     pds             = aPds;
     gds             = aGds;
     dataOffset      = offset;
     endRecordOffset = recOffset;
 }
Esempio n. 4
0
        private long recordOffset = -1; // The byte offset of this grib record (message) in the file from which it was read.

        #endregion Fields

        #region Constructors

        /// <summary> Constructor.</summary>
        /// <param name="hdr">record header 
        /// </param>
        /// <param name="aIs">IS section
        /// </param>
        /// <param name="aPds">PDS section
        /// </param>
        /// <param name="aGds">GDS section
        /// </param>
        /// <param name="offset">to the BMS/BDS section of file
        /// </param>
        /// <param name="recOffset">to the EndOfRecord
        /// </param>
        public Grib1Record(System.String hdr, Grib1IndicatorSection aIs, Grib1ProductDefinitionSection aPds, Grib1GridDefinitionSection aGds, long offset, long recOffset)
        {
            header = hdr;
            is_Renamed = aIs;
            pds = aPds;
            gds = aGds;
            dataOffset = offset;
            endRecordOffset = recOffset;
        }
Esempio n. 5
0
        /// <summary> Constructs a <tt>Grib1Grid</tt> object from a pds.
        /// 
        /// </summary>
        /// <param name="pds">Grib1ProductDefinitionSection to formulate grib
        /// 
        /// </param>
        public Grib1Grid(Grib1ProductDefinitionSection pds)
            : base()
        {
            int generatingProcess = pds.Process_Id;
            int gridNumber = pds.Grid_Id;

            // checksum = 1000 + grid number
            checksum = "1000" + System.Convert.ToString(gridNumber);

            switch (gridNumber)
            {

                case 21:
                case 22:
                case 23:
                case 24:  {
                        type = 0; // Latitude/Longitude
                        name = getName(type);

                        // (Nx - number of points along x-axis)
                        nx = 37;

                        // (Ny - number of points along y-axis)
                        ny = 37;

                        // (resolution and component flags).  See Table 7
                        resolution = 0x88;

                        // (Dx - Longitudinal Direction Increment )
                        dx = 5.0;

                        // (Dy - Latitudinal Direction Increment )
                        dy = 2.5;

                        // (Scanning mode)  See Table 8
                        scan = 64;

                        if (gridNumber == 21)
                        {
                            // (La1 - latitude of first grid point)
                            lat1 = 0.0;

                            // (Lo1 - longitude of first grid point)
                            lon1 = 0.0;

                            // (La2 - latitude of last grid point)
                            lat2 = 90.0;

                            // (Lo2 - longitude of last grid point)
                            lon2 = 180.0;
                        }
                        else if (gridNumber == 22)
                        {
                            // (La1 - latitude of first grid point)
                            lat1 = 0.0;

                            // (Lo1 - longitude of first grid point)
                            lon1 = - 180.0;

                            // (La2 - latitude of last grid point)
                            lat2 = 90.0;

                            // (Lo2 - longitude of last grid point)
                            lon2 = 0.0;
                        }
                        else if (gridNumber == 23)
                        {
                            // (La1 - latitude of first grid point)
                            lat1 = - 90.0;

                            // (Lo1 - longitude of first grid point)
                            lon1 = 0.0;

                            // (La2 - latitude of last grid point)
                            lat2 = 0.0;

                            // (Lo2 - longitude of last grid point)
                            lon2 = 180.0;
                        }
                        else if (gridNumber == 24)
                        {
                            // (La1 - latitude of first grid point)
                            lat1 = - 90.0;

                            // (Lo1 - longitude of first grid point)
                            lon1 = - 180.0;

                            // (La2 - latitude of last grid point)
                            lat2 = 0.0;

                            // (Lo2 - longitude of last grid point)
                            lon2 = 0.0;
                        }
                    }
                    break;

                case 25:
                case 26:  {
                        type = 0; // Latitude/Longitude
                        name = getName(type);

                        // (Nx - number of points along x-axis)
                        nx = 72;

                        // (Ny - number of points along y-axis)
                        ny = 19;

                        // (resolution and component flags).  See Table 7
                        resolution = 0x88;

                        // (Dx - Longitudinal Direction Increment )
                        dx = 5.0;

                        // (Dy - Latitudinal Direction Increment )
                        dy = 5.0;

                        // (Scanning mode)  See Table 8
                        scan = 64;

                        if (gridNumber == 25)
                        {
                            // (La1 - latitude of first grid point)
                            lat1 = 0.0;

                            // (Lo1 - longitude of first grid point)
                            lon1 = 0.0;

                            // (La2 - latitude of last grid point)
                            lat2 = 90.0;

                            // (Lo2 - longitude of last grid point)
                            lon2 = 355.0;
                        }
                        else if (gridNumber == 26)
                        {
                            // (La1 - latitude of first grid point)
                            lat1 = - 90.0;

                            // (Lo1 - longitude of first grid point)
                            lon1 = 0.0;

                            // (La2 - latitude of last grid point)
                            lat2 = 0.0;

                            // (Lo2 - longitude of last grid point)
                            lon2 = 355.0;
                        }
                    }
                    break;

                case 61:
                case 62:
                case 63:
                case 64:  {
                        type = 0; // Latitude/Longitude
                        name = getName(type);

                        // (Nx - number of points along x-axis)
                        nx = 91;

                        // (Ny - number of points along y-axis)
                        ny = 46;

                        // (resolution and component flags).  See Table 7
                        resolution = 0x88;

                        // (Dx - Longitudinal Direction Increment )
                        dx = 2.0;

                        // (Dy - Latitudinal Direction Increment )
                        dy = 2.0;

                        // (Scanning mode)  See Table 8
                        scan = 64;

                        if (gridNumber == 61)
                        {
                            // (La1 - latitude of first grid point)
                            lat1 = 0.0;

                            // (Lo1 - longitude of first grid point)
                            lon1 = 0.0;

                            // (La2 - latitude of last grid point)
                            lat2 = 90.0;

                            // (Lo2 - longitude of last grid point)
                            lon2 = 180.0;
                        }
                        else if (gridNumber == 62)
                        {
                            // (La1 - latitude of first grid point)
                            lat1 = 0.0;

                            // (Lo1 - longitude of first grid point)
                            lon1 = - 180.0;

                            // (La2 - latitude of last grid point)
                            lat2 = 90.0;

                            // (Lo2 - longitude of last grid point)
                            lon2 = 0.0;
                        }
                        else if (gridNumber == 63)
                        {
                            // (La1 - latitude of first grid point)
                            lat1 = - 90.0;

                            // (Lo1 - longitude of first grid point)
                            lon1 = 0.0;

                            // (La2 - latitude of last grid point)
                            lat2 = 0.0;

                            // (Lo2 - longitude of last grid point)
                            lon2 = 180.0;
                        }
                        else if (gridNumber == 64)
                        {
                            // (La1 - latitude of first grid point)
                            lat1 = - 90.0;

                            // (Lo1 - longitude of first grid point)
                            lon1 = - 180.0;

                            // (La2 - latitude of last grid point)
                            lat2 = 0.0;

                            // (Lo2 - longitude of last grid point)
                            lon2 = 0.0;
                        }
                        break;
                    }

                default:
            //					System.Console.Out.WriteLine("Grid " + gridNumber + " not configured yet");
                    break;

            }
        }
Esempio n. 6
0
        /// <summary> scans a Grib file to gather information that could be used to
        /// create an index or dump the metadata contents.
        ///
        /// </summary>
        /// <param name="getProducts">products have enough information for data extractions
        /// </param>
        /// <param name="oneRecord">returns after processing one record in the Grib file
        /// </param>
        /// <throws>  NotSupportedException </throws>
        public void  scan(bool getProducts, bool oneRecord)
        {
            long start = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;

            // stores the number of times a particular GDS is used
            //UPGRADE_TODO: Class 'java.util.HashMap' was converted to 'System.Collections.Hashtable' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashMap'"
            System.Collections.Hashtable  gdsCounter = new System.Collections.Hashtable();
            Grib1ProductDefinitionSection pds        = null;
            Grib1GridDefinitionSection    gds        = null;
            long startOffset = -1;

            //System.out.println("file position =" + raf.Position);
            while (raf.Position < raf.Length)
            {
                if (seekHeader(raf, raf.Length, out startOffset))
                {
                    // Read Section 0 Indicator Section
                    Grib1IndicatorSection is_Renamed = new Grib1IndicatorSection(raf);
                    //System.out.println( "Grib record length=" + is.getGribLength());
                    // EOR (EndOfRecord) calculated so skipping data sections is faster
                    long EOR = raf.Position + is_Renamed.GribLength - is_Renamed.Length;

                    // Read Section 1 Product Definition Section PDS
                    pds = new Grib1ProductDefinitionSection(raf);
                    if (pds.LengthErr)
                    {
                        continue;
                    }

                    if (pds.gdsExists())
                    {
                        // Read Section 2 Grid Definition Section GDS
                        gds = new Grib1GridDefinitionSection(raf);
                    }
                    else
                    {
                        // GDS doesn't exist so make one
                        //System.out.println("GribRecord: No GDS included.");
                        //System.out.println("Process ID:" + pds.getProcess_Id() );
                        //System.out.println("Grid ID:" + pds.getGrid_Id() );
                        gds = (Grib1GridDefinitionSection) new Grib1Grid(pds);
                    }
                    // obtain BMS or BDS offset in the file for this product
                    long dataOffset = 0;
                    if (pds.Center == 98)
                    {
                        // check for ecmwf offset by 1 bug
                        int length = (int)GribNumbers.uint3(raf);                         // should be length of BMS
                        if ((length + raf.Position) < EOR)
                        {
                            dataOffset = raf.Position - 3;                             // ok
                        }
                        else
                        {
                            dataOffset = raf.Position - 2;
                        }
                    }
                    else
                    {
                        dataOffset = raf.Position;
                    }
                    // position filePointer to EndOfRecord
                    raf.Seek(EOR, System.IO.SeekOrigin.Begin);
                    //System.out.println("file offset = " + raf.Position);

                    // assume scan ok
                    if (getProducts)
                    {
                        Grib1Product gp = new Grib1Product(header, pds, getGDSkey(gds, gdsCounter), dataOffset, raf.Position);
                        products.Add(gp);
                    }
                    else
                    {
                        Grib1Record gr = new Grib1Record(header, is_Renamed, pds, gds, dataOffset, raf.Position, startOffset);
                        records.Add(gr);
                    }
                    if (oneRecord)
                    {
                        return;
                    }

                    // early return because ending "7777" missing
                    if (raf.Position > raf.Length)
                    {
                        raf.Seek(0, System.IO.SeekOrigin.Begin);
                        System.Console.Error.WriteLine("Grib1Input: possible file corruption");
                        checkGDSkeys(gds, gdsCounter);
                        return;
                    }
                }         // end if seekHeader
                          //System.out.println( "raf.Position=" + raf.Position);
                          //System.out.println( "raf.Length=" + raf.Length );
            }             // end while raf.Position < raf.Length
            //System.out.println("GribInput: processed in " +
            //   (System.currentTimeMillis()- start) + " milliseconds");
            checkGDSkeys(gds, gdsCounter);
            return;
        }         // end scan
Esempio n. 7
0
        /// <summary> Constructs a <tt>Grib1Grid</tt> object from a pds.
        ///
        /// </summary>
        /// <param name="pds">Grib1ProductDefinitionSection to formulate grib
        ///
        /// </param>
        public Grib1Grid(Grib1ProductDefinitionSection pds) : base()
        {
            int generatingProcess = pds.Process_Id;
            int gridNumber        = pds.Grid_Id;

            // checksum = 1000 + grid number
            checksum = "1000" + System.Convert.ToString(gridNumber);

            switch (gridNumber)
            {
            case 21:
            case 22:
            case 23:
            case 24:  {
                type = 0;                                 // Latitude/Longitude
                name = getName(type);

                // (Nx - number of points along x-axis)
                nx = 37;

                // (Ny - number of points along y-axis)
                ny = 37;

                // (resolution and component flags).  See Table 7
                resolution = 0x88;

                // (Dx - Longitudinal Direction Increment )
                dx = 5.0;

                // (Dy - Latitudinal Direction Increment )
                dy = 2.5;

                // (Scanning mode)  See Table 8
                scan = 64;

                if (gridNumber == 21)
                {
                    // (La1 - latitude of first grid point)
                    lat1 = 0.0;

                    // (Lo1 - longitude of first grid point)
                    lon1 = 0.0;

                    // (La2 - latitude of last grid point)
                    lat2 = 90.0;

                    // (Lo2 - longitude of last grid point)
                    lon2 = 180.0;
                }
                else if (gridNumber == 22)
                {
                    // (La1 - latitude of first grid point)
                    lat1 = 0.0;

                    // (Lo1 - longitude of first grid point)
                    lon1 = -180.0;

                    // (La2 - latitude of last grid point)
                    lat2 = 90.0;

                    // (Lo2 - longitude of last grid point)
                    lon2 = 0.0;
                }
                else if (gridNumber == 23)
                {
                    // (La1 - latitude of first grid point)
                    lat1 = -90.0;

                    // (Lo1 - longitude of first grid point)
                    lon1 = 0.0;

                    // (La2 - latitude of last grid point)
                    lat2 = 0.0;

                    // (Lo2 - longitude of last grid point)
                    lon2 = 180.0;
                }
                else if (gridNumber == 24)
                {
                    // (La1 - latitude of first grid point)
                    lat1 = -90.0;

                    // (Lo1 - longitude of first grid point)
                    lon1 = -180.0;

                    // (La2 - latitude of last grid point)
                    lat2 = 0.0;

                    // (Lo2 - longitude of last grid point)
                    lon2 = 0.0;
                }
            }
            break;


            case 25:
            case 26:  {
                type = 0;                                 // Latitude/Longitude
                name = getName(type);

                // (Nx - number of points along x-axis)
                nx = 72;

                // (Ny - number of points along y-axis)
                ny = 19;

                // (resolution and component flags).  See Table 7
                resolution = 0x88;

                // (Dx - Longitudinal Direction Increment )
                dx = 5.0;

                // (Dy - Latitudinal Direction Increment )
                dy = 5.0;

                // (Scanning mode)  See Table 8
                scan = 64;

                if (gridNumber == 25)
                {
                    // (La1 - latitude of first grid point)
                    lat1 = 0.0;

                    // (Lo1 - longitude of first grid point)
                    lon1 = 0.0;

                    // (La2 - latitude of last grid point)
                    lat2 = 90.0;

                    // (Lo2 - longitude of last grid point)
                    lon2 = 355.0;
                }
                else if (gridNumber == 26)
                {
                    // (La1 - latitude of first grid point)
                    lat1 = -90.0;

                    // (Lo1 - longitude of first grid point)
                    lon1 = 0.0;

                    // (La2 - latitude of last grid point)
                    lat2 = 0.0;

                    // (Lo2 - longitude of last grid point)
                    lon2 = 355.0;
                }
            }
            break;


            case 61:
            case 62:
            case 63:
            case 64:  {
                type = 0;                                 // Latitude/Longitude
                name = getName(type);

                // (Nx - number of points along x-axis)
                nx = 91;

                // (Ny - number of points along y-axis)
                ny = 46;

                // (resolution and component flags).  See Table 7
                resolution = 0x88;

                // (Dx - Longitudinal Direction Increment )
                dx = 2.0;

                // (Dy - Latitudinal Direction Increment )
                dy = 2.0;

                // (Scanning mode)  See Table 8
                scan = 64;

                if (gridNumber == 61)
                {
                    // (La1 - latitude of first grid point)
                    lat1 = 0.0;

                    // (Lo1 - longitude of first grid point)
                    lon1 = 0.0;

                    // (La2 - latitude of last grid point)
                    lat2 = 90.0;

                    // (Lo2 - longitude of last grid point)
                    lon2 = 180.0;
                }
                else if (gridNumber == 62)
                {
                    // (La1 - latitude of first grid point)
                    lat1 = 0.0;

                    // (Lo1 - longitude of first grid point)
                    lon1 = -180.0;

                    // (La2 - latitude of last grid point)
                    lat2 = 90.0;

                    // (Lo2 - longitude of last grid point)
                    lon2 = 0.0;
                }
                else if (gridNumber == 63)
                {
                    // (La1 - latitude of first grid point)
                    lat1 = -90.0;

                    // (Lo1 - longitude of first grid point)
                    lon1 = 0.0;

                    // (La2 - latitude of last grid point)
                    lat2 = 0.0;

                    // (Lo2 - longitude of last grid point)
                    lon2 = 180.0;
                }
                else if (gridNumber == 64)
                {
                    // (La1 - latitude of first grid point)
                    lat1 = -90.0;

                    // (Lo1 - longitude of first grid point)
                    lon1 = -180.0;

                    // (La2 - latitude of last grid point)
                    lat2 = 0.0;

                    // (Lo2 - longitude of last grid point)
                    lon2 = 0.0;
                }
                break;
            }

            default:
                System.Console.Out.WriteLine("Grid " + gridNumber + " not configured yet");
                break;
            }
        } // end Grib1Grid
Esempio n. 8
0
        /// <summary> scans a Grib file to gather information that could be used to
        /// create an index or dump the metadata contents.
        /// 
        /// </summary>
        /// <param name="getProducts">products have enough information for data extractions
        /// </param>
        /// <param name="oneRecord">returns after processing one record in the Grib file
        /// </param>
        /// <throws>  NotSupportedException </throws>
        public void scan(bool getProducts, bool oneRecord)
        {
            long start = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
            // stores the number of times a particular GDS is used
            //UPGRADE_TODO: Class 'java.util.HashMap' was converted to 'System.Collections.Hashtable' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashMap'"
            IDictionary<string,int> gdsCounter = new Dictionary<string,int>();
            Grib1ProductDefinitionSection pds = null;
            Grib1GridDefinitionSection gds = null;
            long startOffset = -1;

            //System.out.println("file position =" + raf.Position);
            while (raf.Position < raf.Length)
            {
                if (seekHeader(raf, raf.Length, out startOffset))
                {
                    // Read Section 0 Indicator Section
                    Grib1IndicatorSection is_Renamed = new Grib1IndicatorSection(raf);
                    //System.out.println( "Grib record length=" + is.getGribLength());
                    // EOR (EndOfRecord) calculated so skipping data sections is faster
                    long EOR = raf.Position + is_Renamed.GribLength - is_Renamed.Length;

                    // Read Section 1 Product Definition Section PDS
                    pds = new Grib1ProductDefinitionSection(raf);
                    if (pds.LengthErr)
                        continue;

                    if (pds.gdsExists())
                    {
                        // Read Section 2 Grid Definition Section GDS
                        gds = new Grib1GridDefinitionSection(raf);
                    }
                    else
                    {
                        // GDS doesn't exist so make one
                        //System.out.println("GribRecord: No GDS included.");
                        //System.out.println("Process ID:" + pds.getProcess_Id() );
                        //System.out.println("Grid ID:" + pds.getGrid_Id() );
                        gds = (Grib1GridDefinitionSection) new Grib1Grid(pds);
                    }
                    // obtain BMS or BDS offset in the file for this product
                    long dataOffset = 0;
                    if (pds.Center == 98)
                    {
                        // check for ecmwf offset by 1 bug
                        int length = (int)GribNumbers.uint3(raf); // should be length of BMS
                        if ((length + raf.Position) < EOR)
                        {
                            dataOffset = raf.Position - 3; // ok
                        }
                        else
                        {
                            dataOffset = raf.Position - 2;
                        }
                    }
                    else
                    {
                        dataOffset = raf.Position;
                    }
                    // position filePointer to EndOfRecord
                    raf.Seek(EOR, System.IO.SeekOrigin.Begin);
                    //System.out.println("file offset = " + raf.Position);

                    // assume scan ok
                    if (getProducts)
                    {
                        Grib1Product gp = new Grib1Product(header, pds, getGDSkey(gds, gdsCounter), dataOffset, raf.Position);
                        products.Add(gp);
                    }
                    else
                    {
                        Grib1Record gr = new Grib1Record(header, is_Renamed, pds, gds, dataOffset, raf.Position, startOffset);
                        records.Add(gr);
                    }
                    if (oneRecord)
                        return ;

                    // early return because ending "7777" missing
                    if (raf.Position > raf.Length)
                    {
                        raf.Seek(0, System.IO.SeekOrigin.Begin);
                        //System.Console.Error.WriteLine("Grib1Input: possible file corruption");
                        checkGDSkeys(gds, gdsCounter);
                        return ;
                    }
                } // end if seekHeader
                //System.out.println( "raf.Position=" + raf.Position);
                //System.out.println( "raf.Length=" + raf.Length );
            } // end while raf.Position < raf.Length
            //System.out.println("GribInput: processed in " +
            //   (System.currentTimeMillis()- start) + " milliseconds");
            checkGDSkeys(gds, gdsCounter);
            return ;
        }