diff --git a/data/grib_data_files.txt b/data/grib_data_files.txt index f6d3a9124..8996acf97 100644 --- a/data/grib_data_files.txt +++ b/data/grib_data_files.txt @@ -91,4 +91,4 @@ mercator.grib2 run_length_packing.grib2 boustrophedonic.grib1 reduced_gaussian_sub_area.legacy.grib1 - +grid_complex_spatial_differencing.grib2 diff --git a/src/accessor/grib_accessor_class_data_g22order_packing.cc b/src/accessor/grib_accessor_class_data_g22order_packing.cc index bbc698100..0fefbc6de 100644 --- a/src/accessor/grib_accessor_class_data_g22order_packing.cc +++ b/src/accessor/grib_accessor_class_data_g22order_packing.cc @@ -787,7 +787,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, optimize_scale_factor, typeOfOriginalFieldValues; + long binary_scale_factor, decimal_scale_factor, typeOfOriginalFieldValues; // long groupSplittingMethodUsed, numberOfGroupsOfDataValues, referenceForGroupWidths; long missingValueManagementUsed, primaryMissingValueSubstitute, secondaryMissingValueSubstitute; long numberOfBitsUsedForTheGroupWidths, numberOfBitsUsedForTheScaledGroupLengths, orderOfSpatialDifferencing; @@ -816,7 +816,7 @@ 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; - optimize_scale_factor = 1; // TODO(masn): To be reviewed + int use_scale = 1; if ((err = grib_get_long_internal(gh, self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS) return err; @@ -939,7 +939,7 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c binary_scale = bin_scale; - if (optimize_scale_factor == 0) { // ECMWF style + if (use_scale) { // ECMWF style ref = min_val; frange = max_val - ref; dec_scale = 0; diff --git a/tests/grib_bitmap.sh b/tests/grib_bitmap.sh index 456f3255e..9ef78550d 100755 --- a/tests/grib_bitmap.sh +++ b/tests/grib_bitmap.sh @@ -1,4 +1,4 @@ -#!/bin/sh +n#!/bin/sh # (C) Copyright 2005- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 @@ -122,7 +122,9 @@ stats=`${tools_dir}/grib_get -F%.2f -p max,min,avg $tempSimple` # Repack ${tools_dir}/grib_copy -r $infile $temp2 -${tools_dir}/grib_compare -c data:n $infile $temp2 +# The values do not have to be be bit-identical. The high effort to make them bit-identical is not justified. +# Therefore, we compare the values with a relative tolerance. +${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 @@ -165,5 +167,88 @@ ${tools_dir}/grib_filter $tempRules $data_dir/boustrophedonic.grib1 > $REDIRECT ${tools_dir}/grib_filter $tempRules $data_dir/missing_field.grib1 > $REDIRECT ${tools_dir}/grib_filter $tempRules $data_dir/reduced_latlon_surface.grib2 > $REDIRECT +# ECC-1858: grid_complex_spatial_differencing +# Optimize binary_scale_factor, decimal_scale_factor by default +# ---------------------------------------------------------- +# Repack + +in=${data_dir}/grid_complex_spatial_differencing.grib2 +in_with_bitmap=${data_dir}/temp_grid_complex_spatial_differencing_bitmap.grib2 +in_no_bitmap=${data_dir}/temp_grid_complex_spatial_differencing_no_bitmap.grib2 + +${tools_dir}/grib_set -s bitmapPresent=1 $in $in_with_bitmap +${tools_dir}/grib_set -s bitmapPresent=0 $in $in_no_bitmap + +# No bitmap +# Repack +${tools_dir}/grib_copy -r $in_no_bitmap $temp2 +stats=`${tools_dir}/grib_get -F%.2f -p max,min,avg $temp2` +[ "$stats" = '549.61 11.61 203.28' ] + +# Rescale +${tools_dir}/grib_set -s scaleValuesBy=0.001 $in_no_bitmap $temp2 +stats=`${tools_dir}/grib_get -F%.4f -p max,min,avg $temp2` +[ "$stats" = '0.5496 0.0116 0.2033' ] + +# BitsPerValue=16 +# If required bits and wanted bits are not the same, use an extra bit (see code) +${tools_dir}/grib_set -s setBitsPerValue=15 $in_no_bitmap $temp2 +stats=`${tools_dir}/grib_get -F%.2f -p max,min,avg $temp2` +[ "$stats" = '549.61 11.61 203.28' ] +grib_check_key_equals $temp2 bitsPerValue 16 + +# BitsPerValue=24 (see comment above) +${tools_dir}/grib_set -s setBitsPerValue=23 $in_no_bitmap $temp2 +stats=`${tools_dir}/grib_get -F%.2f -p max,min,avg $temp2` +[ "$stats" = '549.61 11.61 203.28' ] +grib_check_key_equals $temp2 bitsPerValue 24 + +# Change packing type +${tools_dir}/grib_set -s packingType=grid_simple $in_no_bitmap $temp2 +stats=`${tools_dir}/grib_get -F%.2f -p max,min,avg $temp2` +[ "$stats" = '549.61 11.61 203.28' ] + +${tools_dir}/grib_set -s packingType=grid_complex_spatial_differencing $temp2 $tempSimple +stats=`${tools_dir}/grib_get -F%.2f -p max,min,avg $temp2` +[ "$stats" = '549.61 11.61 203.28' ] + +# With bitmap +# Repack +${tools_dir}/grib_copy -r $in_with_bitmap $temp2 +stats=`${tools_dir}/grib_get -F%.2f -p max,min,avg $temp2` +[ "$stats" = '549.61 11.61 203.28' ] + +# Rescale +${tools_dir}/grib_set -s scaleValuesBy=0.001 $in_with_bitmap $temp2 +stats=`${tools_dir}/grib_get -F%.4f -p max,min,avg $temp2` +[ "$stats" = '0.5496 0.0116 0.2033' ] + +# BitsPerValue=16 (see comment above) +${tools_dir}/grib_set -s setBitsPerValue=15 $in_with_bitmap $temp2 +stats=`${tools_dir}/grib_get -F%.2f -p max,min,avg $temp2` +[ "$stats" = '549.61 11.61 203.28' ] +grib_check_key_equals $temp2 bitsPerValue 16 + +# BitsPerValue=24 (see comment above) +${tools_dir}/grib_set -s setBitsPerValue=23 $in_with_bitmap $temp2 +stats=`${tools_dir}/grib_get -F%.2f -p max,min,avg $temp2` +[ "$stats" = '549.61 11.61 203.28' ] +grib_check_key_equals $temp2 bitsPerValue 24 + +# Change packing type +${tools_dir}/grib_set -s packingType=grid_simple $in_with_bitmap $temp2 +stats=`${tools_dir}/grib_get -F%.2f -p max,min,avg $temp2` +[ "$stats" = '549.61 11.61 203.28' ] + +${tools_dir}/grib_set -s packingType=grid_complex_spatial_differencing $temp2 $tempSimple +stats=`${tools_dir}/grib_get -F%.2f -p max,min,avg $temp2` +[ "$stats" = '549.61 11.61 203.28' ] + +# Clean up for ECC-1858 +rm -f $in_with_bitmap $in_no_bitmap +rm -f $tempSimple + +# ---------------------------------------------------------- + # Clean up rm -f $tempData1 $tempData2 $temp1 $temp2 $tempRules $tempOut