Skip to content

Commit

Permalink
ECC-2021: GRIB2: CCSDS packing should not be applied to spectral fields
Browse files Browse the repository at this point in the history
  • Loading branch information
shahramn committed Feb 6, 2025
1 parent 9bba27d commit a7abad5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/grib_value.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions tests/grib_ccsds.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a7abad5

Please sign in to comment.