From f9994ecb70981bab588f26754ccce458e0e49988 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Tue, 11 Apr 2023 15:52:30 +0100 Subject: [PATCH] ECC-793: Provide mechanism to reject EXPERIMENTAL parameters --- src/grib_util.cc | 22 +++++++++++++++++----- tests/grib_data_quality_checks.sh | 17 +++++++++++++++-- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/grib_util.cc b/src/grib_util.cc index dc3bc8cb7..ec14ba8d6 100644 --- a/src/grib_util.cc +++ b/src/grib_util.cc @@ -2142,8 +2142,11 @@ int grib_util_grib_data_quality_check(grib_handle* h, double min_val, double max bool is_error = true; char description[1024] = {0,}; char step[32] = "unknown"; - char shortName[32] = {0,}; - size_t len = 32; + char shortName[64] = {0,}; + char name[526] = {0,}; + size_t len = 0; + const char* invalid_shortName = "unknown"; + const char* invalid_name = "Experimental product"; // If grib_data_quality_checks == 1, limits failure results in an error // If grib_data_quality_checks == 2, limits failure results in a warning @@ -2151,10 +2154,19 @@ int grib_util_grib_data_quality_check(grib_handle* h, double min_val, double max Assert(ctx->grib_data_quality_checks == 1 || ctx->grib_data_quality_checks == 2); is_error = (ctx->grib_data_quality_checks == 1); + len = sizeof(shortName); err = grib_get_string(h, "shortName", shortName, &len); - if (err || STR_EQUAL(shortName, "unknown")) { - fprintf(stderr, "ECCODES %s : Invalid metadata: shortName=unknown\n", - (is_error ? "ERROR" : "WARNING")); + if (err || STR_EQUAL(shortName, invalid_shortName)) { + fprintf(stderr, "ECCODES %s : Invalid metadata: shortName='%s'\n", + (is_error ? "ERROR" : "WARNING"), invalid_shortName); + if (is_error) return GRIB_INVALID_MESSAGE; + } + + len = sizeof(name); + err = grib_get_string(h, "name", name, &len); + if (err || STR_EQUAL(name, invalid_name)) { + fprintf(stderr, "ECCODES %s : Invalid metadata: name='%s'\n", + (is_error ? "ERROR" : "WARNING"), invalid_name); if (is_error) return GRIB_INVALID_MESSAGE; } diff --git a/tests/grib_data_quality_checks.sh b/tests/grib_data_quality_checks.sh index 4123a2785..81657d24b 100755 --- a/tests/grib_data_quality_checks.sh +++ b/tests/grib_data_quality_checks.sh @@ -209,7 +209,8 @@ if [ $HAVE_AEC -eq 1 ]; then [ $status -ne 0 ] fi -# Invalid shortName +# Invalid shortName/name +# ------------------------- export ECCODES_GRIB_DATA_QUALITY_CHECKS=1 input2=${data_dir}/reduced_gaussian_surface.grib2 ${tools_dir}/grib_set -s discipline=254 $input2 $tempOut @@ -219,7 +220,19 @@ ${tools_dir}/grib_set -s scaleValuesBy=2 $tempOut $tempGrib2 2>$tempErr status=$? set -e [ $status -ne 0 ] -grep -q "Invalid metadata: shortName=unknown" $tempErr +grep -q "Invalid metadata: shortName='unknown'" $tempErr + +# Invalid name (ECC-793) +${tools_dir}/grib_set -s paramId=129080 $input2 $tempOut 2>$tempErr +grib_check_key_equals $tempOut 'name' 'Experimental product' +# Repacking causes the values to be set +set +e +${tools_dir}/grib_set -r -s paramId=129080 $input2 $tempOut 2>$tempErr +status=$? +set -e +[ $status -ne 0 ] +grep -q "Invalid metadata: name='Experimental product'" $tempErr + # Clean up rm -rf $tempDir