Example #1
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