From 8c28b0fcc59abecaec7120fb38164aadd987f8a9 Mon Sep 17 00:00:00 2001 From: shahramn Date: Fri, 12 Apr 2024 11:33:00 +0100 Subject: [PATCH] ECC-1800: GRIB2: Failure setting stepUnits=s,paramId=210203 --- src/grib_accessor_class_g2step_range.cc | 4 ++++ tests/grib_sub_hourly.sh | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/grib_accessor_class_g2step_range.cc b/src/grib_accessor_class_g2step_range.cc index c39601a40..3800a4342 100644 --- a/src/grib_accessor_class_g2step_range.cc +++ b/src/grib_accessor_class_g2step_range.cc @@ -211,6 +211,10 @@ static int pack_string(grib_accessor* a, const char* val, size_t* len) if ((ret = grib_get_long_internal(h, "forceStepUnits", &force_step_units)) != GRIB_SUCCESS) return ret; + if (h->loader) { // h->loader is set only when rebuilding or reparsing + force_step_units = 255; // See ECC-1768 and ECC-1800 + } + try { std::vector steps = parse_range(val, eccodes::Unit{force_step_units}); if (steps.size() == 0) { diff --git a/tests/grib_sub_hourly.sh b/tests/grib_sub_hourly.sh index fdd174c28..eb1405111 100755 --- a/tests/grib_sub_hourly.sh +++ b/tests/grib_sub_hourly.sh @@ -542,5 +542,24 @@ set -e [ $status -ne 0 ] grep -q "Invalid unit" $tempText + +# ECC-1800: Set stepUnits before paramIds, which cause changes in the PTDN +${tools_dir}/grib_set -s stepUnits=s,paramId=210203 $sample_g2 $temp # is_chemical +grib_check_key_equals $temp '-p indicatorOfUnitOfTimeRange,stepUnits:s,productDefinitionTemplateNumber' '13 s 40' + +${tools_dir}/grib_set -s stepUnits=s,paramId=131060 $sample_g2 $temp # probability forecasts +grib_check_key_equals $temp '-p indicatorOfUnitOfTimeRange,stepUnits:s,productDefinitionTemplateNumber' '13 s 9' + +${tools_dir}/grib_set -s stepUnits=s,paramId=210073 $sample_g2 $temp # is_aerosol +grib_check_key_equals $temp '-p indicatorOfUnitOfTimeRange,stepUnits:s,productDefinitionTemplateNumber' '13 s 48' + +${tools_dir}/grib_set -s stepUnits=s,paramId=210170 $sample_g2 $temp # is_chemical_srcsink +grib_check_key_equals $temp '-p indicatorOfUnitOfTimeRange,stepUnits:s,productDefinitionTemplateNumber' '13 s 76' + +# Add a case with filter too +echo "set stepUnits='s'; set paramId=210203; write;" | ${tools_dir}/grib_filter -o $temp - $sample_g2 +grib_check_key_equals $temp '-p indicatorOfUnitOfTimeRange,stepUnits:s,productDefinitionTemplateNumber' '13 s 40' + + # Clean up rm -f $temp $temp2 $tempFilt $tempText