Skip to content

Commit 736ed92

Browse files
committed
ECC-2021: GRIB2: CCSDS packing should not be applied to spectral fields
1 parent 312f8b7 commit 736ed92

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/grib_value.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,10 +416,22 @@ static int preprocess_packingType_change(grib_handle* h, const char* keyname, co
416416
size_t len = sizeof(input_packing_type);
417417

418418
if (grib_inline_strcmp(keyname, "packingType") == 0) {
419+
if (strcmp(keyval, "grid_ccsds")==0) {
420+
// packingType being changed to CCSDS
421+
long isGridded = -1; //??
422+
if ((err = grib_get_long(h, "isGridded", &isGridded)) == GRIB_SUCCESS && isGridded == 0) {
423+
if (h->context->debug) {
424+
fprintf(stderr, "ECCODES DEBUG grib_set_string packingType: "
425+
"CCSDS packing does not apply to spectral fields. Packing not changed\n");
426+
}
427+
return 1; /* Dealt with - no further action needed */
428+
}
429+
}
419430
/* Second order doesn't have a proper representation for constant fields.
420431
So best not to do the change of packing type.
421432
Use strncmp to catch all flavours of 2nd order packing e.g. grid_second_order_boustrophedonic */
422433
if (strncmp(keyval, "grid_second_order", 17) == 0) {
434+
// packingType being changed to grid_second_order
423435
long bitsPerValue = 0;
424436
size_t numCodedVals = 0;
425437
err = grib_get_long(h, "bitsPerValue", &bitsPerValue);

tests/grib_ccsds.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,5 +200,13 @@ if [ $HAVE_JPEG -eq 1 ]; then
200200
${tools_dir}/grib_compare -c data:n $outfile1 $outfile2
201201
fi
202202

203+
# ECC-2021: CCSDS packing should not be applied to spectral fields
204+
infile=$ECCODES_SAMPLES_PATH/sh_ml_grib2.tmpl
205+
grib_check_key_equals $infile isSpectral,isGridded '1 0'
206+
ECCODES_DEBUG=-1 ${tools_dir}/grib_set -s packingType=grid_ccsds $infile $outfile1 >$logfile 2>&1
207+
${tools_dir}/grib_compare $infile $outfile1
208+
grep -q "CCSDS packing does not apply to spectral fields" $logfile
209+
210+
203211
# Clean up
204212
rm -f $outfile1 $outfile2 $logfile

0 commit comments

Comments
 (0)