Package ucar.nc2.grib

Class GribNumbers


  • public final class GribNumbers
    extends Object
    Utilities for reading and interpreting GRIB bytes.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int MISSING
      Grib uses this internally to mean missing
      static int UNDEFINED
      If missing value is not defined use this value.
      static double UNDEFINEDD  
    • Constructor Summary

      Constructors 
      Constructor Description
      GribNumbers()  
    • Field Detail

      • UNDEFINED

        public static final int UNDEFINED
        If missing value is not defined use this value.
        See Also:
        Constant Field Values
      • MISSING

        public static final int MISSING
        Grib uses this internally to mean missing
        See Also:
        Constant Field Values
    • Constructor Detail

      • GribNumbers

        public GribNumbers()
    • Method Detail

      • testGribBitIsSet

        public static boolean testGribBitIsSet​(int value,
                                               int gribBitNumber)
        Test if the given gribBitNumber is set in the test value.
        Parameters:
        value - test the 8 bits in this value .
        gribBitNumber - one based, starting from highest bit. Must be between 1-8.
        Returns:
        true if the given gribBitNumber is set.
      • testBitIsSet

        public static boolean testBitIsSet​(int value,
                                           int bit)
        Test if the given bit is set in the test value.
        Parameters:
        value - test the 8 bits in this value .
        bit - zero based, starting from highest bit. Must be between 0-7.
        Returns:
        true if the given bit is set.
      • isUndefined

        public static boolean isUndefined​(double d)
      • int2

        public static int int2​(RandomAccessFile raf)
                        throws IOException
        Convert 2 bytes into a signed integer.
        Parameters:
        raf - read from here
        Returns:
        integer value
        Throws:
        IOException - on read error
      • uint

        public static int uint​(RandomAccessFile raf)
                        throws IOException
        Convert unsigned bytes into an integer.
        Parameters:
        raf - read one byte from here
        Returns:
        integer value
        Throws:
        IOException - on read error
      • int2

        public static int int2​(int a,
                               int b)
        convert 2 bytes to a signed integer.
        Parameters:
        a - first byte
        b - second byte
        Returns:
        int
      • int3

        public static int int3​(RandomAccessFile raf)
                        throws IOException
        Convert 3 bytes into a signed integer.
        Parameters:
        raf - read from here
        Returns:
        integer value
        Throws:
        IOException - on read error
      • int3

        public static int int3​(int a,
                               int b,
                               int c)
        Convert 3 bytes to signed integer.
        Parameters:
        a - first byte
        b - second byte
        c - third byte
        Returns:
        int
      • int4

        public static int int4​(RandomAccessFile raf)
                        throws IOException
        Convert 4 bytes into a signed integer.
        Parameters:
        raf - read from here
        Returns:
        integer value
        Throws:
        IOException - on read error
      • int4

        public static int int4​(int a,
                               int b,
                               int c,
                               int d)
        Convert 4 bytes into a signed integer.
        Parameters:
        a - first byte
        b - second byte
        c - third byte
        d - fourth byte
        Returns:
        int
      • uint2

        public static int uint2​(RandomAccessFile raf)
                         throws IOException
        Convert 2 bytes into an unsigned integer.
        Parameters:
        raf - read from here
        Returns:
        integer value
        Throws:
        IOException - on read error
      • uint2

        public static int uint2​(int a,
                                int b)
        convert 2 bytes to an unsigned integer.
        Parameters:
        a - first byte
        b - second byte
        Returns:
        unsigned int
      • uint3

        public static int uint3​(RandomAccessFile raf)
                         throws IOException
        Convert 3 bytes into an unsigned integer.
        Parameters:
        raf - read from here
        Returns:
        integer
        Throws:
        IOException - on read error
      • uint3

        public static int uint3​(int a,
                                int b,
                                int c)
        Convert 3 bytes into an unsigned int.
        Parameters:
        a - first byte
        b - second byte
        c - third byte
        Returns:
        unsigned integer
      • float4

        public static float float4​(RandomAccessFile raf)
                            throws IOException
        Convert 4 bytes into a float value.
        Parameters:
        raf - read from here
        Returns:
        float value
        Throws:
        IOException - on read error
      • float4

        public static float float4​(int a,
                                   int b,
                                   int c,
                                   int d)
        Convert 4 bytes to a float.
        Parameters:
        a - first byte
        b - second byte
        c - third byte
        d - fourth byte
        Returns:
        float
      • int8

        public static long int8​(RandomAccessFile raf)
                         throws IOException
        Convert 8 bytes into a signed long.
        Parameters:
        raf - RandomAccessFile
        Returns:
        long value
        Throws:
        IOException - on read error
      • convertSignedByte

        public static int convertSignedByte​(byte v)
        A signed byte has a sign bit then 1 15-bit value. This is not twos complement (!)
        Parameters:
        v - convert byte to signed int
        Returns:
        signed int
      • convertSignedByte2

        public static int convertSignedByte2​(byte v)
      • countBits

        public static int countBits​(byte[] bitmap)