grib/src/main/java/ucar/nc2/grib/grib2/Grib2DataReader.java
private float[] getData40(RandomAccessFile raf, Grib2Drs.Type40 gdrs) throws IOException {
    // 6-xx  jpeg2000 data block to decode

    // dataPoints are number of points encoded, it could be less than the
    // totalNPoints in the grid record if bitMap is used, otherwise equal
    //int dataPoints = drs.getDataPoints();

    int nb = gdrs.numberOfBits;
    int D = gdrs.decimalScaleFactor;
    float DD = (float) java.lang.Math.pow((double) 10, (double) D);
    float R = gdrs.referenceValue;
    int E = gdrs.binaryScaleFactor;
    float EE = (float) java.lang.Math.pow(2.0, (double) E);
    float ref_val = R / DD;

    Grib2JpegDecoder g2j = null;
    // try {
    if (nb != 0) {  // there's data to decode
      g2j = new Grib2JpegDecoder(nb, false);
      byte[] buf = new byte[dataLength - 5];
      raf.readFully(buf);
      g2j.decode(buf);
      gdrs.hasSignedProblem = g2j.hasSignedProblem();
    }

    float[] result = new float[totalNPoints];

    // no data to decode, set to reference value
    if (nb == 0) {
      for (int i = 0; i < dataNPoints; i++) {
        result[i] = ref_val;
      }
      return result;
    }

    int[] idata = g2j.getGdata();
    if (bitmap == null) { // must be one decoded value in idata for every expected data point
      if (idata.length != dataNPoints) {
        logger.debug("Number of points in the data record {} != {} expected from GDS", idata.length,
            dataNPoints);
        throw new IllegalStateException(
            "Number of points in the data record {} != expected from GDS");
      }

      for (int i = 0; i < dataNPoints; i++) {
        // Y * 10^D = R + (X1 + X2) * 2^E ; // regulation 92.9.4
        // Y = (R + ( 0 + X2) * EE)/DD ;
        result[i] = (R + idata[i] * EE) / DD;
      }
      return result;

    } else {  // use bitmap to skip missing values
      for (int i = 0, j = 0; i < totalNPoints; i++) {
        if (GribNumbers.testBitIsSet(bitmap[i / 8], i % 8)) {
          if (j >= idata.length) {
            logger.warn("HEY jj2000 data count %d < bitmask count %d, i=%d, totalNPoints=%d%n",
                    idata.length, j, i, totalNPoints);
            break;
          }
          int indata = idata[j];
          result[i] = (R + indata * EE) / DD;
          j++;
        } else {
          result[i] = staticMissingValue;
        }
      }
    }
    return result;

    /* } catch (NullPointerException npe) {

      logger.error("Grib2DataReader2.jpeg2000Unpacking: bit rate too small nb =" + nb + " for file" + raf.getLocation());
      float[] data = new float[dataNPoints];
      for (int i = 0; i < dataNPoints; i++) {
        data[i] = staticMissingValue;  // LOOK ??
      }
      return data;
    } */
  }
private float[] getData40(RandomAccessFile raf, Grib2Drs.Type40 gdrs) throws IOException {
    // 6-xx  jpeg2000 data block to decode

    // dataPoints are number of points encoded, it could be less than the
    // totalNPoints in the grid record if bitMap is used, otherwise equal
    //int dataPoints = drs.getDataPoints();

    int nb = gdrs.numberOfBits;
    int D = gdrs.decimalScaleFactor;
    float DD = (float) java.lang.Math.pow((double) 10, (double) D);
    float R = gdrs.referenceValue;
    int E = gdrs.binaryScaleFactor;
    float EE = (float) java.lang.Math.pow(2.0, (double) E);
    float ref_val = R / DD;

    Grib2JpegDecoder g2j = null;
    // try {
    if (nb != 0) {  // there's data to decode
      g2j = new Grib2JpegDecoder(nb, false);
      byte[] buf = new byte[dataLength - 5];
      raf.readFully(buf);
      g2j.decode(buf);
      gdrs.hasSignedProblem = g2j.hasSignedProblem();
    }

    float[] result = new float[totalNPoints];

    // no data to decode, set to reference value
    if (nb == 0) {
      for (int i = 0; i < dataNPoints; i++) {
        result[i] = ref_val;
      }
      return result;
    }

    int[] idata = g2j.getGdata();
    if (bitmap == null) { // must be one decoded value in idata for every expected data point
      if (idata.length != dataNPoints) {
        logger.debug("Number of points in the data record {} != {} expected from GDS", idata.length,
            dataNPoints);
        throw new IllegalStateException(
            "Number of points in the data record {} != expected from GDS");
      }

      for (int i = 0; i < dataNPoints; i++) {
        // Y * 10^D = R + (X1 + X2) * 2^E ; // regulation 92.9.4
        // Y = (R + ( 0 + X2) * EE)/DD ;
        result[i] = (R + idata[i] * EE) / DD;
      }
      return result;

    } else {  // use bitmap to skip missing values
      for (int i = 0, j = 0; i < totalNPoints; i++) {
        if (GribNumbers.testBitIsSet(bitmap[i / 8], i % 8)) {
          if (j >= idata.length) {
            logger.warn("HEY jj2000 data count %d < bitmask count %d, i=%d, totalNPoints=%d%n",
                    idata.length, j, i, totalNPoints);
            break;
          }
          int indata = idata[j];
          result[i] = (R + indata * EE) / DD;
          j++;
        } else {
          result[i] = staticMissingValue;
        }
      }
    }
    return result;

    /* } catch (NullPointerException npe) {

      logger.error("Grib2DataReader2.jpeg2000Unpacking: bit rate too small nb =" + nb + " for file" + raf.getLocation());
      float[] data = new float[dataNPoints];
      for (int i = 0; i < dataNPoints; i++) {
        data[i] = staticMissingValue;  // LOOK ??
      }
      return data;
    } */
  }
private float [ ] getData40 ( RandomAccessFile raf , Grib2Drs . Type40 gdrs ) throws IOException { // 6-xx  jpeg2000 data block to decode // dataPoints are number of points encoded, it could be less than the // totalNPoints in the grid record if bitMap is used, otherwise equal //int dataPoints = drs.getDataPoints(); int nb = gdrs . numberOfBits ; int D = gdrs . decimalScaleFactor ; float DD = ( float ) java . lang . Math . pow ( ( double ) 10 , ( double ) D ) ; float R = gdrs . referenceValue ; int E = gdrs . binaryScaleFactor ; float EE = ( float ) java . lang . Math . pow ( 2.0 , ( double ) E ) ; float ref_val = R / DD ; Grib2JpegDecoder g2j = null ; // try { if ( nb != 0 ) { // there's data to decode g2j = new Grib2JpegDecoder ( nb , false ) ; byte [ ] buf = new byte [ dataLength - 5 ] ; raf . readFully ( buf ) ; g2j . decode ( buf ) ; gdrs . hasSignedProblem = g2j . hasSignedProblem ( ) ; } float [ ] result = new float [ totalNPoints ] ; // no data to decode, set to reference value if ( nb == 0 ) { for ( int i = 0 ; i < dataNPoints ; i ++ ) { result [ i ] = ref_val ; } return result ; } int [ ] idata = g2j . getGdata ( ) ; if ( bitmap == null ) { // must be one decoded value in idata for every expected data point if ( idata . length != dataNPoints ) { logger . debug ( "Number of points in the data record {} != {} expected from GDS" , idata . length , dataNPoints ) ; throw new IllegalStateException ( "Number of points in the data record {} != expected from GDS" ) ; } for ( int i = 0 ; i < dataNPoints ; i ++ ) { // Y * 10^D = R + (X1 + X2) * 2^E ; // regulation 92.9.4 // Y = (R + ( 0 + X2) * EE)/DD ; result [ i ] = ( R + idata [ i ] * EE ) / DD ; } return result ; } else { // use bitmap to skip missing values for ( int i = 0 , j = 0 ; i < totalNPoints ; i ++ ) { if ( GribNumbers . testBitIsSet ( bitmap [ i / 8 ] , i % 8 ) ) { if ( j >= idata . length ) { logger . warn ( "HEY jj2000 data count %d < bitmask count %d, i=%d, totalNPoints=%d%n" , idata . length , j , i , totalNPoints ) ; break ; } int indata = idata [ j ] ; result [ i ] = ( R + indata * EE ) / DD ; j ++ ; } else { result [ i ] = staticMissingValue ; } } } return result ; /* } catch (NullPointerException npe) {

      logger.error("Grib2DataReader2.jpeg2000Unpacking: bit rate too small nb =" + nb + " for file" + raf.getLocation());
      float[] data = new float[dataNPoints];
      for (int i = 0; i < dataNPoints; i++) {
        data[i] = staticMissingValue;  // LOOK ??
      }
      return data;
    } */ }
Grid point data - JPEG 2000 code stream format
Grid point data - JPEG 2000 code stream format