private float [ ] getData41 ( RandomAccessFile raf , Grib2Drs . Type0 gdrs ) throws IOException { 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 ) ; // LOOK: can # datapoints differ from bitmap and data ? // dataPoints are number of points encoded, it could be less than the // totalNPoints in the grid record if bitMap is used, otherwise equal float [ ] data = new float [ totalNPoints ] ; // no data to decode, set to reference value if ( nb == 0 ) { Arrays . fill ( data , R ) ; return data ; } // Y * 10**D = R + (X1 + X2) * 2**E // E = binary scale factor // D = decimal scale factor // R = reference value // X1 = 0 // X2 = scaled encoded value // data[ i ] = (R + ( X1 + X2) * EE)/DD ; byte [ ] buf = new byte [ dataLength - 5 ] ; raf . readFully ( buf ) ; InputStream in = new ByteArrayInputStream ( buf ) ; BufferedImage image = ImageIO . read ( in ) ; if ( nb != image . getColorModel ( ) . getPixelSize ( ) ) { logger . debug ( "PNG pixel size disagrees with grib number of bits: " , image . getColorModel ( ) . getPixelSize ( ) , nb ) ; } DataBuffer db = image . getRaster ( ) . getDataBuffer ( ) ; if ( bitmap == null ) { for ( int i = 0 ; i < dataNPoints ; i ++ ) { data [ i ] = ( R + db . getElem ( i ) * EE ) / DD ; } } else { for ( int bitPt = 0 , dataPt = 0 ; bitPt < totalNPoints ; bitPt ++ ) { if ( GribNumbers . testBitIsSet ( bitmap [ bitPt / 8 ] , bitPt % 8 ) ) { data [ bitPt ] = ( R + db . getElem ( dataPt ++ ) * EE ) / DD ; } else { data [ bitPt ] = staticMissingValue ; } } } return data ; }
Code taken from esupport ticket ZVT - 415274