diff --git a/src/accessor/grib_accessor_class_data_g22order_packing.cc b/src/accessor/grib_accessor_class_data_g22order_packing.cc index aefef16c8..c4949e89e 100644 --- a/src/accessor/grib_accessor_class_data_g22order_packing.cc +++ b/src/accessor/grib_accessor_class_data_g22order_packing.cc @@ -786,7 +786,7 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c // long nvals_per_group = 0; // long nbits_per_group_val = 0; - long binary_scale_factor, decimal_scale_factor, typeOfOriginalFieldValues; + long binary_scale_factor, decimal_scale_factor, typeOfOriginalFieldValues, optimize_scale_factor; // long groupSplittingMethodUsed, numberOfGroupsOfDataValues, referenceForGroupWidths; long missingValueManagementUsed, primaryMissingValueSubstitute, secondaryMissingValueSubstitute; long numberOfBitsUsedForTheGroupWidths, numberOfBitsUsedForTheScaledGroupLengths, orderOfSpatialDifferencing; @@ -815,7 +815,10 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c if ((err = grib_get_long_internal(gh, self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) return err; - int use_scale = 1; + if ((err = grib_get_long_internal(gh, self->optimize_scale_factor, &optimize_scale_factor)) != GRIB_SUCCESS) + return err; + + int use_scale = !optimize_scale_factor; if ((err = grib_get_long_internal(gh, self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS) return err; diff --git a/tests/grib_bitmap.sh b/tests/grib_bitmap.sh index 36ba2cf4d..e78ccc897 100755 --- a/tests/grib_bitmap.sh +++ b/tests/grib_bitmap.sh @@ -127,6 +127,8 @@ ${tools_dir}/grib_copy -r $infile $temp2 ${tools_dir}/grib_compare -R all=0.3 -c data:n $infile $temp2 grib_check_key_equals $temp2 bitsPerValue 9 # Note: The input file has bpv=9 +${tools_dir}/grib_set -rs optimizeScaleFactor=1 $infile $temp2 +${tools_dir}/grib_compare $infile $temp2 # Simple to grid_complex tempComplex=temp.grib_bitmap.complex.grib