visad/src/main/java/ucar/nc2/iosp/gempak/GempakGridReader.java
private synchronized float[] DP_UGRB(int[] idata, int kxky, int nbits,
                                       float qmin, float scale,
                                       boolean misflg, int decimalScale)
          throws IOException {
    float scaleFactor = (decimalScale == 0)
            ? 1.f
            : (float) Math.pow(10.0, -decimalScale);
    //
    //Check for valid input.
    //
    float[] grid = new float[kxky];
    if ((nbits <= 1) || (nbits > 31)) {
      return grid;
    }
    if (scale == 0.) {
      return grid;
    }

    //
    //Compute missing data value.
    //
    int imax = (int) (Math.pow(2, nbits) - 1);
    //
    //Retrieve data points from buffer.
    //
    int iword = 0;
    int ibit = 1;  // 1 based bit position
    for (int i = 0; i < kxky; i++) {
      //
      //    Get the integer from the buffer.
      //
      int jshft = nbits + ibit - 33;
      int idat = 0;
      idat = (jshft < 0)
              ? idata[iword] >>> Math.abs(jshft)
              : idata[iword] << jshft;
      idat = idat & imax;
      //
      //    Check to see if packed integer overflows into next word. LOOK fishy bit operations
      //
      if (jshft > 0) {
        jshft -= 32;
        int idat2 = 0;
        idat2 = idata[iword + 1] >>> Math.abs(jshft);
        idat = idat | idat2;
      }
      //
      //    Compute value of word.
      //
      if ((idat == imax) && misflg) {
        grid[i] = RMISSD;
      } else {
        grid[i] = (qmin + idat * scale) * scaleFactor;
      }
      //
      //    Set location for next word.
      //
      ibit += nbits;
      if (ibit > 32) {
        ibit -= 32;
        iword++;
      }
            /*
            if (i < 25) {
                System.out.println("grid["+i+"]: " + grid[i]);
            }
            */
    }
    return grid;
  }
private synchronized float[] DP_UGRB(int[] idata, int kxky, int nbits,
                                       float qmin, float scale,
                                       boolean misflg, int decimalScale)
          throws IOException {
    float scaleFactor = (decimalScale == 0)
            ? 1.f
            : (float) Math.pow(10.0, -decimalScale);
    //
    //Check for valid input.
    //
    float[] grid = new float[kxky];
    if ((nbits <= 1) || (nbits > 31)) {
      return grid;
    }
    if (scale == 0.) {
      return grid;
    }

    //
    //Compute missing data value.
    //
    int imax = (int) (Math.pow(2, nbits) - 1);
    //
    //Retrieve data points from buffer.
    //
    int iword = 0;
    int ibit = 1;  // 1 based bit position
    for (int i = 0; i < kxky; i++) {
      //
      //    Get the integer from the buffer.
      //
      int jshft = nbits + ibit - 33;
      int idat = 0;
      idat = (jshft < 0)
              ? idata[iword] >>> Math.abs(jshft)
              : idata[iword] << jshft;
      idat = idat & imax;
      //
      //    Check to see if packed integer overflows into next word. LOOK fishy bit operations
      //
      if (jshft > 0) {
        jshft -= 32;
        int idat2 = 0;
        idat2 = idata[iword + 1] >>> Math.abs(jshft);
        idat = idat | idat2;
      }
      //
      //    Compute value of word.
      //
      if ((idat == imax) && misflg) {
        grid[i] = RMISSD;
      } else {
        grid[i] = (qmin + idat * scale) * scaleFactor;
      }
      //
      //    Set location for next word.
      //
      ibit += nbits;
      if (ibit > 32) {
        ibit -= 32;
        iword++;
      }
            /*
            if (i < 25) {
                System.out.println("grid["+i+"]: " + grid[i]);
            }
            */
    }
    return grid;
  }
private synchronized float [ ] DP_UGRB ( int [ ] idata , int kxky , int nbits , float qmin , float scale , boolean misflg , int decimalScale ) throws IOException { float scaleFactor = ( decimalScale == 0 ) ? 1.f : ( float ) Math . pow ( 10.0 , - decimalScale ) ; // //Check for valid input. // float [ ] grid = new float [ kxky ] ; if ( ( nbits <= 1 ) || ( nbits > 31 ) ) { return grid ; } if ( scale == 0. ) { return grid ; } // //Compute missing data value. // int imax = ( int ) ( Math . pow ( 2 , nbits ) - 1 ) ; // //Retrieve data points from buffer. // int iword = 0 ; int ibit = 1 ; // 1 based bit position for ( int i = 0 ; i < kxky ; i ++ ) { // //    Get the integer from the buffer. // int jshft = nbits + ibit - 33 ; int idat = 0 ; idat = ( jshft < 0 ) ? idata [ iword ] >>> Math . abs ( jshft ) : idata [ iword ] << jshft ; idat = idat & imax ; // //    Check to see if packed integer overflows into next word. LOOK fishy bit operations // if ( jshft > 0 ) { jshft -= 32 ; int idat2 = 0 ; idat2 = idata [ iword + 1 ] >>> Math . abs ( jshft ) ; idat = idat | idat2 ; } // //    Compute value of word. // if ( ( idat == imax ) && misflg ) { grid [ i ] = RMISSD ; } else { grid [ i ] = ( qmin + idat * scale ) * scaleFactor ; } // //    Set location for next word. // ibit += nbits ; if ( ibit > 32 ) { ibit -= 32 ; iword ++ ; } /*
            if (i < 25) {
                System.out.println("grid["+i+"]: " + grid[i]);
            }
            */ } return grid ; }
Unpack grib data packed into ints

@param idata        int array of packed data
@param kxky         number of output points
@param nbits        number of bits per point
@param qmin         minimum (reference) value
@param scale        parameter scale
@param misflg       missing flag
@param decimalScale scale of value to jive with units
@return the array of unpacked values
@throws IOException problem reading from the file
Unpack grib data packed into ints