diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index eb2e37ea0..3281011f5 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -10,6 +10,7 @@ execute_process( COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_S # Build the executables used by test scripts ################################################ list(APPEND test_bins + list_codetable_flagtable_keys grib_bpv_limit grib_double_cmp read_any @@ -226,6 +227,7 @@ if( HAVE_BUILD_TOOLS ) list(APPEND tests_data_reqd grib_tigge_conversions2) list(APPEND tests_data_reqd bufr_dump_encode_C) list(APPEND tests_data_reqd bufr_dump_decode_C) + list(APPEND tests_no_data_reqd list_codetable_flagtable_keys) endif() # These tests do not require any data downloads diff --git a/tests/list_codetable_flagtable_keys.c b/tests/list_codetable_flagtable_keys.c new file mode 100644 index 000000000..b13c66a1c --- /dev/null +++ b/tests/list_codetable_flagtable_keys.c @@ -0,0 +1,101 @@ +/* + * (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 "grib_api_internal.h" + +typedef struct grib_action_if +{ + grib_action act; + /* Members defined in section */ + /* Members defined in if */ + grib_expression* expression; + grib_action* block_true; + grib_action* block_false; +} grib_action_if; + +typedef struct grib_action_list +{ + grib_action act; + /* Members defined in section */ + /* Members defined in list */ + grib_expression* expression; + grib_action* block_list; +} grib_action_list; + +typedef struct grib_action_gen +{ + grib_action act; + /* Members defined in gen */ + long len; + grib_arguments* params; +} grib_action_gen; + +void print_names(grib_action* a) +{ + while (a) { + if (a->op && !strcmp(a->op, "label")) { + a = a->next; + continue; + } + if (!strcmp(a->cclass->name, "action_class_noop") || + !strcmp(a->cclass->name, "action_class_when")) { + a = a->next; + continue; + } + + if (!strcmp(a->cclass->name, "action_class_list")) { + grib_action_list* al = (grib_action_list*)a; + /*printf("%s\n", a->name);*/ + print_names(al->block_list); + } + else if (!strcmp(a->cclass->name, "action_class_if")) { + grib_action_if* ai = (grib_action_if*)a; + print_names(ai->block_false); + print_names(ai->block_true); + } + else if (!strcmp(a->cclass->name, "action_class_gen")) { + const char* table = NULL; + grib_action_gen* ag = (grib_action_gen*)a; + if (strcmp(a->op,"codetable")==0 || strcmp(a->op,"codeflag")==0) { + printf("%s", a->name); + table = grib_arguments_get_string(NULL, ag->params, 0); + if (table) printf("\t%s=%s", a->op, table); + printf("\n"); + } + } + else { + /*printf("%s\n", a->name);*/ + } + + a = a->next; + } +} + +int main(int argc, char* argv[]) +{ + int i = 0; + int fail = 0; + + grib_context* c = grib_context_get_default(); + grib_action* a = NULL; + + for (i = 1; i < argc; i++) { + if (!(a = grib_parse_file(c, argv[i]))) { + fail++; + printf("FAILED\n"); + exit(1); + } + else { + print_names(a); + } + } + + return fail; +} diff --git a/tests/list_codetable_flagtable_keys.sh b/tests/list_codetable_flagtable_keys.sh new file mode 100755 index 000000000..5e042c311 --- /dev/null +++ b/tests/list_codetable_flagtable_keys.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.sh + +OUTPUT=all_codetable_flagtable_keys.txt +TEMP=temp.list_codetable_flagtable_keys.txt + +[ -z "$ECCODES_DEFINITION_PATH" ] | ECCODES_DEFINITION_PATH=`${tools_dir}/codes_info -d` + +touch $TEMP +echo "Go through all files in $ECCODES_DEFINITION_PATH ..." +for file in `find $ECCODES_DEFINITION_PATH/ -name '*.def' -print`; do + ${test_dir}/list_codetable_flagtable_keys $file >> $TEMP +done + +sort -u < $TEMP > $OUTPUT +echo "Created $OUTPUT" +rm -f $TEMP diff --git a/tools/grib_get_data.sh b/tools/grib_get_data.sh index 223930257..dd1786cd1 100755 --- a/tools/grib_get_data.sh +++ b/tools/grib_get_data.sh @@ -9,10 +9,15 @@ echo "\\endverbatim" echo "-# If you want to define your missing value=1111 and to print the string 'missing' in place of it" echo "\\verbatim" -echo ">grib_get_data -m 1111:missing ../data/reduced_gaussian_model_level.grib2" +echo ">grib_get_data -m 1111:missing ../data/reduced_latlon_surface.grib2" echo "\\endverbatim" echo "-# If you want to print the value of other keys with the data value list" echo "\\verbatim" echo ">grib_get_data -p centre,level,step ../data/reduced_gaussian_model_level.grib2" echo "\\endverbatim" + +echo "-# If you want to control the formatting of the latitudes and longitudes" +echo "\\verbatim" +echo ">grib_get_data -L %12.6f%12.6f ../data/reduced_latlon_surface.grib2" +echo "\\endverbatim"