From 6f59e109ba76cbff6aa2ee8e8b3881c7e85bca4d Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 18 Dec 2024 12:15:04 +0000 Subject: [PATCH] GRIB message validity checker: Geoiterator --- .../grib_accessor_class_message_is_valid.cc | 22 +++++++++++++++---- tests/grib_check_message_validity.sh | 7 ++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/accessor/grib_accessor_class_message_is_valid.cc b/src/accessor/grib_accessor_class_message_is_valid.cc index a467c88f0..9a0bdbea7 100644 --- a/src/accessor/grib_accessor_class_message_is_valid.cc +++ b/src/accessor/grib_accessor_class_message_is_valid.cc @@ -73,9 +73,7 @@ static int check_grid_pl_array(grib_handle* h) } pl = (long*)grib_context_malloc_clear(c, sizeof(long) * plsize); - if (!pl) { - return GRIB_OUT_OF_MEMORY; - } + if (!pl) return GRIB_OUT_OF_MEMORY; if ((ret = grib_get_long_array(h, "pl", pl, &plsize)) != GRIB_SUCCESS) return ret; @@ -90,10 +88,26 @@ static int check_grid_pl_array(grib_handle* h) return GRIB_SUCCESS; } +static int check_geoiterator(grib_handle* h) +{ + //printf("DEBUG %s \n", __func__); + int err = 0; + grib_iterator* iter = grib_iterator_new(h, 0, &err); + if (err == GRIB_NOT_IMPLEMENTED || err == GRIB_SUCCESS) { + grib_iterator_delete(iter); + return GRIB_SUCCESS; // GRIB_NOT_IMPLEMENTED is OK e.g., for spectral fields + } + + grib_context_log(h->context, GRIB_LOG_ERROR, "%s", grib_get_error_message(err)); + grib_iterator_delete(iter); + return err; +} + typedef int (*proj_func)(grib_handle*); static proj_func check_functions[] = { check_field_values, - check_grid_pl_array + check_grid_pl_array, + check_geoiterator }; int grib_accessor_message_is_valid_t::unpack_long(long* val, size_t* len) diff --git a/tests/grib_check_message_validity.sh b/tests/grib_check_message_validity.sh index 73496c491..828ade584 100755 --- a/tests/grib_check_message_validity.sh +++ b/tests/grib_check_message_validity.sh @@ -17,6 +17,13 @@ tempFilt=temp.$label.filt sample=$ECCODES_SAMPLES_PATH/reduced_gg_pl_32_grib2.tmpl grib_check_key_equals $sample isMessageValid 1 +# Check regular lat/lon +# ------------------------------ +${tools_dir}/grib_set -s Nj=0 $data_dir/sample.grib2 $tempGrib +grib_check_key_equals $tempGrib isMessageValid 0 2>$tempText +grep -q "Regular grid Geoiterator" $tempText + + # Check reduced Gaussian grid Ni # ------------------------------ cat >$tempFilt<