ECC-1800: GRIB2: Failure setting stepUnits=s,paramId=210203

This commit is contained in:
shahramn 2024-04-16 11:36:39 +01:00
parent cc40569e21
commit eb8bdcf87e
2 changed files with 43 additions and 8 deletions

View File

@ -115,6 +115,16 @@ int grib_accessor_class_g2step_range_t::pack_string(grib_accessor* a, const char
if ((ret = grib_get_long_internal(h, "forceStepUnits", &force_step_units)) != GRIB_SUCCESS)
return ret;
// Note:
// forceStepUnits is a special key that is used to identify the origin of the defined units
// i.e., whether they have been defined by the user.
// If this key is defined (!= 255), it indicates that the stepUnits have been defined by the user.
// Once this key is set, it has the highest priority: it automatically overrides certain units and the default value in stepUnits
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<eccodes::Step> steps = parse_range(val, eccodes::Unit{force_step_units});
if (steps.size() == 0) {

View File

@ -13,6 +13,14 @@
# See JIRA issues ECC-1620, ECC-1238
# -----------------------------------
label="grib_sub_hourly"
temp=temp.1.$label
temp2=temp.2.$label
tempFilt=temp.$label.filt
tempText=temp.$label.txt
sample_g2=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
grib_expect_failure()
{
a_file=$1
@ -51,14 +59,6 @@ if (set -u; : ${ECCODES_GRIB_HOURLY_STEPS_WITH_UNITS?}) 2> /dev/null; then
fi
label="grib_sub_hourly"
temp=temp.1.$label
temp2=temp.2.$label
tempFilt=temp.$label.filt
tempText=temp.$label.txt
sample_g2=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
instantaneous_field=$data_dir/reduced_gaussian_surface.grib2
accumulated_field=$data_dir/reduced_gaussian_sub_area.grib2
@ -542,5 +542,30 @@ 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=m,productDefinitionTemplateNumber=40 $sample_g2 $temp
grib_check_key_equals $temp '-p indicatorOfUnitOfTimeRange,stepUnits:s,productDefinitionTemplateNumber' '0 m 40'
${tools_dir}/grib_set -s stepUnits=m,step=6,productDefinitionTemplateNumber=40 $sample_g2 $temp
grib_check_key_equals $temp '-p indicatorOfUnitOfTimeRange,stepUnits:s,forecastTime' '0 m 6'
${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