From 9fc2a5c84c271dfa6724f692dba84529ac61affe Mon Sep 17 00:00:00 2001 From: shahramn Date: Fri, 4 Oct 2024 13:10:07 +0100 Subject: [PATCH 1/6] ECC-1929: Definitions: Ability to use the print statement --- src/action_class_print.cc | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/action_class_print.cc b/src/action_class_print.cc index c96e6e22c..366710458 100644 --- a/src/action_class_print.cc +++ b/src/action_class_print.cc @@ -18,6 +18,7 @@ START_CLASS_DEF CLASS = action IMPLEMENTS = destroy;execute + IMPLEMENTS = create_accessor MEMBERS = char *name MEMBERS = char *outname END_CLASS_DEF @@ -36,6 +37,7 @@ or edit "action.class" and rerun ./make_class.pl static void init_class (grib_action_class*); static void destroy (grib_context*,grib_action*); +static int create_accessor(grib_section*,grib_action*,grib_loader*); static int execute(grib_action* a,grib_handle* h); @@ -57,7 +59,7 @@ static grib_action_class _grib_action_class_print = { &destroy, /* destroy */ 0, /* dump */ 0, /* xref */ - 0, /* create_accessor */ + &create_accessor, /* create_accessor */ 0, /* notify_change */ 0, /* reparse */ &execute, /* execute */ @@ -141,3 +143,21 @@ static void destroy(grib_context* context, grib_action* act) grib_context_free_persistent(context, act->name); grib_context_free_persistent(context, act->op); } + +static int create_accessor(grib_section* p, grib_action* act, grib_loader* h) +{ + // ECC-1929: A print statement within the definitions does not + // actually create an accessor. So we just run it + grib_action_print* self = (grib_action_print*)act; + + const int err = execute(act, p->h); + if (err) + grib_context_log(act->context, GRIB_LOG_ERROR, "Print: '%s' (%s)", self->name, grib_get_error_message(err)); + return err; + + // We may want to be forgiving and ignore the error + // if (act->context->debug) { + // return err; + // } + // return GRIB_SUCCESS; +} From 914643efb71bddb603f425a6c105b3f432f95f0b Mon Sep 17 00:00:00 2001 From: shahramn Date: Fri, 4 Oct 2024 15:41:21 +0100 Subject: [PATCH 2/6] Tools: Usage text --- tools/bufr_set.cc | 9 +++++---- tools/grib_set.cc | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/tools/bufr_set.cc b/tools/bufr_set.cc index 7b6c62a4e..a304b7dc3 100644 --- a/tools/bufr_set.cc +++ b/tools/bufr_set.cc @@ -18,9 +18,10 @@ grib_option grib_options[] = { { "w:", "key[:{s|d|i}]=value,key[:{s|d|i}]=value,...", "\n\t\tWhere clause.\n\t\tSet is only executed for BUFR messages matching all the " "key/value constraints.\n\t\tIf a BUFR message does not match the constraints it is" - " copied unchanged\n\t\tto the output_file. This behaviour can be changed " + " copied unchanged\n\t\tto the output_bufr_file. This behaviour can be changed " "setting the option -S.\n\t\tFor each key a string (key:s), a double (key:d) or" " an integer (key:i)\n\t\ttype can be defined. Default type is string." + "\n\t\tIn the value you can also use the forward-slash character '/' to specify an OR condition (i.e. a logical disjunction)" "\n\t\tNote: only one -w clause is allowed.\n", 0, 1, 0 }, { "q", 0, 0, 1, 0, 0 }, @@ -36,12 +37,12 @@ grib_option grib_options[] = { }; const char* tool_description = - "Sets key/value pairs in the input BUFR file and writes" - "\n\teach message to the output_file." + "Sets key/value pairs in the input BUFR file(s) and writes" + "\n\teach message to the output_bufr_file." "\n\tIt fails when an error occurs (e.g. key not found)."; const char* tool_name = "bufr_set"; const char* tool_online_doc = "https://confluence.ecmwf.int/display/ECC/bufr_set"; -const char* tool_usage = "[options] file file ... output_file"; +const char* tool_usage = "[options] bufr_file bufr_file ... output_bufr_file"; int grib_options_count = sizeof(grib_options) / sizeof(grib_option); diff --git a/tools/grib_set.cc b/tools/grib_set.cc index 70adef8e3..5b2e5758b 100644 --- a/tools/grib_set.cc +++ b/tools/grib_set.cc @@ -44,7 +44,7 @@ grib_option grib_options[] = { }; const char* tool_description = - "Sets key/value pairs in the input GRIB file and writes" + "Sets key/value pairs in the input GRIB file(s) and writes" "\n\teach message to the output_grib_file." "\n\tIt fails when an error occurs (e.g. key not found)."; const char* tool_name = "grib_set"; From 389a71ad5e684dda9dc323e47d670c54aead8203 Mon Sep 17 00:00:00 2001 From: shahramn Date: Fri, 4 Oct 2024 18:01:16 +0100 Subject: [PATCH 3/6] Testing: ECC-1929 --- tests/CMakeLists.txt | 1 + tests/codes_ecc-1929.sh | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100755 tests/codes_ecc-1929.sh diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index cba77adcd..82a1ba4df 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -283,6 +283,7 @@ if( HAVE_BUILD_TOOLS ) grib_set_force bufr_ecc-556 codes_ecc-1698 + codes_ecc-1929 codes_get_string codes_codetable gts_get diff --git a/tests/codes_ecc-1929.sh b/tests/codes_ecc-1929.sh new file mode 100755 index 000000000..1d90059d0 --- /dev/null +++ b/tests/codes_ecc-1929.sh @@ -0,0 +1,35 @@ +#!/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 + +REDIRECT=/dev/null + +label="codes_ecc-1929_test" + +tempOut=temp.$label.txt +sample_grib2=$ECCODES_SAMPLES_PATH/GRIB2.tmpl + +tempDir=${label}.temp.dir +rm -rf $tempDir +mkdir -p $tempDir/definitions/grib2 +bootfile=$tempDir/definitions/grib2/boot.def +cat $def_dir/grib2/boot.def > $bootfile +echo 'print "DEBUG: [gridType=] [typeOfLevel=]";' >> $bootfile +echo >> $bootfile + +export ECCODES_DEFINITION_PATH=$PWD/$tempDir/definitions +# This will activate the print statement above +${tools_dir}/grib_get -p edition $sample_grib2 > $tempOut +grep -q "DEBUG: gridType=regular_ll typeOfLevel=surface" $tempOut + +# Clean up +rm -rf $tempDir +rm -f $tempOut From e6cc18d3f901e77874f52692724c2d7b5dc0664d Mon Sep 17 00:00:00 2001 From: shahramn Date: Sat, 5 Oct 2024 17:57:01 +0100 Subject: [PATCH 4/6] Testing: ECC-1929 --- tests/grib_filter_fail.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/grib_filter_fail.sh b/tests/grib_filter_fail.sh index 3f77cf436..dd5aec1f6 100755 --- a/tests/grib_filter_fail.sh +++ b/tests/grib_filter_fail.sh @@ -85,6 +85,17 @@ set -e [ $status -ne 0 ] grep -q "Unable to open file" $tempOut + +# Bad print +# ---------- +set +e +echo 'print ("/") "should fail";' | ${tools_dir}/grib_filter - $input > $tempOut 2>&1 +status=$? +set -e +[ $status -ne 0 ] +grep -q "IO ERROR" $tempOut + + # Signed bits # ----------- cat >$tempFilt < Date: Sat, 5 Oct 2024 20:18:01 +0100 Subject: [PATCH 5/6] Testing: Assertions in defintion files --- tests/CMakeLists.txt | 1 + tests/codes_assert.sh | 39 +++++++++++++++++++++++++++++++++++++++ tests/codes_ecc-1929.sh | 4 +--- 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100755 tests/codes_assert.sh diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 82a1ba4df..1bca272ab 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -282,6 +282,7 @@ if( HAVE_BUILD_TOOLS ) grib_set_bytes grib_set_force bufr_ecc-556 + codes_assert codes_ecc-1698 codes_ecc-1929 codes_get_string diff --git a/tests/codes_assert.sh b/tests/codes_assert.sh new file mode 100755 index 000000000..1bd5c878d --- /dev/null +++ b/tests/codes_assert.sh @@ -0,0 +1,39 @@ +#!/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="codes_assert_test" + +tempOut=temp.$label.txt +sample_grib2=$ECCODES_SAMPLES_PATH/GRIB2.tmpl + +tempDir=${label}.temp.dir +rm -rf $tempDir +mkdir -p $tempDir/definitions/grib2 +bootfile=$tempDir/definitions/grib2/boot.def +cat $def_dir/grib2/boot.def > $bootfile +echo 'assert( year == 1990 );' >> $bootfile +echo >> $bootfile + +export ECCODES_DEFINITION_PATH=$PWD/$tempDir/definitions +# This will activate the print statement above +${tools_dir}/grib_set -s year=1990 $sample_grib2 /dev/null + +set +e +${tools_dir}/grib_set -s year=1991 $sample_grib2 /dev/null > $tempOut 2>&1 +status=$? +set -e +[ $status -ne 0 ] +grep -q "year.*Assertion failure" $tempOut + +# Clean up +rm -rf $tempDir +rm -f $tempOut diff --git a/tests/codes_ecc-1929.sh b/tests/codes_ecc-1929.sh index 1d90059d0..c7ed04d3e 100755 --- a/tests/codes_ecc-1929.sh +++ b/tests/codes_ecc-1929.sh @@ -10,8 +10,6 @@ . ./include.ctest.sh -REDIRECT=/dev/null - label="codes_ecc-1929_test" tempOut=temp.$label.txt @@ -22,7 +20,7 @@ rm -rf $tempDir mkdir -p $tempDir/definitions/grib2 bootfile=$tempDir/definitions/grib2/boot.def cat $def_dir/grib2/boot.def > $bootfile -echo 'print "DEBUG: [gridType=] [typeOfLevel=]";' >> $bootfile +echo 'print "DEBUG: [gridType=] [typeOfLevel=]";' >> $bootfile echo >> $bootfile export ECCODES_DEFINITION_PATH=$PWD/$tempDir/definitions From 626d3c4102f58a3e165678d2892e2bedd76ecfcc Mon Sep 17 00:00:00 2001 From: shahramn Date: Sun, 6 Oct 2024 13:50:10 +0100 Subject: [PATCH 6/6] Dead code removal --- src/action_class_set_missing.cc | 15 +-------------- tools/codes_config.in | 3 +++ 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/action_class_set_missing.cc b/src/action_class_set_missing.cc index 0907c3760..413551547 100644 --- a/src/action_class_set_missing.cc +++ b/src/action_class_set_missing.cc @@ -14,7 +14,6 @@ START_CLASS_DEF CLASS = action - IMPLEMENTS = dump IMPLEMENTS = destroy;execute MEMBERS = char *name END_CLASS_DEF @@ -32,7 +31,6 @@ or edit "action.class" and rerun ./make_class.pl */ static void init_class (grib_action_class*); -static void dump (grib_action* d, FILE*,int); static void destroy (grib_context*,grib_action*); static int execute(grib_action* a,grib_handle* h); @@ -52,7 +50,7 @@ static grib_action_class _grib_action_class_set_missing = { &init_class, /* init_class */ 0, /* init */ &destroy, /* destroy */ - &dump, /* dump */ + 0, /* dump */ 0, /* xref */ 0, /* create_accessor */ 0, /* notify_change */ @@ -95,17 +93,6 @@ static int execute(grib_action* a, grib_handle* h) return grib_set_missing(h, self->name); } -static void dump(grib_action* act, FILE* f, int lvl) -{ - grib_context_log(act->context, GRIB_LOG_ERROR, "%s %s(): Not implemented", __FILE__, __func__); - // int i = 0; - // const grib_action_set_missing* self = (grib_action_set_missing*)act; - // for (i = 0; i < lvl; i++) - // grib_context_print(act->context, f, " "); - // grib_context_print(act->context, f, self->name); - // printf("\n"); -} - static void destroy(grib_context* context, grib_action* act) { grib_action_set_missing* a = (grib_action_set_missing*)act; diff --git a/tools/codes_config.in b/tools/codes_config.in index fa15d0115..017c4715c 100755 --- a/tools/codes_config.in +++ b/tools/codes_config.in @@ -7,6 +7,9 @@ ECCODES_PATCH_VERSION=@eccodes_VERSION_PATCH@ # ECCODES_VERSION="$ECCODES_MAJOR_VERSION.$ECCODES_MINOR_VERSION.$ECCODES_PATCH_VERSION" ECCODES_GIT_SHA1="@eccodes_GIT_SHA1@" +if [ "x$ECCODES_GIT_SHA1" = "x" ]; then + ECCODES_GIT_SHA1="unknown" +fi ################################################################# # Commands