diff --git a/src/grib_value.cc b/src/grib_value.cc index 0f07e69dc..978bbad9b 100644 --- a/src/grib_value.cc +++ b/src/grib_value.cc @@ -416,10 +416,22 @@ static int preprocess_packingType_change(grib_handle* h, const char* keyname, co size_t len = sizeof(input_packing_type); if (grib_inline_strcmp(keyname, "packingType") == 0) { + if (strcmp(keyval, "grid_ccsds")==0) { + // packingType being changed to CCSDS + long isGridded = -1; //?? + if ((err = grib_get_long(h, "isGridded", &isGridded)) == GRIB_SUCCESS && isGridded == 0) { + if (h->context->debug) { + fprintf(stderr, "ECCODES DEBUG grib_set_string packingType: " + "CCSDS packing does not apply to spectral fields. Packing not changed\n"); + } + return 1; /* Dealt with - no further action needed */ + } + } /* Second order doesn't have a proper representation for constant fields. So best not to do the change of packing type. Use strncmp to catch all flavours of 2nd order packing e.g. grid_second_order_boustrophedonic */ if (strncmp(keyval, "grid_second_order", 17) == 0) { + // packingType being changed to grid_second_order long bitsPerValue = 0; size_t numCodedVals = 0; err = grib_get_long(h, "bitsPerValue", &bitsPerValue); diff --git a/tests/grib_ccsds.sh b/tests/grib_ccsds.sh index 13533ab90..6568682ff 100755 --- a/tests/grib_ccsds.sh +++ b/tests/grib_ccsds.sh @@ -200,5 +200,13 @@ if [ $HAVE_JPEG -eq 1 ]; then ${tools_dir}/grib_compare -c data:n $outfile1 $outfile2 fi +# ECC-2021: CCSDS packing should not be applied to spectral fields +infile=$ECCODES_SAMPLES_PATH/sh_ml_grib2.tmpl +grib_check_key_equals $infile isSpectral,isGridded '1 0' +ECCODES_DEBUG=-1 ${tools_dir}/grib_set -s packingType=grid_ccsds $infile $outfile1 >$logfile 2>&1 +${tools_dir}/grib_compare $infile $outfile1 +grep -q "CCSDS packing does not apply to spectral fields" $logfile + + # Clean up rm -f $outfile1 $outfile2 $logfile