From fe5a4b168c348060940d6f488b2d0321237874ea Mon Sep 17 00:00:00 2001 From: shahramn Date: Sat, 3 Aug 2024 14:44:40 +0100 Subject: [PATCH] ECC-1897: GRIB2: Print a warning if the packing type template is experimental or deprecated --- src/grib_value.cc | 30 ++++++++++++++++++++++-------- tests/grib_change_packing.sh | 8 +++++++- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/grib_value.cc b/src/grib_value.cc index f89cb9725..e68ea72e0 100644 --- a/src/grib_value.cc +++ b/src/grib_value.cc @@ -410,7 +410,7 @@ int grib_set_string_internal(grib_handle* h, const char* name, /* Return 1 if we dealt with specific packing type changes and nothing more needs doing. * Return 0 if further action is needed */ -static int process_packingType_change(grib_handle* h, const char* keyname, const char* keyval) +static int preprocess_packingType_change(grib_handle* h, const char* keyname, const char* keyval) { int err = 0; char input_packing_type[100] = {0,}; @@ -456,24 +456,37 @@ static int process_packingType_change(grib_handle* h, const char* keyname, const if (strcmp(input_packing_type, "grid_ieee") == 0) { const long max_bpv = 32; /* Cannot do any higher */ grib_set_long(h, "bitsPerValue", max_bpv); - /* - long accuracy = 0; - err = grib_get_long(h, "accuracy", &accuracy); - if (!err) { - grib_set_long(h, "bitsPerValue", accuracy); - } */ + //long accuracy = 0; + //err = grib_get_long(h, "accuracy", &accuracy); + //if (!err) grib_set_long(h, "bitsPerValue", accuracy); } } } return 0; /* Further action is needed */ } +static void postprocess_packingType_change(grib_handle* h, const char* keyname, const char* keyval) +{ + if (grib_inline_strcmp(keyname, "packingType") == 0) { + long is_experimental = 0, is_deprecated = 0; + if (grib_get_long(h, "isTemplateExperimental", &is_experimental) == GRIB_SUCCESS && is_experimental == 1) { + fprintf(stderr, "ECCODES WARNING : The template for %s=%s is experimental. " + "This template was not validated at the time of publication.\n", + keyname, keyval); + return; + } + if (grib_get_long(h, "isTemplateDeprecated", &is_deprecated) == GRIB_SUCCESS && is_deprecated == 1) { + fprintf(stderr, "ECCODES WARNING : The template for %s=%s is deprecated.\n", keyname, keyval); + } + } +} + int grib_set_string(grib_handle* h, const char* name, const char* val, size_t* length) { int ret = 0; grib_accessor* a = NULL; - int processed = process_packingType_change(h, name, val); + int processed = preprocess_packingType_change(h, name, val); if (processed) return GRIB_SUCCESS; /* Dealt with - no further action needed */ @@ -492,6 +505,7 @@ int grib_set_string(grib_handle* h, const char* name, const char* val, size_t* l ret = a->pack_string(val, length); if (ret == GRIB_SUCCESS) { + postprocess_packingType_change(h, name, val); return grib_dependency_notify_change(a); } return ret; diff --git a/tests/grib_change_packing.sh b/tests/grib_change_packing.sh index 2b4d8ebf5..e9aa4743a 100755 --- a/tests/grib_change_packing.sh +++ b/tests/grib_change_packing.sh @@ -144,9 +144,15 @@ fi # grid_simple_log_preprocessing # ----------------------------- input=${data_dir}/sample.grib2 -${tools_dir}/grib_set -r -s packingType=grid_simple_log_preprocessing $input $temp +${tools_dir}/grib_set -r -s packingType=grid_simple_log_preprocessing $input $temp 2> $temp_err grib_check_key_equals $temp packingType 'grid_simple_log_preprocessing' ${tools_dir}/grib_compare -c data:n -R packedValues=2e-6 $input $temp +# ECC-1897 +grep -q "ECCODES WARNING.*is experimental" $temp_err + +${tools_dir}/grib_set -r -s packingType=grid_simple_matrix $input $temp 2> $temp_err +grep -q "ECCODES WARNING.*is experimental" $temp_err + # Large constant fields # -----------------------