nl_tokens: / * http : // www . unidata . ucar . edu / software / netcdf / docs / BestPractices . html Packed Data Values
pl_tokens: private void doCopyCompress ( Formatter f , ucar . nc2 . grib . grib2 . Grib2Record gr , RandomAccessFile raf , OutputStream out , Counters counters ) throws IOException { float [ ] data = gr . readData ( raf ) ; Grib2SectionDataRepresentation drss = gr . getDataRepresentationSection ( ) ; drss . getDrs ( raf ) ; // calc scale/offset GribData . Info info = gr . getBinaryDataInfo ( raf ) ; int nbits = info . numberOfBits ; counters . count ( "Nbits" , nbits ) ; int width = ( 2 << ( nbits - 1 ) ) - 1 ; //f.format(" nbits = %d%n", nbits); //f.format(" width = %d (0x%s) %n", width2, Long.toHexString(width2)); float dataMin = Float . MAX_VALUE ; float dataMax = - Float . MAX_VALUE ; for ( float fd : data ) { dataMin = Math . <mask> ( dataMin , fd ) ; dataMax = Math . max ( dataMax , fd ) ; } //f.format(" dataMin = %f%n", dataMin); //f.format(" dataMax = %f%n", dataMax); // f.format(" range = %f%n", (dataMax - dataMin)); // scale_factor =(dataMax - dataMin) / (2^n - 1) // add_offset = dataMin + 2^(n-1) * scale_factor //float scale_factor = (dataMax - dataMin) / width2; //float add_offset = dataMin + width2 * scale_factor / 2; float scale_factor = ( dataMax - dataMin ) / ( width - 2 ) ; float add_offset = dataMin - scale_factor ; //f.format(" scale_factor = %f%n", scale_factor); //f.format(" add_offset = %f%n", add_offset); // unpacked_data_value = packed_data_value * scale_factor + add_offset // packed_data_value = nint((unpacked_data_value - add_offset) / scale_factor) /* compressedSize = out.size();
        f.format(" compressedSize = %d%n", compressedSize);
        f.format(" compressedRatio = %f%n", (float) compressedSize / (n*nbits/8));
        f.format(" ratio with grib = %f%n", (float) compressedSize / bean1.getDataLength());  */ }