grib/src/main/java/ucar/nc2/grib/grib2/Grib2DataReader.java
private float[] nGroups0(int bitmap_flag, float ref, float mv1) {
    float[] data = new float[totalNPoints];
    if (bitmap_flag == 255) {
      for (int i = 0; i < totalNPoints; i++) {
        data[i] = ref;
      }

    } else if (bitmap_flag == 0 || bitmap_flag == 254) {
      int mask = 0;
      int mask_pointer = 0;
      for (int i = 0; i < totalNPoints; i++) {
        if ((i & 7) == 0) {
          mask = bitmap[mask_pointer];
          mask_pointer++;
        }
        data[i] = ((mask & 128) == 0) ? ref : mv1;
        mask <<= 1;
      }

    } else {
      throw new IllegalArgumentException("unknown bitmap type =" + bitmap_flag);
    }
    return data;
  }
private float[] nGroups0(int bitmap_flag, float ref, float mv1) {
    float[] data = new float[totalNPoints];
    if (bitmap_flag == 255) {
      for (int i = 0; i < totalNPoints; i++) {
        data[i] = ref;
      }

    } else if (bitmap_flag == 0 || bitmap_flag == 254) {
      int mask = 0;
      int mask_pointer = 0;
      for (int i = 0; i < totalNPoints; i++) {
        if ((i & 7) == 0) {
          mask = bitmap[mask_pointer];
          mask_pointer++;
        }
        data[i] = ((mask & 128) == 0) ? ref : mv1;
        mask <<= 1;
      }

    } else {
      throw new IllegalArgumentException("unknown bitmap type =" + bitmap_flag);
    }
    return data;
  }
/* from wgrib unpk_complex():

p = sec[5];                               // drs
ref_val = ieee2flt(p+11);                 // R
factor_2 = Int_Power(2.0, int2(p+15));    // 2^E
factor_10 = Int_Power(10.0, -int2(p+17)); // 10^-D
ref_val *= factor_10;                     // R/10^D
factor = factor_2 * factor_10;            // 2^E*10^-D
nbits = p[19];                            // NB
ngroups = uint4(p+31);                    // NG
bitmap_flag = code_table_6_0(sec);        // bitmap->indicator
ctable_5_6 = code_table_5_6(sec);

bitmap_flag = code_table_6_0(sec); // == gr.getBitmapSection().getBitMapIndicator();
if (ngroups == 0) {
if (bitmap_flag == 255) {
for (i = 0; i < ndata; i++) data[i] = ref_val;
return 0;
}
if (bitmap_flag == 0 || bitmap_flag == 254) {
mask_pointer = sec[6] + 6;                              // probably bitmask is here ??
mask = 0;
for (i = 0; i < ndata; i++) {
if ((i & 7) == 0) mask = *mask_pointer++;           // get next byte ??
data[i] = (mask & 128) ?  ref_val : UNDEFINED;      // bit 7 set
mask <<= 1;                                         // shift
}
return 0;
}
fatal_error("unknown bitmap", "");
}