diff --git a/src/grib_keys_iterator.c b/src/grib_keys_iterator.c index f1641dbf0..aebff8095 100644 --- a/src/grib_keys_iterator.c +++ b/src/grib_keys_iterator.c @@ -151,6 +151,10 @@ static int skip(grib_keys_iterator* kiter) mark_seen(kiter, kiter->current->name); } + /* ECC-1410 */ + if (kiter->current->all_names[0] == NULL) + return 1; + return 0; } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5f915d6e5..f750397ce 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -20,6 +20,7 @@ list(APPEND test_bins grib_read_index unit_tests bufr_keys_iter + grib_keys_iter gauss_sub grib_nearest_test grib_util_set_spec @@ -154,6 +155,7 @@ if( HAVE_BUILD_TOOLS ) bufr_ls_json bufr_change_edition bufr_keys_iter + grib_keys_iter bufr_get_element bufr_wmo_tables bufr_extract_headers diff --git a/tests/grib_keys_iter.c b/tests/grib_keys_iter.c new file mode 100644 index 000000000..e9613ef44 --- /dev/null +++ b/tests/grib_keys_iter.c @@ -0,0 +1,37 @@ +#include +#include +#include +#include +#include + +#include "eccodes.h" + +int main(int argc, char* argv[]) +{ + FILE* f = NULL; + codes_handle* h = NULL; + int err = 0; + + assert(argc == 2); + f = fopen(argv[1], "rb"); + assert(f); + + while ((h = codes_handle_new_from_file(0, f, PRODUCT_GRIB, &err)) != NULL) { + codes_keys_iterator* kiter = NULL; + + /* Use namespace of NULL to get ALL keys */ + kiter = codes_keys_iterator_new(h, 0, /*namespace=*/NULL); + assert(kiter); + + while (codes_keys_iterator_next(kiter)) { + const char* name = codes_keys_iterator_get_name(kiter); + assert(name); + printf("%s\n", name); + } + + codes_keys_iterator_delete(kiter); + codes_handle_delete(h); + } + fclose(f); + return 0; +} diff --git a/tests/grib_keys_iter.sh b/tests/grib_keys_iter.sh new file mode 100755 index 000000000..a4018fa5c --- /dev/null +++ b/tests/grib_keys_iter.sh @@ -0,0 +1,26 @@ +#!/bin/sh +# (C) Copyright 2005- ECMWF. +# +# This software is licensed under the terms of the Apache Licence Version 2.0 +# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +# +# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by +# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. +# + +. ./include.ctest.sh + +label="grib_keys_iter_test" +tempOut=temp.$label.out + +cd ${data_dir} + +# ECC-1410 +f='tigge/tiggelam_cnmc_sfc.grib' +$EXEC ${test_dir}/grib_keys_iter $f + +for f in *grib *grib[12] tigge/*grib; do + $EXEC ${test_dir}/grib_keys_iter $f > $tempOut +done + +rm -f $tempOut