grib/src/main/java/ucar/nc2/grib/grib2/Grib2DataReader.java
@Nullable
  private int[] getData40raw(RandomAccessFile raf, Grib2Drs.Type40 gdrs) throws IOException {
    int nb = gdrs.numberOfBits;
    if (nb == 0) {
      return null;
    }
    int missing_value = (2 << nb - 1) - 1;       // all ones - reserved for missing value

    Grib2JpegDecoder g2j;
    g2j = new Grib2JpegDecoder(nb, false);
    byte[] buf = new byte[dataLength - 5];
    raf.readFully(buf);
    g2j.decode(buf);
    gdrs.hasSignedProblem = g2j.hasSignedProblem();

    int[] idata = g2j.getGdata();

    if (bitmap == null) { // must be one decoded value in idata for every expected data point
      if (idata.length != totalNPoints) {
        logger.debug("Number of points in the data record {} != {} expected from GDS", idata.length,
            totalNPoints);
        return null;
      }
      return idata;

    } else {  // use bitmap to skip missing values
      int[] result = new int[totalNPoints];

      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;
          }
          result[i] = idata[j];
          j++;
        } else {
          result[i] = missing_value;
        }
      }
      return result;
    }

  }
@Nullable
  private int[] getData40raw(RandomAccessFile raf, Grib2Drs.Type40 gdrs) throws IOException {
    int nb = gdrs.numberOfBits;
    if (nb == 0) {
      return null;
    }
    int missing_value = (2 << nb - 1) - 1;       // all ones - reserved for missing value

    Grib2JpegDecoder g2j;
    g2j = new Grib2JpegDecoder(nb, false);
    byte[] buf = new byte[dataLength - 5];
    raf.readFully(buf);
    g2j.decode(buf);
    gdrs.hasSignedProblem = g2j.hasSignedProblem();

    int[] idata = g2j.getGdata();

    if (bitmap == null) { // must be one decoded value in idata for every expected data point
      if (idata.length != totalNPoints) {
        logger.debug("Number of points in the data record {} != {} expected from GDS", idata.length,
            totalNPoints);
        return null;
      }
      return idata;

    } else {  // use bitmap to skip missing values
      int[] result = new int[totalNPoints];

      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;
          }
          result[i] = idata[j];
          j++;
        } else {
          result[i] = missing_value;
        }
      }
      return result;
    }

  }
@ Nullable private int [ ] getData40raw ( RandomAccessFile raf , Grib2Drs . Type40 gdrs ) throws IOException { int nb = gdrs . numberOfBits ; if ( nb == 0 ) { return null ; } int missing_value = ( 2 << nb - 1 ) - 1 ; // all ones - reserved for missing value Grib2JpegDecoder g2j ; g2j = new Grib2JpegDecoder ( nb , false ) ; byte [ ] buf = new byte [ dataLength - 5 ] ; raf . readFully ( buf ) ; g2j . decode ( buf ) ; gdrs . hasSignedProblem = g2j . hasSignedProblem ( ) ; int [ ] idata = g2j . getGdata ( ) ; if ( bitmap == null ) { // must be one decoded value in idata for every expected data point if ( idata . length != totalNPoints ) { logger . debug ( "Number of points in the data record {} != {} expected from GDS" , idata . length , totalNPoints ) ; return null ; } return idata ; } else { // use bitmap to skip missing values int [ ] result = new int [ totalNPoints ] ; 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 ; } result [ i ] = idata [ j ] ; j ++ ; } else { result [ i ] = missing_value ; } } return result ; } }
Grid point data - JPEG 2000 code stream format
Grid point data - JPEG 2000 code stream format