Ejemplo n.º 1
0
        internal Grib1WaveSpectra2DDirFreq(System.IO.Stream raf)
        {
            SupportClass.Skip(raf, 4);

            byte[] ver = GribNumbers.ReadBytes(raf, 4);
            System.Text.Encoding enc = System.Text.Encoding.ASCII;
            version = enc.GetString(ver);

            SupportClass.Skip(raf, 2);

            directionNumber     = raf.ReadByte();
            frequencyNumber     = raf.ReadByte();
            numberOfDirections  = raf.ReadByte();
            numberOfFrequencies = raf.ReadByte();
            dirScaleFactor      = GribNumbers.int4(raf);
            freqScaleFactor     = GribNumbers.int4(raf);

            SupportClass.Skip(raf, 37);

            directions  = new double[numberOfDirections];
            frequencies = new double[numberOfFrequencies];

            for (int i = 0; i < numberOfDirections; i++)
            {
                int val = GribNumbers.int4(raf);
                directions[i] = (double)val / (double)dirScaleFactor;
            }

            for (int i = 0; i < numberOfFrequencies; i++)
            {
                int val = GribNumbers.int4(raf);
                frequencies[i] = (double)val / (double)freqScaleFactor;
            }
        }
Ejemplo n.º 2
0
        // *** constructors *******************************************************

        /// <summary> Constructs a <tt>Grib2LocalUseSection</tt> object from a raf.</summary>
        /// <param name="raf">
        /// </param>
        /// <throws>  IOException  if raf contains no valid GRIB product </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 Grib2LocalUseSection(System.IO.FileStream raf)
        {
            // octets 1-4 (Length of GDS)
            length = GribNumbers.int4(raf);
            //System.out.println( "LUS length=" + length );

            section = raf.ReadByte();             // This is section 2
            //System.out.println( "LUS Local Use is 2, section=" + section );

            if (section != 2)
            {
                // no local use section
                SupportClass.Skip(raf, -5);
                return;
            }
            else
            {
                //SupportClass.Skip(raf, length - 5);
                bytes = new byte[length - 5];
                int nb = raf.Read(bytes, 0, length - 5);
                if (nb != length - 5)
                {
                    throw new NoValidGribException("Failed to read Local Use Section data");
                }
            }
        }         // end of Grib2LocalUseSection
Ejemplo n.º 3
0
        // *** constructors *******************************************************

        /// <summary> Constructs a <tt>Grib2BitMapSection</tt> object from a byteBuffer.
        ///
        /// </summary>
        /// <param name="raf">RandomAccessFile with Section BMS content
        /// </param>
        /// <param name="gds">Grib2GridDefinitionSection
        /// </param>
        /// <throws>  IOException  if stream contains no valid GRIB file </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 Grib2BitMapSection(System.IO.FileStream raf, Grib2GridDefinitionSection gds)
        {
            int[] bitmask = new int[] { 128, 64, 32, 16, 8, 4, 2, 1 };

            // octets 1-4 (Length of BMS)
            length = GribNumbers.int4(raf);
            //System.out.println( "BMS length=" + length );

            section = raf.ReadByte();
            //System.out.println( "BMS is 6, section=" + section );

            bitMapIndicator = raf.ReadByte();
            //System.out.println( "BMS bitMapIndicator=" + bitMapIndicator );

            // no bitMap
            if (bitMapIndicator != 0)
            {
                return;
            }

            sbyte[] data = new sbyte[this.length - 6];
            SupportClass.ReadInput(raf, data, 0, data.Length);

            // create new bit map, octet 4 contains number of unused bits at the end
            this.bitmap = new bool[gds.NumberPoints];
            //System.out.println( "BMS GDS NumberPoints = " + gds.getNumberPoints() );
            //System.out.println( "BMS bitmap.length = " + this.bitmap.length );

            // fill bit map
            for (int i = 0; i < this.bitmap.Length; i++)
            {
                this.bitmap[i] = (data[i / 8] & bitmask[i % 8]) != 0;
            }
        }
Ejemplo n.º 4
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
Ejemplo n.º 5
0
        // *** constructors *******************************************************

        /// <summary> Constructs a <tt>Grib2IdentificationSection</tt> object from a RandomAccessFile.
        ///
        /// </summary>
        /// <param name="raf">RandomAccessFile with Section 1 content
        ///
        /// </param>
        /// <throws>  IOException  if raf contains no valid GRIB file </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 Grib2IdentificationSection(System.IO.FileStream raf)
        {
            // section 1 octet 1-4 (length of section)
            length = GribNumbers.int4(raf);

            //System.out.println( "IdentificationSection1 length=" + length );

            section = raf.ReadByte();
            //System.out.println( "Section number=" + section );

            // Center  octet 6-7
            center_id = GribNumbers.int2(raf);
            //System.out.println( "center_id=" + center_id );

            // Center  octet 8-9
            subcenter_id = GribNumbers.int2(raf);
            //System.out.println( "subcenter_id=" + subcenter_id );

            // Paramter master table octet 10
            master_table_version = raf.ReadByte();
            //System.out.println( "master tbl=" + master_table_version );

            // Paramter local table octet 11
            local_table_version = raf.ReadByte();
            //System.out.println( "local tbl=" + local_table_version );

            // significanceOfRT octet 12
            significanceOfRT = raf.ReadByte();
            //System.out.println( "significanceOfRT=" + significanceOfRT );

            // octets 13-19 (base time of forecast)
            {
                int year   = GribNumbers.int2(raf);
                int month  = raf.ReadByte();
                int day    = raf.ReadByte();
                int hour   = raf.ReadByte();
                int minute = raf.ReadByte();
                int second = raf.ReadByte();

                refTime       = new DateTime(year, month, day, hour, minute, second, DateTimeKind.Utc);
                baseTime      = refTime;
                referenceTime = refTime.ToString(dateFormat);
            }

            productStatus = raf.ReadByte();
            //System.out.println( "productStatus=" + productStatus );

            productType = raf.ReadByte();
            //System.out.println( "productType=" + productType );
        }         // end if Grib2IdentificationSection
Ejemplo n.º 6
0
        // *** constructors *******************************************************

        /// <summary> Constructs a <tt>Grib1IndicatorSection</tt> object from a byteBuffer.
        ///
        /// </summary>
        /// <param name="raf">RandomAccessFile with IndicatorSection content
        ///
        /// </param>
        /// <throws>  NotSupportedException  if raf contains no valid GRIB file </throws>
        /// <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 Grib1IndicatorSection(System.IO.FileStream raf)
        {
            long mark = raf.Position;

            //if Grib edition 1, get bytes for the gribLength
            int[] data = new int[3];
            for (int i = 0; i < 3; i++)
            {
                data[i] = raf.ReadByte();
            }
            //System.out.println( "data[]=" + data[0] +", "+ data[1]+", "+data[2] ) ;

            // edition of GRIB specification
            edition = raf.ReadByte();
            //System.out.println( "edition=" + edition ) ;
            if (edition == 1)
            {
                // length of GRIB record
                // Reset to beginning, then read 3 bytes
                raf.Position = mark;
                gribLength   = (long)GribNumbers.uint3(raf);
                // Skip next byte, edition already read
                raf.ReadByte();
                //System.out.println( "edition 1 gribLength=" + gribLength ) ;
                length = 8;
            }
            else if (edition == 2)
            {
                // length of GRIB record
                discipline = data[2];
                //System.out.println( "discipline=" + discipline) ;
                gribLength = GribNumbers.int8(raf);
                //System.out.println( "editon 2 gribLength=" + gribLength) ;
                length = 16;
            }
            else
            {
                throw new NotSupportedException("GRIB edition " + edition + " is not yet supported");
            }
        }         // end Grib1IndicatorSection
Ejemplo n.º 7
0
        /// <summary> Constructs a <tt> Grib1BitMapSection</tt> object from a raf input stream.
        ///
        /// </summary>
        /// <param name="raf">input stream with BMS content
        ///
        /// </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'"
        internal Grib1BitMapSection(System.IO.Stream raf)
        {
            int[] bitmask = new int[] { 128, 64, 32, 16, 8, 4, 2, 1 };

            // octet 1-3 (length of section)
            length = (int)GribNumbers.uint3(raf);


            // octet 4 unused bits
            int unused = raf.ReadByte();


            // octets 5-6
            int bm = GribNumbers.int2(raf);

            if (bm != 0)
            {
                System.Console.Out.WriteLine("BMS pre-defined BM provided by center");
                if ((length - 6) == 0)
                {
                    return;
                }
                sbyte[] data = new sbyte[length - 6];
                SupportClass.ReadInput(raf, data, 0, data.Length);
                return;
            }

            sbyte[] data2 = new sbyte[length - 6];
            SupportClass.ReadInput(raf, data2, 0, data2.Length);

            // create new bit map, octet 4 contains number of unused bits at the end
            Bitmap = new bool[(length - 6) * 8 - unused];


            // fill bit map
            for (int i = 0; i < Bitmap.Length; i++)
            {
                Bitmap[i] = (data2[i / 8] & bitmask[i % 8]) != 0;
            }
        } // end Grib1BitMapSection
Ejemplo n.º 8
0
        }         // end Grib1GridDefinitionSection( raf )

        //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  getP_VorL(System.IO.FileStream raf)
        {
            isThin = true;
            int numPts;

            if (ny != 1)
            {
                dx     = (float)GribNumbers.UNDEFINED;
                numPts = ny;
            }
            else
            {
                dx     = (float)GribNumbers.UNDEFINED;
                numPts = nx;
            }
            //System.out.println( "GDS  numPts = " + numPts);
            int[] numPlPts = new int[numPts];
            for (int i = 0; i < numPts; i++)
            {
                numPlPts[i] = GribNumbers.int2(raf);
                //System.out.println( "GDS  numPlPts[ i ] = " +  numPlPts[ i ] );
            }
        }
Ejemplo n.º 9
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
Ejemplo n.º 10
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
Ejemplo n.º 11
0
        // *** constructors *******************************************************

        /// <summary> Constructs a <tt>Grib1ProductDefinitionSection</tt> object from a raf.
        ///
        /// </summary>
        /// <param name="raf">with PDS content
        ///
        /// </param>
        /// <throws>  NotSupportedException  if raf contains no valid GRIB file </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 Grib1ProductDefinitionSection(System.IO.FileStream raf)
        {
            // octets 1-3 PDS length
            length = (int)GribNumbers.uint3(raf);
            //System.out.println( "PDS length = " + length );

            // Paramter table octet 4
            table_version = raf.ReadByte();

            // Center  octet 5
            center_id = raf.ReadByte();

            // octet 6 Generating Process - See Table A
            process_id = raf.ReadByte();

            // octet 7 (id of grid type) - not supported yet
            grid_id = raf.ReadByte();

            //octet 8 (flag for presence of GDS and BMS)
            int exists = raf.ReadByte();

            //BKSystem.IO.BitStream s = new BKSystem.IO.BitStream(8);
//            s.WriteByte((byte)raf.ReadByte());
//            s.Position = 0;
//            sbyte exists;
//            s.Read(out exists);
//            bms_exists = (exists & 64) == 64;

            gds_exists = (exists & 128) == 128;
            bms_exists = (exists & 64) == 64;

            // octet 9 (parameter and unit)
            parameterNumber = raf.ReadByte();

            // octets 10-12 (level)
            int levelType   = raf.ReadByte();
            int levelValue1 = raf.ReadByte();
            int levelValue2 = raf.ReadByte();

            level = new GribPDSLevel(levelType, levelValue1, levelValue2);

            // octets 13-17 (base time for reference time)
            int year   = raf.ReadByte();
            int month  = raf.ReadByte();
            int day    = raf.ReadByte();
            int hour   = raf.ReadByte();
            int minute = raf.ReadByte();

            // get info for forecast time
            // octet 18 Forecast time unit
            timeUnit = raf.ReadByte();

            switch (timeUnit)
            {
            case 0:                      // minute
                tUnit = "minute";
                break;

            case 1:                      // hours
                tUnit = "hour";
                break;

            case 2:                      // day
                tUnit = "day";
                break;

            case 3:                      // month
                tUnit = "month";
                break;

            case 4:                      //1 year
                tUnit = "1year";
                break;

            case 5:                      // decade
                tUnit = "decade";
                break;

            case 6:                      // normal
                tUnit = "day";
                break;

            case 7:                      // century
                tUnit = "century";
                break;

            case 10:                      //3 hours
                tUnit = "3hours";
                break;

            case 11:                      // 6 hours
                tUnit = "6hours";
                break;

            case 12:                      // 12 hours
                tUnit = "12hours";
                break;

            case 254:                      // second
                tUnit = "second";
                break;


            default:
                System.Console.Error.WriteLine("PDS: Time Unit " + timeUnit + " is not yet supported");
                break;
            }

            // octet 19 & 20 used to create Forecast time
            p1 = raf.ReadByte();
            p2 = raf.ReadByte();

            // octet 21 (time range indicator)
            timeRangeValue = raf.ReadByte();
            // forecast time is always at the end of the range
            //System.out.println( "PDS timeRangeValue =" + timeRangeValue );
            switch (timeRangeValue)
            {
            case 0:
                timeRange    = "product valid at RT + P1";
                forecastTime = p1;
                break;

            case 1:
                timeRange    = "product valid for RT, P1=0";
                forecastTime = 0;
                break;

            case 2:
                timeRange    = "product valid from (RT + P1) to (RT + P2)";
                forecastTime = p2;
                break;

            case 3:
                timeRange    = "product is an average between (RT + P1) to (RT + P2)";
                forecastTime = p2;
                break;

            case 4:
                timeRange    = "product is an accumulation between (RT + P1) to (RT + P2)";
                forecastTime = p2;
                break;

            case 5:
                timeRange    = "product is the difference (RT + P2) - (RT + P1)";
                forecastTime = p2;
                break;

            case 6:
                timeRange    = "product is an average from (RT - P1) to (RT - P2)";
                forecastTime = -p2;
                break;

            case 7:
                timeRange    = "product is an average from (RT - P1) to (RT + P2)";
                forecastTime = p2;
                break;

            case 10:
                timeRange = "product valid at RT + P1";
                // p1 really consists of 2 bytes p1 and p2
                forecastTime = p1 = GribNumbers.int2(p1, p2);
                p2           = 0;
                break;

            case 51:
                timeRange    = "mean value from RT to (RT + P2)";
                forecastTime = p2;
                break;

            default:
                System.Console.Error.WriteLine("PDS: Time Range Indicator " + timeRangeValue + " is not yet supported");
                break;
            }

            // octet 22 & 23
            int avgInclude = GribNumbers.int2(raf);

            // octet 24
            int avgMissing = raf.ReadByte();

            // octet 25
            int century = raf.ReadByte() - 1;

            // octet 26, sub center
            subcenter_id = raf.ReadByte();

            // octets 27-28 (decimal scale factor)
            decscale = GribNumbers.int2(raf);

            refTime       = new DateTime(century * 100 + year, month, day, hour, minute, 0, DateTimeKind.Utc);
            baseTime      = refTime;
            referenceTime = refTime.ToString(dateFormat);

            //System.out.println( "PDS referenceTime raw = " +
            //(century * 100 + year) +"-" +
            //month + "-" + day + "T" + hour +":" + minute +":00Z" );
            //System.out.println( "PDS referenceTime     = " + referenceTime );

            // TODO

            /*
             *          parameter_table = GribPDSParamTable.getParameterTable(center_id, subcenter_id, table_version);
             *          parameter = parameter_table.getParameter(parameterNumber);
             */
            parameter = new Parameter();


            if (center_id == 7 && subcenter_id == 2)
            {
                // ensemble product
                epds = new Grib1Ensemble(raf, parameterNumber);
            }
            // Special handling of 2D Wave Spectra (single)
            else if (table_version == 140 && parameterNumber == 251)
            {
                SupportClass.Skip(raf, 12);
                int extDef = raf.ReadByte(); // Extension definition

                // Read ECMWF extension for 2D wave spectra single
                if (extDef == 13)
                {
                    waveSpectra2DDirFreq = new Grib1WaveSpectra2DDirFreq(raf);
                }
            }
            else if (length != 28)
            {
                // check if all bytes read in section
                //lengthErr = true;
                int extra;
                for (int i = 29; i <= length; i++)
                {
                    extra = raf.ReadByte();
                }
            }
        }         // end Grib1ProductDefinitionSection
Ejemplo n.º 12
0
        // *** constructors *******************************************************

        /// <summary> Constructs a Grib2ProductDefinitionSection  object from a raf.
        ///
        /// </summary>
        /// <param name="raf">RandomAccessFile with PDS content
        ///
        /// </param>
        /// <throws>  IOException  if raf contains no valid GRIB file </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 Grib2ProductDefinitionSection(System.IO.FileStream raf)
        {
            // octets 1-4 (Length of PDS)
            length = GribNumbers.int4(raf);
            //System.out.println( "PDS length=" + length );

            // octet 5
            section = raf.ReadByte();
            //System.out.println( "PDS is 4, section=" + section );

            // octet 6-7
            coordinates = GribNumbers.int2(raf);
            //System.out.println( "PDS coordinates=" + coordinates );

            // octet 8-9
            productDefinition = GribNumbers.int2(raf);
            //System.out.println( "PDS productDefinition=" + productDefinition );

            switch (productDefinition)
            {
            // Analysis or forecast at a horizontal level or in a horizontal
            // layer at a point in time
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
            case 8:  {
                // octet 10
                parameterCategory = raf.ReadByte();
                //System.out.println( "PDS parameterCategory=" +
                //parameterCategory );

                // octet 11
                parameterNumber = raf.ReadByte();
                //System.out.println( "PDS parameterNumber=" + parameterNumber );

                // octet 12
                typeGenProcess = raf.ReadByte();
                //System.out.println( "PDS typeGenProcess=" + typeGenProcess );

                // octet 13
                backGenProcess = raf.ReadByte();
                //System.out.println( "PDS backGenProcess=" + backGenProcess );

                // octet 14
                analysisGenProcess = raf.ReadByte();
                //System.out.println( "PDS analysisGenProcess=" +
                //analysisGenProcess );

                // octet 15-16
                hoursAfter = GribNumbers.int2(raf);
                //System.out.println( "PDS hoursAfter=" + hoursAfter );

                // octet 17
                minutesAfter = raf.ReadByte();
                //System.out.println( "PDS minutesAfter=" + minutesAfter );

                // octet 18
                timeRangeUnit = raf.ReadByte();
                //System.out.println( "PDS timeRangeUnit=" + timeRangeUnit );

                // octet 19-22
                forecastTime = GribNumbers.int4(raf);
                //System.out.println( "PDS forecastTime=" + forecastTime );

                // octet 23
                typeFirstFixedSurface = raf.ReadByte();
                //System.out.println( "PDS typeFirstFixedSurface=" +
                //     typeFirstFixedSurface );

                // octet 24
                int scaleFirstFixedSurface = raf.ReadByte();
                //System.out.println( "PDS scaleFirstFixedSurface=" +
                //     scaleFirstFixedSurface );

                // octet 25-28
                int valueFirstFixedSurface = GribNumbers.int4(raf);
                //System.out.println( "PDS valueFirstFixedSurface=" +
                //     valueFirstFixedSurface );

                //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'"
                FirstFixedSurfaceValue = (float)((scaleFirstFixedSurface == 0 || valueFirstFixedSurface == 0)?valueFirstFixedSurface:System.Math.Pow(valueFirstFixedSurface, -scaleFirstFixedSurface));

                // octet 29
                typeSecondFixedSurface = raf.ReadByte();
                //System.out.println( "PDS typeSecondFixedSurface=" +
                //typeSecondFixedSurface );

                // octet 30
                int scaleSecondFixedSurface = raf.ReadByte();
                //System.out.println( "PDS scaleSecondFixedSurface=" +
                //scaleSecondFixedSurface );

                // octet 31-34
                int valueSecondFixedSurface = GribNumbers.int4(raf);
                //System.out.println( "PDS valueSecondFixedSurface=" +
                //valueSecondFixedSurface );

                //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'"
                SecondFixedSurfaceValue = (float)((scaleSecondFixedSurface == 0 || valueSecondFixedSurface == 0)?valueSecondFixedSurface:System.Math.Pow(valueSecondFixedSurface, -scaleSecondFixedSurface));


                // Individual ensemble forecast, control and perturbed, at a
                // horizontal level or in a horizontal layer at a point in time
                if (productDefinition == 1)
                {
                    System.Console.Out.WriteLine("PDS productDefinition == 1 not done");

                    //Derived forecast based on all ensemble members at a horizontal
                    // level or in a horizontal layer at a point in time
                }
                else if (productDefinition == 2)
                {
                    System.Console.Out.WriteLine("PDS productDefinition == 2 not done");

                    // Derived forecasts based on a cluster of ensemble members over
                    // a rectangular area at a horizontal level or in a horizontal layer
                    // at a point in time
                }
                else if (productDefinition == 3)
                {
                    System.Console.Out.WriteLine("PDS productDefinition == 3 not done");

                    // Derived forecasts based on a cluster of ensemble members
                    // over a circular area at a horizontal level or in a horizontal
                    // layer at a point in time
                }
                else if (productDefinition == 4)
                {
                    System.Console.Out.WriteLine("PDS productDefinition == 4 not done");

                    // Probability forecasts at a horizontal level or in a horizontal
                    //  layer at a point in time
                }
                else if (productDefinition == 5)
                {
                    System.Console.Out.WriteLine("PDS productDefinition == 5 not done");

                    // Percentile forecasts at a horizontal level or in a horizontal layer
                    // at a point in time
                }
                else if (productDefinition == 6)
                {
                    System.Console.Out.WriteLine("PDS productDefinition == 6 not done");

                    // Analysis or forecast error at a horizontal level or in a horizontal
                    // layer at a point in time
                }
                else if (productDefinition == 7)
                {
                    System.Console.Out.WriteLine("PDS productDefinition == 7 not done");

                    // Average, accumulation, and/or extreme values at a horizontal
                    // level or in a horizontal layer in a continuous or non-continuous
                    // time interval
                }
                else if (productDefinition == 8)
                {
                    //System.out.println( "PDS productDefinition == 8 " );
                    //  35-41 bytes
                    int year   = GribNumbers.int2(raf);
                    int month  = (raf.ReadByte()) - 1;
                    int day    = raf.ReadByte();
                    int hour   = raf.ReadByte();
                    int minute = raf.ReadByte();
                    int second = raf.ReadByte();
                    //System.out.println( "PDS date:" + year +":" + month +
                    //":" + day + ":" + hour +":" + minute +":" + second );

                    // 42 - 46
                    int timeRanges = raf.ReadByte();
                    //System.out.println( "PDS timeRanges=" + timeRanges ) ;
                    int missingDataValues = GribNumbers.int4(raf);
                    //System.out.println( "PDS missingDataValues=" + missingDataValues ) ;
                    // 47 - 48
                    int outmostTimeRange = raf.ReadByte();
                    //System.out.println( "PDS outmostTimeRange=" + outmostTimeRange )
                    ;
                    int missing = raf.ReadByte();
                    //System.out.println( "PDS missing=" + missing ) ;
                    // 49 - 53
                    int statisticalProcess = raf.ReadByte();
                    //System.out.println( "PDS statisticalProcess=" + statisticalProcess ) ;
                    int timeIncrement = GribNumbers.int4(raf);
                    //System.out.println( "PDS timeIncrement=" + timeIncrement ) ;

                    // 54 - 58
                    int indicatorTR = raf.ReadByte();
                    //System.out.println( "PDS indicatorTR=" + indicatorTR ) ;

                    int lengthTR = GribNumbers.int4(raf);

                    if (timeRanges == 1)
                    {
                        this.forecastTime += calculateIncrement(statisticalProcess, timeIncrement);
                    }
                    //System.out.println( "PDS lengthTR=" + lengthTR ) ;

                    //int indicatorSF = raf.read();
                    //System.out.println( "PDS indicatorSF=" + indicatorSF ) ;

                    //int incrementSF = GribNumbers.int4( raf );
                    //System.out.println( "PDS incrementSF=" + incrementSF ) ;
                }
                break;
            }                             // cases 0-8

            // Radar product

            case 20:  {
                parameterCategory = raf.ReadByte();
                //System.out.println( "PDS parameterCategory=" +
                //parameterCategory );

                parameterNumber = raf.ReadByte();
                //System.out.println( "PDS parameterNumber=" + parameterNumber );

                typeGenProcess = raf.ReadByte();
                //System.out.println( "PDS typeGenProcess=" + typeGenProcess );

                backGenProcess = raf.ReadByte();
                //System.out.println( "PDS backGenProcess=" + backGenProcess );

                hoursAfter = GribNumbers.int2(raf);
                //System.out.println( "PDS hoursAfter=" + hoursAfter );

                minutesAfter = raf.ReadByte();
                //System.out.println( "PDS minutesAfter=" + minutesAfter );

                timeRangeUnit = raf.ReadByte();
                //System.out.println( "PDS timeRangeUnit=" + timeRangeUnit );

                forecastTime = GribNumbers.int4(raf);
                //System.out.println( "PDS forecastTime=" + forecastTime );

                break;
            }                             // case 20

            // Satellite Product

            case 30:  {
                parameterCategory = raf.ReadByte();
                //System.out.println( "PDS parameterCategory=" + parameterCategory );

                parameterNumber = raf.ReadByte();
                //System.out.println( "PDS parameterNumber=" + parameterNumber );

                typeGenProcess = raf.ReadByte();
                //System.out.println( "PDS typeGenProcess=" + typeGenProcess );

                backGenProcess = raf.ReadByte();
                //System.out.println( "PDS backGenProcess=" + backGenProcess );

                nb = raf.ReadByte();
                //System.out.println( "PDS nb =" + nb );
                for (int j = 0; j < nb; j++)
                {
                    SupportClass.Skip(raf, 10);
                }
                break;
            }                             // case 30

            // CCITTIA5 character string

            case 254:  {
                parameterCategory = raf.ReadByte();
                //System.out.println( "PDS parameterCategory=" +
                //parameterCategory );

                parameterNumber = raf.ReadByte();
                //System.out.println( "PDS parameterNumber=" + parameterNumber );

                //numberOfChars = GribNumbers.int4( raf );
                //System.out.println( "PDS numberOfChars=" +
                //numberOfChars );
                break;
            }                             // case 254


            default:
                break;
            }             // end switch
        }
Ejemplo n.º 13
0
        /// <summary> Constructs a Grib1BinaryDataSection object from a raf.
        /// A bit map is defined.
        ///
        /// </summary>
        /// <param name="raf">raf with BDS content
        /// </param>
        /// <param name="decimalscale">the exponent of the decimal scale
        /// </param>
        /// <param name="bms">bit map section of GRIB record
        ///
        /// </param>
        /// <throws>  NotSupportedException  if stream contains no valid GRIB file </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 Grib1BinaryDataSection(System.IO.FileStream raf, int decimalscale, Grib1BitMapSection bms)
        {
            // octets 1-3 (section length)
            length = (int)GribNumbers.uint3(raf);
            //System.out.println( "BDS length = " + length );

            // octet 4, 1st half (packing flag)
            int unusedbits = raf.ReadByte();

            // TODO Check this!!!
            if ((unusedbits & 192) != 0)
            {
                throw new NotSupportedException("BDS: (octet 4, 1st half) not grid point data and simple packing ");
            }

            // octet 4, 2nd half (number of unused bits at end of this section)
            unusedbits = unusedbits & 15;
            //System.out.println( "BDS unusedbits = " + unusedbits );

            // octets 5-6 (binary scale factor)
            int binscale = GribNumbers.int2(raf);

            // octets 7-10 (reference point = minimum value)
            float refvalue = GribNumbers.float4(raf);

            // octet 11 (number of bits per value)
            int numbits = raf.ReadByte();

            //System.out.println( "BDS numbits = " + numbits );
            if (numbits == 0)
            {
                isConstant = true;
            }
            //System.out.println( "BDS isConstant = " + isConstant );

            // *** read values *******************************************************

            //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 ref_Renamed = (float)(System.Math.Pow(10.0, -decimalscale) * refvalue);
            //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 scale = (float)(System.Math.Pow(10.0, -decimalscale) * System.Math.Pow(2.0, binscale));

            if (bms != null)
            {
                bool[] bitmap = bms.Bitmap;

                values = new float[bitmap.Length];
                for (int i = 0; i < bitmap.Length; i++)
                {
                    if (bitmap[i])
                    {
                        if (!isConstant)
                        {
                            values[i] = ref_Renamed + scale * bits2UInt(numbits, raf);
                        }
                        else
                        {
                            // rdg - added this to handle a constant valued parameter
                            values[i] = ref_Renamed;
                        }
                    }
                    else
                    {
                        values[i] = Grib1BinaryDataSection.UNDEFINED;
                    }
                }
            }
            else
            {
                // bms is null
                if (!isConstant)
                {
                    //System.out.println( "BDS values.size = " +
                    //(((length - 11) * 8 - unusedbits) /  numbits));
                    values = new float[((length - 11) * 8 - unusedbits) / numbits];

                    for (int i = 0; i < values.Length; i++)
                    {
                        values[i] = ref_Renamed + scale * bits2UInt(numbits, raf);
                    }
                }
                else
                {
                    // constant valued - same min and max
                    int x = 0, y = 0;
                    raf.Seek(raf.Position - 53, System.IO.SeekOrigin.Begin);                     // return to start of GDS
                    length = (int)GribNumbers.uint3(raf);
                    if (length == 42)
                    {
                        // Lambert/Mercator offset
                        SupportClass.Skip(raf, 3);
                        x = GribNumbers.int2(raf);
                        y = GribNumbers.int2(raf);
                    }
                    else
                    {
                        SupportClass.Skip(raf, 7);
                        length = (int)GribNumbers.uint3(raf);
                        if (length == 32)
                        {
                            // Polar sterographic
                            SupportClass.Skip(raf, 3);
                            x = GribNumbers.int2(raf);
                            y = GribNumbers.int2(raf);
                        }
                        else
                        {
                            x = y = 1;
                            System.Console.Out.WriteLine("BDS constant value, can't determine array size");
                        }
                    }
                    values = new float[x * y];
                    for (int i = 0; i < values.Length; i++)
                    {
                        values[i] = ref_Renamed;
                    }
                }
            }
        }         // end Grib1BinaryDataSection
Ejemplo n.º 14
0
        /// <summary> Constructs a <tt>Grib1GridDefinitionSection</tt> object from a raf.
        ///
        /// </summary>
        /// <param name="raf">RandomAccessFile with GDS content
        ///
        /// </param>
        /// <throws>  NoValidGribException  if raf contains no valid GRIB info </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 Grib1GridDefinitionSection(System.IO.FileStream raf)
        {
            int reserved;             // used to read empty space

            // octets 1-3 (Length of GDS)
            length = (int)GribNumbers.uint3(raf);
            if (length == 0)
            {
                // there's a extra byte between PDS and GDS
                SupportClass.Skip(raf, -2);
                length = (int)GribNumbers.uint3(raf);
            }
            //System.out.println( "GDS length = " + length );

            // TODO Fix Checksum stuff
            // get byte array for this gds, then reset raf to same position
            // calculate checksum for this gds via the byte array

            /*
             * long mark = raf.Position;
             * sbyte[] dst = new sbyte[length - 3];
             * SupportClass.ReadInput(raf, dst, 0, dst.Length);
             * raf.Seek(mark, System.IO.SeekOrigin.Begin);
             * //UPGRADE_ISSUE: Class 'java.util.zip.CRC32' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilzipCRC32'"
             * //UPGRADE_ISSUE: Constructor 'java.util.zip.CRC32.CRC32' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilzipCRC32'"
             * CRC32 cs = new CRC32();
             * //UPGRADE_ISSUE: Method 'java.util.zip.CRC32.update' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilzipCRC32'"
             * cs.update(dst);
             * //UPGRADE_ISSUE: Method 'java.util.zip.CRC32.getValue' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilzipCRC32'"
             * checksum = System.Convert.ToString(cs.getValue());
             * //System.out.println( "GDS checksum =" + checksum );
             */

            // octets 4 NV
            int NV = raf.ReadByte();

            //System.out.println( "GDS NV = " + NV );

            // octet 5 PL the location (octet number) of the list of numbers of points in each row
            P_VorL = raf.ReadByte();
            //System.out.println( "GDS PL = " + P_VorL );

            // octet 6 (grid type)
            type = raf.ReadByte();
            //System.out.println( "GDS grid type = " + type );
            name = getName(type);

            if (type != 50)
            {
                // values same up to resolution

                // octets 7-8 (Nx - number of points along x-axis)
                nx = GribNumbers.int2(raf);
                nx = (nx == -1)?1:nx;

                // octets 9-10 (Ny - number of points along y-axis)
                ny = GribNumbers.int2(raf);
                ny = (ny == -1)?1:ny;

                // octets 11-13 (La1 - latitude of first grid point)
                lat1 = GribNumbers.int3(raf) / 1000.0;

                // octets 14-16 (Lo1 - longitude of first grid point)
                lon1 = GribNumbers.int3(raf) / 1000.0;

                // octet 17 (resolution and component flags).  See Table 7
                resolution = raf.ReadByte();
            }

            switch (type)
            {
            //  Latitude/Longitude  grids ,  Arakawa semi-staggered e-grid rotated
            //  Arakawa filled e-grid rotated
            case 0:
            case 4:
            case 40:
            case 201:
            case 202:

                // octets 18-20 (La2 - latitude of last grid point)
                lat2 = GribNumbers.int3(raf) / 1000.0;

                // octets 21-23 (Lo2 - longitude of last grid point)
                lon2 = GribNumbers.int3(raf) / 1000.0;

                // octets 24-25 (Dx - Longitudinal Direction Increment )
                dx = GribNumbers.int2(raf) / 1000.0;

                // octets 26-27 (Dy - Latitudinal Direction Increment )
                //               Np - parallels between a pole and the equator
                if (type == 4)
                {
                    np = GribNumbers.int2(raf);
                }
                else
                {
                    dy = GribNumbers.int2(raf) / 1000.0;
                }

                // octet 28 (Scanning mode)  See Table 8
                scan = raf.ReadByte();

                // octet 29-32 reserved
                reserved = GribNumbers.int4(raf);

                if (length > 32)
                {
                    // getP_VorL(raf);
                    // Vertical coordinates (NV) and thinned grids (PL) not supported - skip this
                    SupportClass.Skip(raf, length - 32);
                }

                break;                         // end Latitude/Longitude grids


            case 1:                      //  Mercator grids

                // octets 18-20 (La2 - latitude of last grid point)
                lat2 = GribNumbers.int3(raf) / 1000.0;

                // octets 21-23 (Lo2 - longitude of last grid point)
                lon2 = GribNumbers.int3(raf) / 1000.0;

                // octets 24-26 (Latin - latitude where cylinder intersects the earth
                latin1 = GribNumbers.int3(raf) / 1000.0;

                // octet 27 reserved
                reserved = raf.ReadByte();

                // octet 28 (Scanning mode)  See Table 8
                scan = raf.ReadByte();

                // octets 29-31 (Dx - Longitudinal Direction Increment )
                dx = GribNumbers.int3(raf);

                // octets 32-34 (Dx - Longitudinal Direction Increment )
                dy = GribNumbers.int3(raf);

                // octet 35-42 reserved
                reserved = GribNumbers.int4(raf);
                reserved = GribNumbers.int4(raf);

                if (length > 42)
                {
                    // getP_VorL(raf);
                    // Vertical coordinates (NV) and thinned grids (PL) not supported - skip this
                    SupportClass.Skip(raf, length - 42);
                }

                break;                         // end Mercator grids


            case 3:                      // Lambert Conformal

                // octets 18-20 (Lov - Orientation of the grid - east lon parallel to y axis)
                lov = GribNumbers.int3(raf) / 1000.0;

                // octets 21-23 (Dx - the X-direction grid length) See Note 2 of Table D
                dx = GribNumbers.int3(raf);

                // octets 24-26 (Dy - the Y-direction grid length) See Note 2 of Table D
                dy = GribNumbers.int3(raf);

                // octets 27 (Projection Center flag) See Note 5 of Table D
                proj_center = raf.ReadByte();

                // octet 28 (Scanning mode)  See Table 8
                scan = raf.ReadByte();

                // octets 29-31 (Latin1 - first lat where secant cone cuts spherical earth
                latin1 = GribNumbers.int3(raf) / 1000.0;

                // octets 32-34 (Latin2 - second lat where secant cone cuts spherical earth)
                latin2 = GribNumbers.int3(raf) / 1000.0;

                // octets 35-37 (lat of southern pole)
                latsp = GribNumbers.int3(raf) / 1000.0;

                // octets 38-40 (lon of southern pole)
                lonsp = GribNumbers.int3(raf) / 1000.0;

                // octets 41-42
                reserved = GribNumbers.int2(raf);

                if (length > 42)
                {
                    // getP_VorL(raf);
                    // Vertical coordinates (NV) and thinned grids (PL) not supported - skip this
                    SupportClass.Skip(raf, length - 42);
                }

                break;                         // end Lambert Conformal


            case 5:                      //  Polar Stereographic grids

                // octets 18-20 (Lov - Orientation of the grid - east lon parallel to y axis)
                lov = GribNumbers.int3(raf) / 1000.0;

                // octets 21-23 (Dx - Longitudinal Direction Increment )
                dx = GribNumbers.int3(raf);

                // octets 24-26(Dy - Latitudinal Direction Increment )
                dy = GribNumbers.int3(raf);

                // octets 27 (Projection Center flag) See Note 5 of Table D
                proj_center = raf.ReadByte();

                // octet 28 (Scanning mode)  See Table 8
                scan = raf.ReadByte();

                // octet 29-32 reserved
                reserved = GribNumbers.int4(raf);

                if (length > 32)
                {
                    // getP_VorL(raf);
                    // Vertical coordinates (NV) and thinned grids (PL) not supported - skip this
                    SupportClass.Skip(raf, length - 32);
                }

                break;                         // end Polar Stereographic grids

            //rotated grid
            case 10:
                //18-20
                this.lat2 = GribNumbers.int3(raf) / 1000.0;
                //21-23
                this.lon2 = GribNumbers.int3(raf) / 1000.0;

                //24-25
                var tmpDx = GribNumbers.int2(raf);
                this.dx = tmpDx == -1 ? -9999.0 : tmpDx / 1000.0;

                //26-27
                var tmpDy = GribNumbers.int2(raf);
                this.dy = tmpDy == -1 ? -9999.0 : tmpDy / 1000.0;

                //28
                scan = raf.ReadByte();
                //29-32
                GribNumbers.int4(raf);

                //33-35
                this.latsp = GribNumbers.int3(raf) / 1000.0;
                //36-38
                this.lonsp = GribNumbers.int3(raf) / 1000.0;

                //39-42 - angle
                GribNumbers.float4(raf);

                if (length > 42)
                {
                    SupportClass.Skip(raf, length - 42);
                }

                break;


            default:
                System.Console.Out.WriteLine("Unknown Grid Type : " + type);
                break;
            }             // end switch grid_type

            //System.out.println( "scan=" + scan );
            if ((scan & 63) != 0)
            {
                throw new NoValidGribException("GDS: This scanning mode (" + scan + ") is not supported.");
            }
        }         // end Grib1GridDefinitionSection( raf )
Ejemplo n.º 15
0
        // *** constructors *******************************************************

        /// <summary> Constructs a <tt>Grib2DataRepresentationSection</tt> object from a raf.
        ///
        /// </summary>
        /// <param name="raf">RandomAccessFile with Section DRS content
        /// </param>
        /// <throws>  IOException  if stream contains no valid GRIB file </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 Grib2DataRepresentationSection(System.IO.FileStream raf)
        {
            InitBlock();
            // octets 1-4 (Length of DRS)
            length = GribNumbers.int4(raf);
            //System.out.println( "DRS length=" + length );

            section = raf.ReadByte();
            //System.out.println( "DRS is 5 section=" + section );

            dataPoints = GribNumbers.int4(raf);
            //System.out.println( "DRS dataPoints=" + dataPoints );

            dataTemplate = (int)GribNumbers.uint2(raf);
            //System.out.println( "DRS dataTemplate=" + dataTemplate );

            switch (dataTemplate)
            {
            // Data Template Number
            case 0:
            case 1:                      // 0 - Grid point data - simple packing
                                         // 1 - Matrix values - simple packing
                                         //System.out.println( "DRS dataTemplate=" + dataTemplate );
                referenceValue     = GribNumbers.IEEEfloat4(raf);
                binaryScaleFactor  = GribNumbers.int2(raf);
                decimalScaleFactor = GribNumbers.int2(raf);
                numberOfBits       = raf.ReadByte();
                //System.out.println( "DRS numberOfBits=" + numberOfBits );
                originalType = raf.ReadByte();
                //System.out.println( "DRS originalType=" + originalType );

                if (dataTemplate == 0)
                {
                    break;
                }
                // case 1 not implememted
                System.Console.Out.WriteLine("DRS dataTemplate=1 not implemented yet");
                break;

            case 2:
            case 3:                      // Grid point data - complex packing
                                         //System.out.println( "DRS dataTemplate=" + dataTemplate );
                                         // octet 12 - 15
                referenceValue = GribNumbers.IEEEfloat4(raf);
                // octet 16 - 17
                binaryScaleFactor = GribNumbers.int2(raf);
                // octet 18 - 19
                decimalScaleFactor = GribNumbers.int2(raf);
                // octet 20
                numberOfBits = raf.ReadByte();
                //System.out.println( "DRS numberOfBits=" + numberOfBits );
                // octet 21
                originalType = raf.ReadByte();
                //System.out.println( "DRS originalType=" + originalType );
                // octet 22
                splittingMethod = raf.ReadByte();
                //System.out.println( "DRS splittingMethod=" +
                //     splittingMethod );
                // octet 23
                missingValueManagement = raf.ReadByte();
                //System.out.println( "DRS missingValueManagement=" +
                //     missingValueManagement );
                // octet 24 - 27
                primaryMissingValue = GribNumbers.IEEEfloat4(raf);
                // octet 28 - 31
                secondaryMissingValue = GribNumbers.IEEEfloat4(raf);
                // octet 32 - 35
                numberOfGroups = GribNumbers.int4(raf);
                //System.out.println( "DRS numberOfGroups=" +
                //     numberOfGroups );
                // octet 36
                referenceGroupWidths = raf.ReadByte();
                //System.out.println( "DRS referenceGroupWidths=" +
                //     referenceGroupWidths );
                // octet 37
                bitsGroupWidths = raf.ReadByte();
                // according to documentation subtract referenceGroupWidths
                bitsGroupWidths = bitsGroupWidths - referenceGroupWidths;
                //System.out.println( "DRS bitsGroupWidths=" +
                //     bitsGroupWidths );
                // octet 38 - 41
                referenceGroupLength = GribNumbers.int4(raf);
                //System.out.println( "DRS referenceGroupLength=" +
                //     referenceGroupLength );
                // octet 42
                lengthIncrement = raf.ReadByte();
                //System.out.println( "DRS lengthIncrement=" +
                //     lengthIncrement );
                // octet 43 - 46
                lengthLastGroup = GribNumbers.int4(raf);
                //System.out.println( "DRS lengthLastGroup=" +
                //     lengthLastGroup );
                // octet 47
                bitsScaledGroupLength = raf.ReadByte();
                //System.out.println( "DRS bitsScaledGroupLength=" +
                //     bitsScaledGroupLength );
                if (dataTemplate == 2)
                {
                    break;
                }

                // case 3 // complex packing & spatial differencing
                orderSpatial = raf.ReadByte();
                //System.out.println( "DRS orderSpatial=" + orderSpatial);
                descriptorSpatial = raf.ReadByte();
                //System.out.println( "DRS descriptorSpatial=" + descriptorSpatial);
                break;


            case 40:
            case 40000:                      // Grid point data - JPEG 2000 Code Stream Format
                //System.out.println( "DRS dataTemplate=" + dataTemplate );

                referenceValue     = GribNumbers.IEEEfloat4(raf);
                binaryScaleFactor  = GribNumbers.int2(raf);
                decimalScaleFactor = GribNumbers.int2(raf);
                numberOfBits       = raf.ReadByte();
                //System.out.println( "DRS numberOfBits=" + numberOfBits );
                originalType = raf.ReadByte();
                //System.out.println( "DRS originalType=" + originalType );
                compressionMethod = raf.ReadByte();
                //System.out.println( "DRS compressionMethod=" + compressionMethod );
                compressionRatio = raf.ReadByte();
                //System.out.println( "DRS compressionRatio=" + compressionRatio );
                break;

            default:
                break;
            }
        }         // end of Grib2DataRepresentationSection
Ejemplo n.º 16
0
        // *** constructors *******************************************************

        /// <summary> Constructs a <tt>Grib2GridDefinitionSection</tt> object from a raf.
        ///
        /// </summary>
        /// <param name="raf">RandomAccessFile
        /// </param>
        /// <param name="doCheckSum"> calculate the checksum
        /// </param>
        /// <throws>  IOException  if raf contains no valid GRIB product </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 Grib2GridDefinitionSection(System.IO.FileStream raf, bool doCheckSum)
        {
            int scalefactorradius = 0;
            int scaledvalueradius = 0;
            int scalefactormajor  = 0;
            int scaledvaluemajor  = 0;
            int scalefactorminor  = 0;
            int scaledvalueminor  = 0;

            // octets 1-4 (Length of GDS)
            length = GribNumbers.int4(raf);
            //System.out.println( "GDS length=" + length );

            if (doCheckSum)
            {
                /*
                 *              // get byte array for this gds, then reset raf to same position
                 *              // calculate checksum for this gds via the byte array
                 *              long mark = raf.Position;
                 *              sbyte[] dst = new sbyte[length - 4];
                 *              SupportClass.ReadInput(raf, dst, 0, dst.Length);
                 *              raf.Seek(mark, System.IO.SeekOrigin.Begin);
                 *              //UPGRADE_ISSUE: Class 'java.util.zip.CRC32' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilzipCRC32'"
                 *              //UPGRADE_ISSUE: Constructor 'java.util.zip.CRC32.CRC32' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilzipCRC32'"
                 *              CRC32 cs = new CRC32();
                 *              //UPGRADE_ISSUE: Method 'java.util.zip.CRC32.update' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilzipCRC32'"
                 *              cs.update(dst);
                 *              //UPGRADE_ISSUE: Method 'java.util.zip.CRC32.getValue' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilzipCRC32'"
                 *              checksum = System.Convert.ToString(cs.getValue());
                 *              //System.out.println( "GDS checksum =" + checksum );
                 */
                // TODO Check this
            }

            section = raf.ReadByte();             // This is section 3
            //System.out.println( "GDS is 3, section=" + section );

            source = raf.ReadByte();
            //System.out.println( "GDS source=" + source );

            numberPoints = GribNumbers.int4(raf);
            //System.out.println( "GDS numberPoints=" + numberPoints );

            olon = raf.ReadByte();
            //System.out.println( "GDS olon=" + olon );

            iolon = raf.ReadByte();
            //System.out.println( "GDS iolon=" + iolon );

            gdtn = GribNumbers.int2(raf);
            //System.out.println( "GDS gdtn=" + gdtn );

            name = getGridName(gdtn);

            float ratio;

            switch (gdtn)
            {
            // Grid Definition Template Number
            case 0:
            case 1:
            case 2:
            case 3:                      // Latitude/Longitude Grid
                shape = raf.ReadByte();
                //System.out.println( "shape=" + shape );
                scalefactorradius = raf.ReadByte();
                scaledvalueradius = GribNumbers.int4(raf);
                scalefactormajor  = raf.ReadByte();
                scaledvaluemajor  = GribNumbers.int4(raf);
                scalefactorminor  = raf.ReadByte();
                scaledvalueminor  = GribNumbers.int4(raf);
                nx = GribNumbers.int4(raf);
                //System.out.println( "nx=" + nx);
                ny = GribNumbers.int4(raf);
                //System.out.println( "ny=" + ny);
                angle             = GribNumbers.int4(raf);
                subdivisionsangle = GribNumbers.int4(raf);
                if (angle == 0)
                {
                    ratio = tenToNegSix;
                }
                else
                {
                    ratio = angle / subdivisionsangle;
                }
                //System.out.println( "ratio =" + ratio );
                la1        = (float)(GribNumbers.int4(raf) * ratio);
                lo1        = (float)(GribNumbers.int4(raf) * ratio);
                resolution = raf.ReadByte();
                la2        = (float)(GribNumbers.int4(raf) * ratio);
                lo2        = (float)(GribNumbers.int4(raf) * ratio);
                dx         = (float)(GribNumbers.int4(raf) * ratio);
                dy         = (float)(GribNumbers.int4(raf) * ratio);
                scanMode   = raf.ReadByte();

                //  1, 2, and 3 needs checked
                if (gdtn == 1)
                {
                    //Rotated Latitude/longitude
                    spLat         = GribNumbers.int4(raf) * tenToNegSix;
                    spLon         = GribNumbers.int4(raf) * tenToNegSix;
                    rotationangle = GribNumbers.IEEEfloat4(raf);
                }
                else if (gdtn == 2)
                {
                    //Stretched Latitude/longitude
                    poleLat = GribNumbers.int4(raf) * tenToNegSix;
                    poleLon = GribNumbers.int4(raf) * tenToNegSix;
                    factor  = GribNumbers.int4(raf);
                }
                else if (gdtn == 3)
                {
                    //Stretched and Rotated
                    // Latitude/longitude
                    spLat         = GribNumbers.int4(raf) * tenToNegSix;
                    spLon         = GribNumbers.int4(raf) * tenToNegSix;
                    rotationangle = GribNumbers.IEEEfloat4(raf);
                    poleLat       = GribNumbers.int4(raf) * tenToNegSix;
                    poleLon       = GribNumbers.int4(raf) * tenToNegSix;
                    factor        = GribNumbers.int4(raf);
                }
                break;


            case 10:                      // Mercator
                // la1, lo1, lad, la2, and lo2 need checked
                shape = raf.ReadByte();
                //System.out.println( "shape=" + shape );
                scalefactorradius = raf.ReadByte();
                scaledvalueradius = GribNumbers.int4(raf);
                scalefactormajor  = raf.ReadByte();
                scaledvaluemajor  = GribNumbers.int4(raf);
                scalefactorminor  = raf.ReadByte();
                scaledvalueminor  = GribNumbers.int4(raf);
                nx = GribNumbers.int4(raf);
                //System.out.println( "nx=" + nx);
                ny = GribNumbers.int4(raf);
                //System.out.println( "ny=" + ny);
                la1        = GribNumbers.int4(raf) * tenToNegSix;
                lo1        = GribNumbers.int4(raf) * tenToNegSix;
                resolution = raf.ReadByte();
                lad        = GribNumbers.int4(raf) * tenToNegSix;
                la2        = GribNumbers.int4(raf) * tenToNegSix;
                lo2        = GribNumbers.int4(raf) * tenToNegSix;
                scanMode   = raf.ReadByte();
                angle      = GribNumbers.int4(raf);
                dx         = (float)(GribNumbers.int4(raf) * tenToNegThree);
                dy         = (float)(GribNumbers.int4(raf) * tenToNegThree);

                break;


            case 20:                      // Polar stereographic projection
                // la1, lo1, lad, and lov need checked
                shape = raf.ReadByte();
                //System.out.println( "shape=" + shape );
                scalefactorradius = raf.ReadByte();
                scaledvalueradius = GribNumbers.int4(raf);
                scalefactormajor  = raf.ReadByte();
                scaledvaluemajor  = GribNumbers.int4(raf);
                scalefactorminor  = raf.ReadByte();
                scaledvalueminor  = GribNumbers.int4(raf);
                nx = GribNumbers.int4(raf);
                //System.out.println( "nx=" + nx);
                ny = GribNumbers.int4(raf);
                //System.out.println( "ny=" + ny);
                la1              = GribNumbers.int4(raf) * tenToNegSix;
                lo1              = GribNumbers.int4(raf) * tenToNegSix;
                resolution       = raf.ReadByte();
                lad              = GribNumbers.int4(raf) * tenToNegSix;
                lov              = GribNumbers.int4(raf) * tenToNegSix;
                dx               = (float)(GribNumbers.int4(raf) * tenToNegThree);
                dy               = (float)(GribNumbers.int4(raf) * tenToNegThree);
                projectionCenter = raf.ReadByte();
                scanMode         = raf.ReadByte();

                break;


            case 30:                      // Lambert Conformal
                shape = raf.ReadByte();
                //System.out.println( "shape=" + shape );
                scalefactorradius = raf.ReadByte();
                scaledvalueradius = GribNumbers.int4(raf);
                scalefactormajor  = raf.ReadByte();
                scaledvaluemajor  = GribNumbers.int4(raf);
                scalefactorminor  = raf.ReadByte();
                scaledvalueminor  = GribNumbers.int4(raf);
                nx = GribNumbers.int4(raf);
                //System.out.println( "nx=" + nx);
                ny = GribNumbers.int4(raf);
                //System.out.println( "ny=" + ny);
                la1 = (float)(GribNumbers.int4(raf) * tenToNegSix);
                //System.out.println( "la1=" + la1 );
                lo1 = (float)(GribNumbers.int4(raf) * tenToNegSix);
                //System.out.println( "lo1=" + lo1);
                resolution       = raf.ReadByte();
                lad              = (float)(GribNumbers.int4(raf) * tenToNegSix);
                lov              = (float)(GribNumbers.int4(raf) * tenToNegSix);
                dx               = (float)(GribNumbers.int4(raf) * tenToNegThree);
                dy               = (float)(GribNumbers.int4(raf) * tenToNegThree);
                projectionCenter = raf.ReadByte();
                scanMode         = raf.ReadByte();
                latin1           = (float)(GribNumbers.int4(raf) * tenToNegSix);
                latin2           = (float)(GribNumbers.int4(raf) * tenToNegSix);
                //System.out.println( "latin1=" + latin1);
                //System.out.println( "latin2=" + latin2);
                spLat = (float)(GribNumbers.int4(raf) * tenToNegSix);
                spLon = (float)(GribNumbers.int4(raf) * tenToNegSix);
                //System.out.println( "spLat=" + spLat);
                //System.out.println( "spLon=" + spLon);

                break;


            case 31:                      // Albers Equal Area
                // la1, lo1, lad, and lov need checked
                shape = raf.ReadByte();
                //System.out.println( "shape=" + shape );
                scalefactorradius = raf.ReadByte();
                scaledvalueradius = GribNumbers.int4(raf);
                scalefactormajor  = raf.ReadByte();
                scaledvaluemajor  = GribNumbers.int4(raf);
                scalefactorminor  = raf.ReadByte();
                scaledvalueminor  = GribNumbers.int4(raf);
                nx = GribNumbers.int4(raf);
                //System.out.println( "nx=" + nx);
                ny = GribNumbers.int4(raf);
                //System.out.println( "ny=" + ny);
                la1 = GribNumbers.int4(raf) * tenToNegSix;
                //System.out.println( "la1=" + la1 );
                lo1 = GribNumbers.int4(raf) * tenToNegSix;
                //System.out.println( "lo1=" + lo1);
                resolution       = raf.ReadByte();
                lad              = GribNumbers.int4(raf) * tenToNegSix;
                lov              = GribNumbers.int4(raf) * tenToNegSix;
                dx               = (float)(GribNumbers.int4(raf) * tenToNegThree);
                dy               = (float)(GribNumbers.int4(raf) * tenToNegThree);
                projectionCenter = raf.ReadByte();
                scanMode         = raf.ReadByte();
                latin1           = GribNumbers.int4(raf) * tenToNegSix;
                latin2           = GribNumbers.int4(raf) * tenToNegSix;
                //System.out.println( "latin1=" + latin1);
                //System.out.println( "latin2=" + latin2);
                spLat = GribNumbers.int4(raf) * tenToNegSix;
                spLon = GribNumbers.int4(raf) * tenToNegSix;
                //System.out.println( "spLat=" + spLat);
                //System.out.println( "spLon=" + spLon);

                break;


            case 40:
            case 41:
            case 42:
            case 43:                      // Gaussian latitude/longitude
                shape = raf.ReadByte();
                //System.out.println( "shape=" + shape );
                scalefactorradius = raf.ReadByte();
                scaledvalueradius = GribNumbers.int4(raf);
                scalefactormajor  = raf.ReadByte();
                scaledvaluemajor  = GribNumbers.int4(raf);
                scalefactorminor  = raf.ReadByte();
                scaledvalueminor  = GribNumbers.int4(raf);
                nx = GribNumbers.int4(raf);
                //System.out.println( "nx=" + nx);
                ny = GribNumbers.int4(raf);
                //System.out.println( "ny=" + ny);
                angle             = GribNumbers.int4(raf);
                subdivisionsangle = GribNumbers.int4(raf);
                if (angle == 0)
                {
                    ratio = tenToNegSix;
                }
                else
                {
                    ratio = angle / subdivisionsangle;
                }
                //System.out.println( "ratio =" + ratio );
                la1        = (float)(GribNumbers.int4(raf) * ratio);
                lo1        = (float)(GribNumbers.int4(raf) * ratio);
                resolution = raf.ReadByte();
                la2        = (float)(GribNumbers.int4(raf) * ratio);
                lo2        = (float)(GribNumbers.int4(raf) * ratio);
                dx         = (float)(GribNumbers.int4(raf) * ratio);
                n          = raf.ReadByte();
                scanMode   = raf.ReadByte();

                if (gdtn == 41)
                {
                    //Rotated Gaussian Latitude/longitude

                    spLat         = GribNumbers.int4(raf) * ratio;
                    spLon         = GribNumbers.int4(raf) * ratio;
                    rotationangle = GribNumbers.IEEEfloat4(raf);
                }
                else if (gdtn == 42)
                {
                    //Stretched Gaussian
                    // Latitude/longitude

                    poleLat = GribNumbers.int4(raf) * ratio;
                    poleLon = GribNumbers.int4(raf) * ratio;
                    factor  = GribNumbers.int4(raf);
                }
                else if (gdtn == 43)
                {
                    //Stretched and Rotated Gaussian
                    // Latitude/longitude

                    spLat         = GribNumbers.int4(raf) * ratio;
                    spLon         = GribNumbers.int4(raf) * ratio;
                    rotationangle = GribNumbers.IEEEfloat4(raf);
                    poleLat       = GribNumbers.int4(raf) * ratio;
                    poleLon       = GribNumbers.int4(raf) * ratio;
                    factor        = GribNumbers.int4(raf);
                }
                break;


            case 50:
            case 51:
            case 52:
            case 53:                      // Spherical harmonic coefficients

                j      = GribNumbers.IEEEfloat4(raf);
                k      = GribNumbers.IEEEfloat4(raf);
                m      = GribNumbers.IEEEfloat4(raf);
                method = raf.ReadByte();
                mode   = raf.ReadByte();
                if (gdtn == 51)
                {
                    //Rotated Spherical harmonic coefficients

                    spLat         = GribNumbers.int4(raf) * tenToNegSix;
                    spLon         = GribNumbers.int4(raf) * tenToNegSix;
                    rotationangle = GribNumbers.IEEEfloat4(raf);
                }
                else if (gdtn == 52)
                {
                    //Stretched Spherical
                    // harmonic coefficients

                    poleLat = GribNumbers.int4(raf) * tenToNegSix;
                    poleLon = GribNumbers.int4(raf) * tenToNegSix;
                    factor  = GribNumbers.int4(raf);
                }
                else if (gdtn == 53)
                {
                    //Stretched and Rotated
                    // Spherical harmonic coefficients

                    spLat         = GribNumbers.int4(raf) * tenToNegSix;
                    spLon         = GribNumbers.int4(raf) * tenToNegSix;
                    rotationangle = GribNumbers.IEEEfloat4(raf);
                    poleLat       = GribNumbers.int4(raf) * tenToNegSix;
                    poleLon       = GribNumbers.int4(raf) * tenToNegSix;
                    factor        = GribNumbers.int4(raf);
                }
                break;


            case 90:                      // Space view perspective or orthographic
                shape = raf.ReadByte();
                //System.out.println( "shape=" + shape );
                scalefactorradius = raf.ReadByte();
                scaledvalueradius = GribNumbers.int4(raf);
                scalefactormajor  = raf.ReadByte();
                scaledvaluemajor  = GribNumbers.int4(raf);
                scalefactorminor  = raf.ReadByte();
                scaledvalueminor  = GribNumbers.int4(raf);
                nx = GribNumbers.int4(raf);
                //System.out.println( "nx=" + nx);
                ny = GribNumbers.int4(raf);
                //System.out.println( "ny=" + ny);
                lap        = GribNumbers.int4(raf);
                lop        = GribNumbers.int4(raf);
                resolution = raf.ReadByte();
                dx         = GribNumbers.int4(raf);
                dy         = GribNumbers.int4(raf);
                xp         = (float)(GribNumbers.int4(raf) * tenToNegThree);
                yp         = (float)(GribNumbers.int4(raf) * tenToNegThree);
                scanMode   = raf.ReadByte();
                angle      = GribNumbers.int4(raf);
                altitude   = GribNumbers.int4(raf) * 1000000;
                xo         = GribNumbers.int4(raf);
                yo         = GribNumbers.int4(raf);

                break;


            case 100:                      // Triangular grid based on an icosahedron

                n2          = raf.ReadByte();
                n3          = raf.ReadByte();
                ni          = GribNumbers.int2(raf);
                nd          = raf.ReadByte();
                poleLat     = GribNumbers.int4(raf) * tenToNegSix;
                poleLon     = GribNumbers.int4(raf) * tenToNegSix;
                lonofcenter = GribNumbers.int4(raf);
                position    = raf.ReadByte();
                order       = raf.ReadByte();
                scanMode    = raf.ReadByte();
                n           = GribNumbers.int4(raf);
                break;


            case 110:                      // Equatorial azimuthal equidistant projection
                shape = raf.ReadByte();
                //System.out.println( "shape=" + shape );
                scalefactorradius = raf.ReadByte();
                scaledvalueradius = GribNumbers.int4(raf);
                scalefactormajor  = raf.ReadByte();
                scaledvaluemajor  = GribNumbers.int4(raf);
                scalefactorminor  = raf.ReadByte();
                scaledvalueminor  = GribNumbers.int4(raf);
                nx = GribNumbers.int4(raf);
                //System.out.println( "nx=" + nx);
                ny = GribNumbers.int4(raf);
                //System.out.println( "ny=" + ny);
                la1              = GribNumbers.int4(raf) * tenToNegSix;
                lo1              = GribNumbers.int4(raf) * tenToNegSix;
                resolution       = raf.ReadByte();
                dx               = (float)(GribNumbers.int4(raf) * tenToNegThree);
                dy               = (float)(GribNumbers.int4(raf) * tenToNegThree);
                projectionCenter = raf.ReadByte();
                scanMode         = raf.ReadByte();

                break;


            case 120:                      // Azimuth-range Projection
                nb       = GribNumbers.int4(raf);
                nr       = GribNumbers.int4(raf);
                la1      = GribNumbers.int4(raf);
                lo1      = GribNumbers.int4(raf);
                dx       = GribNumbers.int4(raf);
                dstart   = GribNumbers.IEEEfloat4(raf);
                scanMode = raf.ReadByte();
                for (int i = 0; i < nr; i++)
                {
                    // get azi (33+4(Nr-1))-(34+4(Nr-1))
                    // get adelta (35+4(Nr-1))-(36+4(Nr-1))
                }
                System.Console.Out.WriteLine("need code to get azi and adelta");

                break;


            default:
                System.Console.Out.WriteLine("Unknown Grid Type " + System.Convert.ToString(gdtn));
                break;
            }             // end switch

            // calculate earth radius
            if ((gdtn < 50 || gdtn > 53) && gdtn != 100 && gdtn != 120)
            {
                if (shape == 0)
                {
                    earthRadius = 6367470;
                }
                else if (shape == 1)
                {
                    earthRadius = scaledvalueradius;
                    if (scalefactorradius != 0)
                    {
                        earthRadius = (float)(earthRadius / System.Math.Pow(10, scalefactorradius));
                    }
                }
                else if (shape == 2)
                {
                    //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'"
                    majorAxis = (float)6378160.0;
                    //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'"
                    minorAxis = (float)6356775.0;
                }
                else if (shape == 3)
                {
                    majorAxis = scaledvaluemajor;
                    //System.out.println( "majorAxisScale =" + scalefactormajor );
                    //System.out.println( "majorAxisiValue =" + scaledvaluemajor );
                    majorAxis = (float)(majorAxis / System.Math.Pow(10, scalefactormajor));

                    minorAxis = scaledvalueminor;
                    //System.out.println( "minorAxisScale =" + scalefactorminor );
                    //System.out.println( "minorAxisValue =" + scaledvalueminor );
                    minorAxis = (float)(minorAxis / System.Math.Pow(10, scalefactorminor));
                }
                else if (shape == 4)
                {
                    //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'"
                    majorAxis = (float)6378137.0;
                    minorAxis = (float)SupportClass.Identity(6356752.314);
                }
                else if (shape == 6)
                {
                    earthRadius = 6371229;
                }
            }
        }         // end of Grib2GridDefinitionSection
Ejemplo n.º 17
0
        /// <summary> Creates an ensemble object for the product PDS.</summary>
        /// <param name="raf">RandomAccessFile.
        /// </param>
        /// <param name="parameterNumber">
        /// </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'"
        internal Grib1Ensemble(System.IO.Stream raf, int parameterNumber)
        {
            // skip 12 bytes to start of ensemble
            SupportClass.Skip(raf, 12);

            // octet 41 id's ensemble
            int app = raf.ReadByte();

            if (app != 1)
            {
                System.Console.Out.WriteLine("not ensemble product");
                return;
            }

            // octet 42 Type
            eType = raf.ReadByte();

            // octet 43 Identification number
            eId = raf.ReadByte();

            // octet 44 Product Identifier
            eProd = raf.ReadByte();

            // octet 45 Spatial Identifier
            eSpatial = raf.ReadByte();

            if (parameterNumber == 191 || parameterNumber == 192)
            {
                // octet 46 Probability product definition
                epd = raf.ReadByte();

                // octet 47 Probability type
                ept = raf.ReadByte();

                // octet 48-51 Probability lower limit
                epll = GribNumbers.int4(raf);

                // octet 52-55 Probability upper limit
                epul = GribNumbers.int4(raf);

                // octet 56-60 reserved
                int reserved = GribNumbers.int4(raf);

                if (eType == 4 || eType == 5)
                {
                    // octet 61 Ensemble size
                    eSize = raf.ReadByte();

                    // octet 62 Cluster size
                    eCSize = raf.ReadByte();

                    // octet 63 Number of clusters
                    eCNumber = raf.ReadByte();

                    // octet 64 Clustering Method
                    eCMethod = raf.ReadByte();

                    // octet 65-67 Northern latitude of clustering domain
                    nLat = GribNumbers.int3(raf);

                    // octet 68-70 Southern latitude of clustering domain
                    sLat = GribNumbers.int3(raf);

                    // octet 71-73 Eastern latitude of clustering domain
                    eLat = GribNumbers.int3(raf);

                    // octet 74-76 Western latitude of clustering domain
                    wLat = GribNumbers.int3(raf);

                    if (eType == 4)
                    {
                        // octets 77-86 Cluster Membership
                        cm = new sbyte[10];
                        SupportClass.ReadInput(raf, cm, 0, cm.Length);
                    }
                }
            }
        }
Ejemplo n.º 18
0
 public int ReadInt32(int startByte)
 {
     // Use GribNumbers to handle endian byte swapping
     return(GribNumbers.int4(_memStream));
 }