From 283b69596b217e6fd06d199a3c5bf15c8fa9f2e4 Mon Sep 17 00:00:00 2001 From: Eugen Betke Date: Wed, 24 Apr 2024 17:17:54 +0000 Subject: [PATCH 01/14] ECC-1813: stepUnits (without step) change low_level_keys --- src/grib_accessor_class_g2end_step.cc | 21 ++++++++++- src/grib_accessor_class_optimal_step_units.cc | 36 +++++++++++++++++-- tests/grib_sub_hourly.sh | 9 +++++ 3 files changed, 62 insertions(+), 4 deletions(-) diff --git a/src/grib_accessor_class_g2end_step.cc b/src/grib_accessor_class_g2end_step.cc index a86733eb3..eed6b5d13 100644 --- a/src/grib_accessor_class_g2end_step.cc +++ b/src/grib_accessor_class_g2end_step.cc @@ -262,9 +262,13 @@ static int unpack_one_time_range_long_(grib_accessor* a, long* val, size_t* len) } if (add_time_range) { *val = start_step_value + time_range_value; + if ((err = grib_set_long_internal(h, "endStepUnit", step_units)) != GRIB_SUCCESS) + return err; } else { *val = start_step_value; + if ((err = grib_set_long_internal(h, "endStepUnit", step_units)) != GRIB_SUCCESS) + return err; } return GRIB_SUCCESS; @@ -310,9 +314,13 @@ static int unpack_one_time_range_double_(grib_accessor* a, double *val , size_t* } if (add_time_range) { *val = (start_step + time_range).value(eccodes::Unit(step_units)); + if ((err = grib_set_long_internal(h, "endStepUnit", step_units)) != GRIB_SUCCESS) + return err; } else { *val = start_step.value(eccodes::Unit(start_step_unit)); + if ((err = grib_set_long_internal(h, "endStepUnit", start_step_unit)) != GRIB_SUCCESS) + return err; } return GRIB_SUCCESS; @@ -441,14 +449,19 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) grib_handle* h = grib_handle_of_accessor(a); int ret = 0; long start_step_value; + long start_step_unit; long numberOfTimeRange; if ((ret = grib_get_long_internal(h, self->start_step_value, &start_step_value))) return ret; + if ((ret = grib_get_long_internal(h, "startStepUnit", &start_step_unit))) + return ret; /* point in time */ if (self->year == NULL) { *val = start_step_value; + if ((ret = grib_set_long_internal(h, "endStepUnit", start_step_unit))) + return ret; return 0; } @@ -479,14 +492,19 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) grib_handle* h = grib_handle_of_accessor(a); int ret = 0; long start_step_value; + long start_step_unit; long numberOfTimeRange; if ((ret = grib_get_long_internal(h, self->start_step_value, &start_step_value))) return ret; + if ((ret = grib_get_long_internal(h, "startStepUnit", &start_step_unit))) + return ret; /* point in time */ if (self->year == NULL) { *val = start_step_value; + if ((ret = grib_set_long_internal(h, "endStepUnit", start_step_unit))) + return ret; return 0; } @@ -542,7 +560,8 @@ static int pack_long_(grib_accessor* a, const long end_step_value, const long en /*point in time */ if (self->year == NULL) { - err = grib_set_long_internal(h, "startStepUnit", end_step.unit().value()); + if ((err = grib_set_long_internal(h, "startStepUnit", end_step.unit().value())) != GRIB_SUCCESS) + return err; err = grib_set_long_internal(h, self->start_step_value, end_step.value()); return err; } diff --git a/src/grib_accessor_class_optimal_step_units.cc b/src/grib_accessor_class_optimal_step_units.cc index 494667e9a..e56228764 100644 --- a/src/grib_accessor_class_optimal_step_units.cc +++ b/src/grib_accessor_class_optimal_step_units.cc @@ -178,6 +178,12 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) grib_handle* h = grib_handle_of_accessor(a); grib_accessor_optimal_step_units* self = (grib_accessor_optimal_step_units*)a; + long start_step; + long start_step_unit; + long end_step; + long end_step_unit; + int ret; + auto supported_units = eccodes::Unit::list_supported_units(); try { eccodes::Unit unit{*val}; // throws if not supported @@ -198,11 +204,35 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) return GRIB_INVALID_ARGUMENT; } - int ret; + self->overwriteStepUnits = *val; - if ((ret = grib_set_long_internal(h, "forceStepUnits", *val)) != GRIB_SUCCESS) { + if ((ret = grib_set_long_internal(h, "forceStepUnits", *val)) != GRIB_SUCCESS) + return ret; + + if ((ret = grib_get_long_internal(h, "startStep", &start_step)) != GRIB_SUCCESS) + return ret; + if ((ret = grib_get_long_internal(h, "startStepUnit", &start_step_unit)) != GRIB_SUCCESS) + return ret; + if ((ret = grib_get_long_internal(h, "endStep", &end_step)) != GRIB_SUCCESS) + return ret; + if ((ret = grib_get_long_internal(h, "endStepUnit", &end_step_unit)) != GRIB_SUCCESS) + return ret; + + //printf("start_step: %ld, start_step_unit: %ld, end_step: %ld, end_step_unit: %ld\n", start_step, start_step_unit, end_step, end_step_unit); + + eccodes::Step start{start_step, start_step_unit}; + start = start.set_unit(*val); + eccodes::Step end{end_step, end_step_unit}; + end = end.set_unit(*val); + + if ((ret = grib_set_long_internal(h, "startStepUnit", start.unit().value())) != GRIB_SUCCESS) + return ret; + if ((ret = grib_set_long_internal(h, "startStep", start.value())) != GRIB_SUCCESS) + return ret; + if ((ret = grib_set_long_internal(h, "endStepUnit", end.unit().value())) != GRIB_SUCCESS) + return ret; + if ((ret = grib_set_long_internal(h, "endStep", end.value())) != GRIB_SUCCESS) return ret; - } return GRIB_SUCCESS; } diff --git a/tests/grib_sub_hourly.sh b/tests/grib_sub_hourly.sh index 2f399da0f..18dab0fe1 100755 --- a/tests/grib_sub_hourly.sh +++ b/tests/grib_sub_hourly.sh @@ -62,6 +62,9 @@ fi instantaneous_field=$data_dir/reduced_gaussian_surface.grib2 accumulated_field=$data_dir/reduced_gaussian_sub_area.grib2 + + + # Check the lowercase alias 'stepunits' for a variety of step types (instant, accum etc) ${tools_dir}/grib_get -p stepunits $data_dir/tigge_cf_ecmwf.grib2 @@ -89,6 +92,12 @@ grib_check_key_equals $temp "-p $keys_step_range" "59m 59m 59 59 m" grib_check_key_equals $temp "-p $keys_start_step" "59m 59m 59 59 m" grib_check_key_equals $temp "-p $keys_end_step" "59m 59m 59 59 m" +${tools_dir}/grib_set -s stepUnits=m,step=60 $fn $temp +grib_check_key_equals $temp "-p $low_level_keys" "60 m" +${tools_dir}/grib_set -s stepUnits=s $temp $temp2 +grib_check_key_equals $temp2 "-p $low_level_keys" "3600 s" +${tools_dir}/grib_set -s stepUnits=h $temp $temp2 +grib_check_key_equals $temp2 "-p $low_level_keys" "1 h" #### stepUnits overrides the units in the low level keys # if stepUnits=UNIT is set, then set the low level keys to UNIT From 57bfc520df39e03a11fec32c490aa07617705202 Mon Sep 17 00:00:00 2001 From: Eugen Betke Date: Wed, 24 Apr 2024 17:30:34 +0000 Subject: [PATCH 02/14] ECC-1813: Return error code instead of throwing an exception --- src/grib_accessor_class_optimal_step_units.cc | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/grib_accessor_class_optimal_step_units.cc b/src/grib_accessor_class_optimal_step_units.cc index e56228764..6c15ef430 100644 --- a/src/grib_accessor_class_optimal_step_units.cc +++ b/src/grib_accessor_class_optimal_step_units.cc @@ -204,7 +204,6 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) return GRIB_INVALID_ARGUMENT; } - self->overwriteStepUnits = *val; if ((ret = grib_set_long_internal(h, "forceStepUnits", *val)) != GRIB_SUCCESS) return ret; @@ -218,21 +217,26 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) if ((ret = grib_get_long_internal(h, "endStepUnit", &end_step_unit)) != GRIB_SUCCESS) return ret; - //printf("start_step: %ld, start_step_unit: %ld, end_step: %ld, end_step_unit: %ld\n", start_step, start_step_unit, end_step, end_step_unit); + try { + eccodes::Step start{start_step, start_step_unit}; + start.set_unit(*val); + eccodes::Step end{end_step, end_step_unit}; + end.set_unit(*val); - eccodes::Step start{start_step, start_step_unit}; - start = start.set_unit(*val); - eccodes::Step end{end_step, end_step_unit}; - end = end.set_unit(*val); - - if ((ret = grib_set_long_internal(h, "startStepUnit", start.unit().value())) != GRIB_SUCCESS) - return ret; - if ((ret = grib_set_long_internal(h, "startStep", start.value())) != GRIB_SUCCESS) - return ret; - if ((ret = grib_set_long_internal(h, "endStepUnit", end.unit().value())) != GRIB_SUCCESS) - return ret; - if ((ret = grib_set_long_internal(h, "endStep", end.value())) != GRIB_SUCCESS) - return ret; + if ((ret = grib_set_long_internal(h, "startStepUnit", start.unit().value())) != GRIB_SUCCESS) + return ret; + if ((ret = grib_set_long_internal(h, "startStep", start.value())) != GRIB_SUCCESS) + return ret; + if ((ret = grib_set_long_internal(h, "endStepUnit", end.unit().value())) != GRIB_SUCCESS) + return ret; + if ((ret = grib_set_long_internal(h, "endStep", end.value())) != GRIB_SUCCESS) + return ret; + } + catch (std::exception& e) { + std::string msg = std::string{"Failed to convert steps to: "} + std::to_string(*val) + " (" + e.what() + ")"; + grib_context_log(a->context, GRIB_LOG_ERROR, "%s", msg.c_str()); + return GRIB_INTERNAL_ERROR; + } return GRIB_SUCCESS; } From cb4f057345a2bf1d43e58fb8ea1d779e51c34096 Mon Sep 17 00:00:00 2001 From: Eugen Betke Date: Wed, 24 Apr 2024 17:34:33 +0000 Subject: [PATCH 03/14] ECC-1813: Test accumulated fields --- tests/grib_sub_hourly.sh | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/tests/grib_sub_hourly.sh b/tests/grib_sub_hourly.sh index 18dab0fe1..5f33ad125 100755 --- a/tests/grib_sub_hourly.sh +++ b/tests/grib_sub_hourly.sh @@ -63,7 +63,23 @@ instantaneous_field=$data_dir/reduced_gaussian_surface.grib2 accumulated_field=$data_dir/reduced_gaussian_sub_area.grib2 +fn="$instantaneous_field" +low_level_keys="forecastTime,indicatorOfUnitOfTimeRange:s" +${tools_dir}/grib_set -s stepUnits=m,step=60 $fn $temp +grib_check_key_equals $temp "-p $low_level_keys" "60 m" +${tools_dir}/grib_set -s stepUnits=s $temp $temp2 +grib_check_key_equals $temp2 "-p $low_level_keys" "3600 s" +${tools_dir}/grib_set -s stepUnits=h $temp $temp2 +grib_check_key_equals $temp2 "-p $low_level_keys" "1 h" +fn="$accumulated_field" +low_level_keys="forecastTime,indicatorOfUnitOfTimeRange:s,lengthOfTimeRange,indicatorOfUnitForTimeRange:s" +${tools_dir}/grib_set -s stepUnits=m,stepRange=60-180 $fn $temp +grib_check_key_equals $temp "-p $low_level_keys" "60 m 120 m" +${tools_dir}/grib_set -s stepUnits=s $temp $temp2 +grib_check_key_equals $temp2 "-p $low_level_keys" "3600 s 7200 s" +${tools_dir}/grib_set -s stepUnits=h $temp $temp2 +grib_check_key_equals $temp2 "-p $low_level_keys" "1 h 2 h" # Check the lowercase alias 'stepunits' for a variety of step types (instant, accum etc) ${tools_dir}/grib_get -p stepunits $data_dir/tigge_cf_ecmwf.grib2 @@ -92,13 +108,6 @@ grib_check_key_equals $temp "-p $keys_step_range" "59m 59m 59 59 m" grib_check_key_equals $temp "-p $keys_start_step" "59m 59m 59 59 m" grib_check_key_equals $temp "-p $keys_end_step" "59m 59m 59 59 m" -${tools_dir}/grib_set -s stepUnits=m,step=60 $fn $temp -grib_check_key_equals $temp "-p $low_level_keys" "60 m" -${tools_dir}/grib_set -s stepUnits=s $temp $temp2 -grib_check_key_equals $temp2 "-p $low_level_keys" "3600 s" -${tools_dir}/grib_set -s stepUnits=h $temp $temp2 -grib_check_key_equals $temp2 "-p $low_level_keys" "1 h" - #### stepUnits overrides the units in the low level keys # if stepUnits=UNIT is set, then set the low level keys to UNIT # else optimise low level keys From 7e2ebecfe1a1c027fe1450aeb47d4832699ac238 Mon Sep 17 00:00:00 2001 From: Eugen Betke Date: Wed, 24 Apr 2024 17:35:55 +0000 Subject: [PATCH 04/14] ECC-1813: Improve description --- tests/grib_sub_hourly.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/grib_sub_hourly.sh b/tests/grib_sub_hourly.sh index 5f33ad125..23c1fb9ca 100755 --- a/tests/grib_sub_hourly.sh +++ b/tests/grib_sub_hourly.sh @@ -63,6 +63,7 @@ instantaneous_field=$data_dir/reduced_gaussian_surface.grib2 accumulated_field=$data_dir/reduced_gaussian_sub_area.grib2 +# ECC-1813: Test that we can set the stepUnits without setting the step fn="$instantaneous_field" low_level_keys="forecastTime,indicatorOfUnitOfTimeRange:s" ${tools_dir}/grib_set -s stepUnits=m,step=60 $fn $temp From 13c04fc5a63190433b1120db3ed96cdc85d92ddc Mon Sep 17 00:00:00 2001 From: shahramn Date: Thu, 2 May 2024 14:46:56 +0100 Subject: [PATCH 05/14] Testing: grib_histogram --- tests/big2gribex.sh | 6 ++++++ tests/grib_histogram.sh | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/tests/big2gribex.sh b/tests/big2gribex.sh index c8c0b6098..acc78cdf2 100755 --- a/tests/big2gribex.sh +++ b/tests/big2gribex.sh @@ -17,6 +17,12 @@ if [ ! -x ${tools_dir}/big2gribex ]; then exit 0 fi +set +e +${tools_dir}/big2gribex +status=$? +set -e +[ $status -ne 0 ] + ${tools_dir}/big2gribex $data_dir/test.grib1 $tempGrib # Clean up diff --git a/tests/grib_histogram.sh b/tests/grib_histogram.sh index c5b56ab22..9653a9500 100755 --- a/tests/grib_histogram.sh +++ b/tests/grib_histogram.sh @@ -17,5 +17,17 @@ tempOut=temp.$label.txt ${tools_dir}/grib_histogram $ECCODES_SAMPLES_PATH/GRIB1.tmpl > $tempOut ${tools_dir}/grib_histogram $ECCODES_SAMPLES_PATH/GRIB2.tmpl > $tempOut +${tools_dir}/grib_histogram -p step,shortName $ECCODES_SAMPLES_PATH/GRIB2.tmpl > $tempOut + +# Something with a bitmap +input=$data_dir/reduced_latlon_surface.grib2 +grib_check_key_equals $input numberOfMissing 98701 +${tools_dir}/grib_histogram $input > $tempOut + +# Skip +input=$data_dir/tigge_cf_ecmwf.grib2 +${tools_dir}/grib_histogram -w level=925,shortName=gh $input > $tempOut + + # Clean up rm -f $tempOut From beb8abb32c21291e433055baf3e44f10459a1e2a Mon Sep 17 00:00:00 2001 From: shahramn Date: Thu, 2 May 2024 16:23:06 +0100 Subject: [PATCH 06/14] Dead code removal --- tools/grib_histogram.cc | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tools/grib_histogram.cc b/tools/grib_histogram.cc index 90a7e8532..fa77614d7 100644 --- a/tools/grib_histogram.cc +++ b/tools/grib_histogram.cc @@ -76,14 +76,6 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h) names[name_count++] = options->requested_print_keys[i].name; } - if (!options->skip) { - if (options->set_values_count != 0) - err = grib_set_values(h, options->set_values, options->set_values_count); - - if (err != GRIB_SUCCESS && options->fail) - exit(err); - } - GRIB_CHECK(grib_get_long(h, "missingValuesPresent", &missingValuesPresent), 0); GRIB_CHECK(grib_get_size(h, "values", &size), 0); From 71f5dbd1df46ed00e0a3a1e8325eed5e53c75db5 Mon Sep 17 00:00:00 2001 From: shahramn Date: Thu, 2 May 2024 20:36:36 +0100 Subject: [PATCH 07/14] Tools: Deprecated tools --- tools/{ => deprecated}/bufr_3to4.cc | 0 tools/{ => deprecated}/mars_request.cc | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename tools/{ => deprecated}/bufr_3to4.cc (100%) rename tools/{ => deprecated}/mars_request.cc (100%) diff --git a/tools/bufr_3to4.cc b/tools/deprecated/bufr_3to4.cc similarity index 100% rename from tools/bufr_3to4.cc rename to tools/deprecated/bufr_3to4.cc diff --git a/tools/mars_request.cc b/tools/deprecated/mars_request.cc similarity index 100% rename from tools/mars_request.cc rename to tools/deprecated/mars_request.cc From e1630d3435f5125e52066924ffc25e2cb537a663 Mon Sep 17 00:00:00 2001 From: shahramn Date: Fri, 3 May 2024 09:56:14 +0100 Subject: [PATCH 08/14] Examples: Cleanup --- examples/C/new_sample.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/examples/C/new_sample.c b/examples/C/new_sample.c index 9560e3924..82524b022 100644 --- a/examples/C/new_sample.c +++ b/examples/C/new_sample.c @@ -25,8 +25,7 @@ int main(int argc, char** argv) exit(1); } - /* h = codes_grib_handle_new_from_samples(NULL, "GRIB2"); */ - h = codes_handle_new_from_samples(NULL, "just a test"); + h = codes_handle_new_from_samples(NULL, "nonexistentsample"); if (h) return 1; h = codes_handle_new_from_samples(NULL, "GRIB2"); @@ -148,12 +147,6 @@ int main(int argc, char** argv) CODES_CHECK(codes_set_long(h, "jScansPositively", 0), 0); CODES_CHECK(codes_set_long(h, "jPointsAreConsecutive", 0), 0); CODES_CHECK(codes_set_long(h, "alternativeRowScanning", 0), 0); - CODES_CHECK(codes_set_long(h, "iScansPositively", 1), 0); - - /* ITERATOR */ - - - /* NEAREST */ CODES_CHECK(codes_set_long(h, "timeRangeIndicator", 0), 0); CODES_CHECK(codes_set_long(h, "NV", 0), 0); @@ -165,15 +158,12 @@ int main(int argc, char** argv) /* Parameter information */ - /* 0 = Temperature (grib2/tables/4/4.1.0.table) */ CODES_CHECK(codes_set_long(h, "parameterCategory", 0), 0); - /* 0 = Temperature (K) (grib2/tables/4/4.2.0.0.table) */ CODES_CHECK(codes_set_long(h, "parameterNumber", 0), 0); - /* 0 = Analysis (grib2/tables/4/4.3.table) */ CODES_CHECK(codes_set_long(h, "typeOfGeneratingProcess", 0), 0); @@ -185,7 +175,6 @@ int main(int argc, char** argv) /* 1 = Hour (grib2/tables/4/4.4.table) */ CODES_CHECK(codes_set_long(h, "indicatorOfUnitOfTimeRange", 1), 0); - /* 1 = Hour (stepUnits.table) */ CODES_CHECK(codes_set_long(h, "stepUnits", 1), 0); @@ -226,7 +215,6 @@ int main(int argc, char** argv) /* grib 2 Section 6 BIT-MAP SECTION */ - /* 255 = A bit map does not apply to this product (grib2/tables/4/6.0.table) */ CODES_CHECK(codes_set_long(h, "bitMapIndicator", 255), 0); From ea073235d2b06f04268d59e38767a6617935ed19 Mon Sep 17 00:00:00 2001 From: shahramn Date: Fri, 3 May 2024 09:56:40 +0100 Subject: [PATCH 09/14] Error messages: Samples path --- src/grib_handle.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/grib_handle.cc b/src/grib_handle.cc index 732537f12..1afad3476 100644 --- a/src/grib_handle.cc +++ b/src/grib_handle.cc @@ -231,7 +231,7 @@ grib_handle* codes_handle_new_from_samples(grib_context* c, const char* name) if (!g) { grib_context_log(c, GRIB_LOG_ERROR, "Unable to load sample file '%s.tmpl'\n" - " from %s\n" + " samples path='%s'\n" " (ecCodes Version=%s)", name, c->grib_samples_path, ECCODES_VERSION_STR); } From 97294f6b5064c08e83bf3b0eebeb24d22ebcb8c9 Mon Sep 17 00:00:00 2001 From: Eugen Betke Date: Fri, 3 May 2024 13:49:22 +0000 Subject: [PATCH 10/14] ECC-1813: Init local variables, add comment, improve test --- src/grib_accessor_class_optimal_step_units.cc | 12 +- tests/grib_sub_hourly.sh | 116 +++++++++--------- 2 files changed, 68 insertions(+), 60 deletions(-) diff --git a/src/grib_accessor_class_optimal_step_units.cc b/src/grib_accessor_class_optimal_step_units.cc index 6c15ef430..d06592e31 100644 --- a/src/grib_accessor_class_optimal_step_units.cc +++ b/src/grib_accessor_class_optimal_step_units.cc @@ -178,10 +178,10 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) grib_handle* h = grib_handle_of_accessor(a); grib_accessor_optimal_step_units* self = (grib_accessor_optimal_step_units*)a; - long start_step; - long start_step_unit; - long end_step; - long end_step_unit; + long start_step = 0; + long start_step_unit = 0; + long end_step = 0; + long end_step_unit = 0; int ret; auto supported_units = eccodes::Unit::list_supported_units(); @@ -204,6 +204,10 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) return GRIB_INVALID_ARGUMENT; } + // ECC-1813: When the stepUnits key is used without specifying a value, as in the command + // "grib-set -s stepUnits=m in.grib out.grib", the following code initiates an indirect update + // of the low-level keys: forecastTime,indicatorOfUnitOfTimeRange,indicatorOfUnitForTimeRange,lengthOfTimeRange + self->overwriteStepUnits = *val; if ((ret = grib_set_long_internal(h, "forceStepUnits", *val)) != GRIB_SUCCESS) return ret; diff --git a/tests/grib_sub_hourly.sh b/tests/grib_sub_hourly.sh index 23c1fb9ca..bb7bac891 100755 --- a/tests/grib_sub_hourly.sh +++ b/tests/grib_sub_hourly.sh @@ -64,21 +64,25 @@ accumulated_field=$data_dir/reduced_gaussian_sub_area.grib2 # ECC-1813: Test that we can set the stepUnits without setting the step -fn="$instantaneous_field" +in="$instantaneous_field" low_level_keys="forecastTime,indicatorOfUnitOfTimeRange:s" -${tools_dir}/grib_set -s stepUnits=m,step=60 $fn $temp +${tools_dir}/grib_set -s stepUnits=m,step=60 $in $temp grib_check_key_equals $temp "-p $low_level_keys" "60 m" ${tools_dir}/grib_set -s stepUnits=s $temp $temp2 grib_check_key_equals $temp2 "-p $low_level_keys" "3600 s" +${tools_dir}/grib_set -s stepUnits=m $temp $temp2 +grib_check_key_equals $temp2 "-p $low_level_keys" "60 m" ${tools_dir}/grib_set -s stepUnits=h $temp $temp2 grib_check_key_equals $temp2 "-p $low_level_keys" "1 h" -fn="$accumulated_field" +in="$accumulated_field" low_level_keys="forecastTime,indicatorOfUnitOfTimeRange:s,lengthOfTimeRange,indicatorOfUnitForTimeRange:s" -${tools_dir}/grib_set -s stepUnits=m,stepRange=60-180 $fn $temp +${tools_dir}/grib_set -s stepUnits=m,stepRange=60-180 $in $temp grib_check_key_equals $temp "-p $low_level_keys" "60 m 120 m" ${tools_dir}/grib_set -s stepUnits=s $temp $temp2 grib_check_key_equals $temp2 "-p $low_level_keys" "3600 s 7200 s" +${tools_dir}/grib_set -s stepUnits=m $temp $temp2 +grib_check_key_equals $temp2 "-p $low_level_keys" "60 m 120 m" ${tools_dir}/grib_set -s stepUnits=h $temp $temp2 grib_check_key_equals $temp2 "-p $low_level_keys" "1 h 2 h" @@ -87,23 +91,23 @@ ${tools_dir}/grib_get -p stepunits $data_dir/tigge_cf_ecmwf.grib2 #### Make sure that step, stepRange, startStep, endStep produce the same result for instantaneous fields -fn="$instantaneous_field" +in="$instantaneous_field" low_level_keys="forecastTime,indicatorOfUnitOfTimeRange:s" keys_step="step,step:s,step:i,step:d,stepUnits:s" keys_step_range="stepRange,stepRange:s,stepRange:i,stepRange:d,stepUnits:s" keys_start_step="startStep,startStep:s,startStep:i,startStep:d,stepUnits:s" keys_end_step="endStep,endStep:s,endStep:i,endStep:d,stepUnits:s" -${tools_dir}/grib_set -s forecastTime=0,indicatorOfUnitOfTimeRange=h $fn $temp +${tools_dir}/grib_set -s forecastTime=0,indicatorOfUnitOfTimeRange=h $in $temp grib_check_key_equals $temp "-p $low_level_keys" "0 h" -${tools_dir}/grib_set -s stepUnits=m,step=59 $fn $temp +${tools_dir}/grib_set -s stepUnits=m,step=59 $in $temp grib_check_key_equals $temp "-p $keys_step" "59m 59m 59 59 m" grib_check_key_equals $temp "-p $keys_step_range" "59m 59m 59 59 m" grib_check_key_equals $temp "-p $keys_start_step" "59m 59m 59 59 m" grib_check_key_equals $temp "-p $keys_end_step" "59m 59m 59 59 m" -${tools_dir}/grib_set -s forecastTime=0,indicatorOfUnitOfTimeRange=h $fn $temp +${tools_dir}/grib_set -s forecastTime=0,indicatorOfUnitOfTimeRange=h $in $temp grib_check_key_equals $temp "-p $low_level_keys" "0 h" -${tools_dir}/grib_set -s step=59m $fn $temp +${tools_dir}/grib_set -s step=59m $in $temp grib_check_key_equals $temp "-p $keys_step" "59m 59m 59 59 m" grib_check_key_equals $temp "-p $keys_step_range" "59m 59m 59 59 m" grib_check_key_equals $temp "-p $keys_start_step" "59m 59m 59 59 m" @@ -114,53 +118,53 @@ grib_check_key_equals $temp "-p $keys_end_step" "59m 59m 59 59 m" # else optimise low level keys # instant fields: low_level_keys="forecastTime,indicatorOfUnitOfTimeRange:s,lengthOfTimeRange,indicatorOfUnitForTimeRange:s" -fn="$instantaneous_field" +in="$instantaneous_field" low_level_keys="forecastTime,indicatorOfUnitOfTimeRange:s" keys__="step,stepUnits:s" keys_s="step:s" keys_i="step:i,stepUnits:s" keys_d="step:d,stepUnits:s" -${tools_dir}/grib_set -s stepUnits=m,step=60 $fn $temp +${tools_dir}/grib_set -s stepUnits=m,step=60 $in $temp grib_check_key_equals $temp "-p $low_level_keys" "60 m" grib_check_key_equals $temp "-p $keys_s" "1$HOUR" grib_check_key_equals $temp "-p $keys_s -s stepUnits=m" "60m" -${tools_dir}/grib_set -s stepUnits=m,step=60 $fn $temp +${tools_dir}/grib_set -s stepUnits=m,step=60 $in $temp grib_check_key_equals $temp "-p $low_level_keys" "60 m" grib_check_key_equals $temp "-p $keys_s" "1$HOUR" grib_check_key_equals $temp "-p $keys_s -s stepUnits=m" "60m" -${tools_dir}/grib_set -s step=60m $fn $temp +${tools_dir}/grib_set -s step=60m $in $temp grib_check_key_equals $temp "-p $low_level_keys" "1 h" grib_check_key_equals $temp "-p $keys_s" "1$HOUR" grib_check_key_equals $temp "-p $keys_s -s stepUnits=m" "60m" # accumulated fields: -fn="$accumulated_field" +in="$accumulated_field" low_level_keys="forecastTime,indicatorOfUnitOfTimeRange:s,lengthOfTimeRange,indicatorOfUnitForTimeRange:s" keys__="step,startStep,endStep,stepRange,stepUnits:s" keys_s="step:s,startStep:s,endStep:s,stepRange:s,stepUnits:s" keys_i="step:i,startStep:i,endStep:i,stepRange:i,stepUnits:s" keys_d="step:d,startStep:d,endStep:d,stepRange:d,stepUnits:s" -${tools_dir}/grib_set -s stepUnits=m,stepRange=60-120 $fn $temp +${tools_dir}/grib_set -s stepUnits=m,stepRange=60-120 $in $temp grib_check_key_equals $temp "-p $low_level_keys" "60 m 60 m" grib_check_key_equals $temp "-p $keys_s" "2$HOUR 1$HOUR 2$HOUR 1$HOUR-2$HOUR h" grib_check_key_equals $temp "-p $keys_s -s stepUnits=m" "120m 60m 120m 60m-120m m" -${tools_dir}/grib_set -s stepUnits=m,stepRange=60-120 $fn $temp +${tools_dir}/grib_set -s stepUnits=m,stepRange=60-120 $in $temp grib_check_key_equals $temp "-p $low_level_keys" "60 m 60 m" grib_check_key_equals $temp "-p $keys_s" "2$HOUR 1$HOUR 2$HOUR 1$HOUR-2$HOUR h" grib_check_key_equals $temp "-p $keys_s -s stepUnits=m" "120m 60m 120m 60m-120m m" -${tools_dir}/grib_set -s stepRange=60m-120m $fn $temp +${tools_dir}/grib_set -s stepRange=60m-120m $in $temp grib_check_key_equals $temp "-p $low_level_keys" "1 h 1 h" grib_check_key_equals $temp "-p $keys_s" "2$HOUR 1$HOUR 2$HOUR 1$HOUR-2$HOUR h" grib_check_key_equals $temp "-p $keys_s -s stepUnits=m" "120m 60m 120m 60m-120m m" #### CHECK units -fn="$accumulated_field" +in="$accumulated_field" low_level_keys="forecastTime,indicatorOfUnitOfTimeRange:s,lengthOfTimeRange,indicatorOfUnitForTimeRange:s" -${tools_dir}/grib_set -s forecastTime=0,indicatorOfUnitOfTimeRange=h,lengthOfTimeRange=96,indicatorOfUnitForTimeRange=h $fn $temp +${tools_dir}/grib_set -s forecastTime=0,indicatorOfUnitOfTimeRange=h,lengthOfTimeRange=96,indicatorOfUnitForTimeRange=h $in $temp grib_check_key_equals $temp "-p $low_level_keys" "0 h 96 h" grib_check_key_equals $temp " -w count=1 -s stepUnits=s -p step:i,stepUnits:s" "345600 s" @@ -181,38 +185,38 @@ grib_check_key_equals $temp " -w count=1 -s stepUnits=6h -p step,stepUnits:s" "1 grib_check_key_equals $temp " -w count=1 -s stepUnits=12h -p step,stepUnits:s" "8x12h 12h" grib_check_key_equals $temp " -w count=1 -s stepUnits=D -p step,stepUnits:s" "4D D" -${tools_dir}/grib_set -s stepUnits=s,startStep=0,endStep=345600 $fn $temp +${tools_dir}/grib_set -s stepUnits=s,startStep=0,endStep=345600 $in $temp grib_check_key_equals $temp "-p $low_level_keys" "0 s 345600 s" -${tools_dir}/grib_set -s stepUnits=m,startStep=0,endStep=5760 $fn $temp +${tools_dir}/grib_set -s stepUnits=m,startStep=0,endStep=5760 $in $temp grib_check_key_equals $temp "-p $low_level_keys" "0 m 5760 m" -${tools_dir}/grib_set -s stepUnits=h,startStep=0,endStep=96 $fn $temp +${tools_dir}/grib_set -s stepUnits=h,startStep=0,endStep=96 $in $temp grib_check_key_equals $temp "-p $low_level_keys" "0 h 96 h" -${tools_dir}/grib_set -s stepUnits=6h,startStep=0,endStep=16 $fn $temp +${tools_dir}/grib_set -s stepUnits=6h,startStep=0,endStep=16 $in $temp grib_check_key_equals $temp "-p $low_level_keys" "0 6h 16 6h" -${tools_dir}/grib_set -s stepUnits=12h,startStep=0,endStep=8 $fn $temp +${tools_dir}/grib_set -s stepUnits=12h,startStep=0,endStep=8 $in $temp grib_check_key_equals $temp "-p $low_level_keys" "0 12h 8 12h" -${tools_dir}/grib_set -s stepUnits=D,startStep=0,endStep=4 $fn $temp +${tools_dir}/grib_set -s stepUnits=D,startStep=0,endStep=4 $in $temp grib_check_key_equals $temp "-p $low_level_keys" "0 D 4 D" #### CHECK negative forecastTime -fn="$accumulated_field" +in="$accumulated_field" low_level_keys="forecastTime,indicatorOfUnitOfTimeRange:s,lengthOfTimeRange,indicatorOfUnitForTimeRange:s" -${tools_dir}/grib_set -s forecastTime=-6,indicatorOfUnitOfTimeRange=h,lengthOfTimeRange=6,indicatorOfUnitForTimeRange=h $fn $temp +${tools_dir}/grib_set -s forecastTime=-6,indicatorOfUnitOfTimeRange=h,lengthOfTimeRange=6,indicatorOfUnitForTimeRange=h $in $temp grib_check_key_equals $temp "-p $low_level_keys" "-6 h 6 h" grib_check_key_equals $temp "-s stepUnits:s=h -p startStep:s,endStep:s" "-6$HOUR 0$HOUR" grib_check_key_equals $temp "-s stepUnits:s=m -p startStep:s,endStep:s" "-360m 0m" grib_check_key_equals $temp "-s stepUnits:s=s -p startStep:s,endStep:s" "-21600s 0s" -${tools_dir}/grib_set -s forecastTime=-48,indicatorOfUnitOfTimeRange=h,lengthOfTimeRange=0,indicatorOfUnitForTimeRange=h $fn $temp +${tools_dir}/grib_set -s forecastTime=-48,indicatorOfUnitOfTimeRange=h,lengthOfTimeRange=0,indicatorOfUnitForTimeRange=h $in $temp grib_check_key_equals $temp "-p stepRange" "-48$HOUR" #### CHECK: check optimal units are set correctly in GRIB files -fn="$accumulated_field" +in="$accumulated_field" low_level_keys="forecastTime,indicatorOfUnitOfTimeRange:s,lengthOfTimeRange,indicatorOfUnitForTimeRange:s" -${tools_dir}/grib_set -s forecastTime=24,indicatorOfUnitOfTimeRange=h,lengthOfTimeRange=1,indicatorOfUnitForTimeRange=D $fn $temp +${tools_dir}/grib_set -s forecastTime=24,indicatorOfUnitOfTimeRange=h,lengthOfTimeRange=1,indicatorOfUnitForTimeRange=D $in $temp grib_check_key_equals $temp "-p $low_level_keys" "24 h 1 D" ### TODO(maee): @Shahram: how to make parameters position independent @@ -239,18 +243,18 @@ grib_check_key_equals $temp2 "-p $low_level_keys" "60 h 120 h" ${tools_dir}/grib_set -s stepUnits:s=h,startStep:i=60,endStep:i=180 $temp $temp2 grib_check_key_equals $temp2 "-p $low_level_keys" "60 h 120 h" -#fn="$accumulated_field" +#in="$accumulated_field" #low_level_keys="forecastTime,indicatorOfUnitOfTimeRange:s,lengthOfTimeRange,indicatorOfUnitForTimeRange:s" ##high_level_keys="startStep:s,endStep:s" #high_level_keys="startStep:i,endStep:i" -#${tools_dir}/grib_set -s forecastTime=24,indicatorOfUnitOfTimeRange=h,lengthOfTimeRange=1,indicatorOfUnitForTimeRange=D $fn $temp +#${tools_dir}/grib_set -s forecastTime=24,indicatorOfUnitOfTimeRange=h,lengthOfTimeRange=1,indicatorOfUnitForTimeRange=D $in $temp #grib_check_key_equals $temp "-p $low_level_keys" "24 h 1 D" #grib_check_key_equals $temp "-p $high_level_keys" "24 48" #${tools_dir}/grib_set -s startStep:i=24 $temp $temp2 #grib_check_key_equals $temp2 "-p $low_level_keys" "24 h 0 h" #grib_check_key_equals $temp2 "-p $high_level_keys" "24 24" -#${tools_dir}/grib_set -s forecastTime=24,indicatorOfUnitOfTimeRange=h,lengthOfTimeRange=24,indicatorOfUnitForTimeRange=h $fn $temp +#${tools_dir}/grib_set -s forecastTime=24,indicatorOfUnitOfTimeRange=h,lengthOfTimeRange=24,indicatorOfUnitForTimeRange=h $in $temp #grib_check_key_equals $temp "-p $low_level_keys" "24 h 24 h" #grib_check_key_equals $temp "-p $high_level_keys" "24 48" #${tools_dir}/grib_set -s startStep:i=24 $temp $temp2 @@ -259,9 +263,9 @@ grib_check_key_equals $temp2 "-p $low_level_keys" "60 h 120 h" #exit #### CHECK: grib_set - endStep + stepUnits -fn="$accumulated_field" +in="$accumulated_field" low_level_keys="forecastTime,indicatorOfUnitOfTimeRange:s,lengthOfTimeRange,indicatorOfUnitForTimeRange:s" -${tools_dir}/grib_set -s forecastTime=24,indicatorOfUnitOfTimeRange=h,lengthOfTimeRange=1,indicatorOfUnitForTimeRange=D $fn $temp +${tools_dir}/grib_set -s forecastTime=24,indicatorOfUnitOfTimeRange=h,lengthOfTimeRange=1,indicatorOfUnitForTimeRange=D $in $temp grib_check_key_equals $temp "-p $low_level_keys" "24 h 1 D" # Use range unit: hour @@ -321,14 +325,14 @@ ${tools_dir}/grib_set -s stepRange:s=62D-122D $temp $temp2 grib_check_key_equals $temp2 "-p $low_level_keys" "1488 h 1440 h" grib_check_key_equals $temp2 "-p stepRange:s" "1488$HOUR-2928$HOUR" -fn="$instantaneous_field" +in="$instantaneous_field" low_level_keys="forecastTime,indicatorOfUnitOfTimeRange:s" keys__="step,stepUnits:s" keys_s="step:s" keys_i="step:i,stepUnits:s" keys_d="step:d,stepUnits:s" -${tools_dir}/grib_set -s forecastTime=59,indicatorOfUnitOfTimeRange=m $fn $temp +${tools_dir}/grib_set -s forecastTime=59,indicatorOfUnitOfTimeRange=m $in $temp grib_check_key_equals $temp "-p $keys__ -s stepUnits=s" "3540s s" grib_check_key_equals $temp "-p $keys__ -s stepUnits=m" "59m m" #grib_check_key_equals $temp "-p $keys__ -s stepUnits=h" "0" # not supported @@ -343,7 +347,7 @@ grib_check_key_equals $temp "-p $keys_d -s stepUnits=m" "59 m" #grib_check_key_equals $temp "-p $keys_d -s stepUnits=h" "0.983333" # not supported -${tools_dir}/grib_set -s forecastTime=0,indicatorOfUnitOfTimeRange=m $fn $temp +${tools_dir}/grib_set -s forecastTime=0,indicatorOfUnitOfTimeRange=m $in $temp grib_check_key_equals $temp "-p $keys_i -s stepUnits=s" "0 s" grib_check_key_equals $temp "-p $keys_i -s stepUnits=m" "0 m" grib_check_key_equals $temp "-p $keys_i -s stepUnits=h" "0 h" @@ -352,14 +356,14 @@ grib_check_key_equals $temp "-p $keys_d -s stepUnits=m" "0 m" grib_check_key_equals $temp "-p $keys_d -s stepUnits=h" "0 h" -fn="$instantaneous_field" +in="$instantaneous_field" low_level_keys="forecastTime,indicatorOfUnitOfTimeRange:s" keys__="step,stepUnits:s" keys_s="step:s,stepUnits:s" keys_i="step:i,stepUnits:s" keys_d="step:d,stepUnits:s" -${tools_dir}/grib_set -s forecastTime=0,indicatorOfUnitOfTimeRange=m $fn $temp +${tools_dir}/grib_set -s forecastTime=0,indicatorOfUnitOfTimeRange=m $in $temp grib_check_key_equals $temp "-p $low_level_keys" "0 m" grib_check_key_equals $temp "-p $keys__" "0m m" grib_check_key_equals $temp "-p $keys_s" "0m m" @@ -380,7 +384,7 @@ grib_check_key_equals $temp "-p $keys_d -s stepUnits=m" "0 m" grib_check_key_equals $temp "-p $keys_d -s stepUnits=h" "0 h" -${tools_dir}/grib_set -s forecastTime=59,indicatorOfUnitOfTimeRange=m $fn $temp +${tools_dir}/grib_set -s forecastTime=59,indicatorOfUnitOfTimeRange=m $in $temp grib_check_key_equals $temp "-p $low_level_keys" "59 m" grib_check_key_equals $temp "-p $keys__" "59m m" #grib_check_key_equals $temp "-p $keys_s" "59" @@ -388,14 +392,14 @@ grib_check_key_equals $temp "-p $keys_s" "59m m" grib_check_key_equals $temp "-p $keys_i" "59 m" grib_check_key_equals $temp "-p $keys_d" "59 m" -${tools_dir}/grib_set -s forecastTime=60,indicatorOfUnitOfTimeRange=m $fn $temp +${tools_dir}/grib_set -s forecastTime=60,indicatorOfUnitOfTimeRange=m $in $temp grib_check_key_equals $temp "-p $low_level_keys" "60 m" grib_check_key_equals $temp "-p $keys__" "1$HOUR h" grib_check_key_equals $temp "-p $keys_s" "1$HOUR h" grib_check_key_equals $temp "-p $keys_i" "1 h" grib_check_key_equals $temp "-p $keys_d" "1 h" -${tools_dir}/grib_set -s forecastTime=61,indicatorOfUnitOfTimeRange=m $fn $temp +${tools_dir}/grib_set -s forecastTime=61,indicatorOfUnitOfTimeRange=m $in $temp grib_check_key_equals $temp "-p $low_level_keys" "61 m" grib_check_key_equals $temp "-p $keys__" "61m m" #grib_check_key_equals $temp "-p $keys_s" "61" @@ -403,14 +407,14 @@ grib_check_key_equals $temp "-p $keys_s" "61m m" grib_check_key_equals $temp "-p $keys_i" "61 m" grib_check_key_equals $temp "-p $keys_d" "61 m" -${tools_dir}/grib_set -s forecastTime=24,indicatorOfUnitOfTimeRange=h $fn $temp +${tools_dir}/grib_set -s forecastTime=24,indicatorOfUnitOfTimeRange=h $in $temp grib_check_key_equals $temp "-p $low_level_keys" "24 h" grib_check_key_equals $temp "-p $keys__" "24$HOUR h" grib_check_key_equals $temp "-p $keys_s" "24$HOUR h" grib_check_key_equals $temp "-p $keys_i" "24 h" grib_check_key_equals $temp "-p $keys_d" "24 h" -${tools_dir}/grib_set -s forecastTime=1440,indicatorOfUnitOfTimeRange=m $fn $temp +${tools_dir}/grib_set -s forecastTime=1440,indicatorOfUnitOfTimeRange=m $in $temp grib_check_key_equals $temp "-p $low_level_keys" "1440 m" grib_check_key_equals $temp "-p $keys__" "24$HOUR h" grib_check_key_equals $temp "-p $keys_s" "24$HOUR h" @@ -418,40 +422,40 @@ grib_check_key_equals $temp "-p $keys_i" "24 h" grib_check_key_equals $temp "-p $keys_d" "24 h" -fn="$accumulated_field" +in="$accumulated_field" low_level_keys="forecastTime,indicatorOfUnitOfTimeRange:s,lengthOfTimeRange,indicatorOfUnitForTimeRange:s" -${tools_dir}/grib_set -s stepRange=60m-2h $fn $temp +${tools_dir}/grib_set -s stepRange=60m-2h $in $temp grib_check_key_equals $temp "-p $low_level_keys" "1 h 1 h" -fn="$accumulated_field" +in="$accumulated_field" low_level_keys="forecastTime,indicatorOfUnitOfTimeRange:s,lengthOfTimeRange,indicatorOfUnitForTimeRange:s" keys__="stepRange,startStep,endStep" keys_s="stepRange:s,startStep:s,endStep:s" keys_i="stepRange:i,startStep:i,endStep:i" keys_d="stepRange:d,startStep:d,endStep:d" -${tools_dir}/grib_set -s forecastTime=0,indicatorOfUnitOfTimeRange=m,lengthOfTimeRange=2,indicatorOfUnitForTimeRange=h $fn $temp +${tools_dir}/grib_set -s forecastTime=0,indicatorOfUnitOfTimeRange=m,lengthOfTimeRange=2,indicatorOfUnitForTimeRange=h $in $temp grib_check_key_equals $temp "-p $low_level_keys" "0 m 2 h" grib_check_key_equals $temp "-p $keys__" "0$HOUR-2$HOUR 0$HOUR 2$HOUR" grib_check_key_equals $temp "-p $keys_s" "0$HOUR-2$HOUR 0$HOUR 2$HOUR" grib_check_key_equals $temp "-p $keys_i" "2 0 2" grib_check_key_equals $temp "-p $keys_d" "2 0 2" -${tools_dir}/grib_set -s forecastTime=24,indicatorOfUnitOfTimeRange=h,lengthOfTimeRange=1,indicatorOfUnitForTimeRange=D $fn $temp +${tools_dir}/grib_set -s forecastTime=24,indicatorOfUnitOfTimeRange=h,lengthOfTimeRange=1,indicatorOfUnitForTimeRange=D $in $temp grib_check_key_equals $temp "-p $low_level_keys" "24 h 1 D" grib_check_key_equals $temp "-p $keys__" "24$HOUR-48$HOUR 24$HOUR 48$HOUR" grib_check_key_equals $temp "-p $keys_s" "24$HOUR-48$HOUR 24$HOUR 48$HOUR" grib_check_key_equals $temp "-p $keys_i" "48 24 48" grib_check_key_equals $temp "-p $keys_d" "48 24 48" -${tools_dir}/grib_set -s forecastTime=25,indicatorOfUnitOfTimeRange=h,lengthOfTimeRange=1,indicatorOfUnitForTimeRange=D $fn $temp +${tools_dir}/grib_set -s forecastTime=25,indicatorOfUnitOfTimeRange=h,lengthOfTimeRange=1,indicatorOfUnitForTimeRange=D $in $temp grib_check_key_equals $temp "-p $low_level_keys" "25 h 1 D" grib_check_key_equals $temp "-p $keys__" "25$HOUR-49$HOUR 25$HOUR 49$HOUR" grib_check_key_equals $temp "-p $keys_s" "25$HOUR-49$HOUR 25$HOUR 49$HOUR" grib_check_key_equals $temp "-p $keys_i" "49 25 49" grib_check_key_equals $temp "-p $keys_d" "49 25 49" -${tools_dir}/grib_set -s forecastTime=45,indicatorOfUnitOfTimeRange=m,lengthOfTimeRange=15,indicatorOfUnitForTimeRange=m $fn $temp +${tools_dir}/grib_set -s forecastTime=45,indicatorOfUnitOfTimeRange=m,lengthOfTimeRange=15,indicatorOfUnitForTimeRange=m $in $temp grib_check_key_equals $temp "-p $low_level_keys" "45 m 15 m" grib_check_key_equals $temp "-p $keys__" "45m-60m 45m 60m" #grib_check_key_equals $temp "-p $keys_s" "45-60 45 60" @@ -459,28 +463,28 @@ grib_check_key_equals $temp "-p $keys_s" "45m-60m 45m 60m" grib_check_key_equals $temp "-p $keys_i" "60 45 60" grib_check_key_equals $temp "-p $keys_d" "60 45 60" -${tools_dir}/grib_set -s forecastTime=60,indicatorOfUnitOfTimeRange=m,lengthOfTimeRange=2,indicatorOfUnitForTimeRange=h $fn $temp +${tools_dir}/grib_set -s forecastTime=60,indicatorOfUnitOfTimeRange=m,lengthOfTimeRange=2,indicatorOfUnitForTimeRange=h $in $temp grib_check_key_equals $temp "-p $low_level_keys" "60 m 2 h" grib_check_key_equals $temp "-p $keys__" "1$HOUR-3$HOUR 1$HOUR 3$HOUR" grib_check_key_equals $temp "-p $keys_s" "1$HOUR-3$HOUR 1$HOUR 3$HOUR" grib_check_key_equals $temp "-p $keys_i" "3 1 3" grib_check_key_equals $temp "-p $keys_d" "3 1 3" -${tools_dir}/grib_set -s forecastTime=18,indicatorOfUnitOfTimeRange=h,lengthOfTimeRange=6,indicatorOfUnitForTimeRange=h $fn $temp +${tools_dir}/grib_set -s forecastTime=18,indicatorOfUnitOfTimeRange=h,lengthOfTimeRange=6,indicatorOfUnitForTimeRange=h $in $temp grib_check_key_equals $temp "-p $low_level_keys" "18 h 6 h" grib_check_key_equals $temp "-p $keys__" "18$HOUR-24$HOUR 18$HOUR 24$HOUR" grib_check_key_equals $temp "-p $keys_s" "18$HOUR-24$HOUR 18$HOUR 24$HOUR" grib_check_key_equals $temp "-p $keys_i" "24 18 24" grib_check_key_equals $temp "-p $keys_d" "24 18 24" -${tools_dir}/grib_set -s forecastTime=1080,indicatorOfUnitOfTimeRange=m,lengthOfTimeRange=360,indicatorOfUnitForTimeRange=m $fn $temp +${tools_dir}/grib_set -s forecastTime=1080,indicatorOfUnitOfTimeRange=m,lengthOfTimeRange=360,indicatorOfUnitForTimeRange=m $in $temp grib_check_key_equals $temp "-p $low_level_keys" "1080 m 360 m" grib_check_key_equals $temp "-p $keys__" "18$HOUR-24$HOUR 18$HOUR 24$HOUR" grib_check_key_equals $temp "-p $keys_s" "18$HOUR-24$HOUR 18$HOUR 24$HOUR" grib_check_key_equals $temp "-p $keys_i" "24 18 24" grib_check_key_equals $temp "-p $keys_d" "24 18 24" -${tools_dir}/grib_set -s forecastTime=1080,indicatorOfUnitOfTimeRange=m,lengthOfTimeRange=6,indicatorOfUnitForTimeRange=h $fn $temp +${tools_dir}/grib_set -s forecastTime=1080,indicatorOfUnitOfTimeRange=m,lengthOfTimeRange=6,indicatorOfUnitForTimeRange=h $in $temp grib_check_key_equals $temp "-p $low_level_keys" "1080 m 6 h" grib_check_key_equals $temp "-p $keys__" "18$HOUR-24$HOUR 18$HOUR 24$HOUR" grib_check_key_equals $temp "-p $keys_s" "18$HOUR-24$HOUR 18$HOUR 24$HOUR" From 4f577fea529851993abd42c6bb8e9626cf94ed15 Mon Sep 17 00:00:00 2001 From: shahramn Date: Fri, 3 May 2024 17:32:10 +0100 Subject: [PATCH 11/14] Expression: unary op name --- src/grib_expression_class_unop.cc | 11 +++++++++-- src/grib_iterator_class_healpix.cc | 6 +++--- tools/grib_histogram.cc | 1 - 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/grib_expression_class_unop.cc b/src/grib_expression_class_unop.cc index 6188b4586..ae7678043 100644 --- a/src/grib_expression_class_unop.cc +++ b/src/grib_expression_class_unop.cc @@ -17,6 +17,7 @@ CLASS = expression IMPLEMENTS = destroy IMPLEMENTS = native_type + IMPLEMENTS = get_name IMPLEMENTS = evaluate_long IMPLEMENTS = evaluate_double IMPLEMENTS = print @@ -42,6 +43,7 @@ typedef const char* string; /* to keep make_class.pl happy */ static void destroy(grib_context*,grib_expression* e); static void print(grib_context*,grib_expression*,grib_handle*); static void add_dependency(grib_expression* e, grib_accessor* observer); +static string get_name(grib_expression* e); static int native_type(grib_expression*,grib_handle*); static int evaluate_long(grib_expression*,grib_handle*,long*); static int evaluate_double(grib_expression*,grib_handle*,double*); @@ -65,7 +67,7 @@ static grib_expression_class _grib_expression_class_unop = { &print, &add_dependency, &native_type, - 0, + &get_name, &evaluate_long, &evaluate_double, 0, @@ -97,6 +99,12 @@ static int evaluate_double(grib_expression* g, grib_handle* h, double* dres) return GRIB_SUCCESS; } +static const char* get_name(grib_expression* g) +{ + grib_expression_unop* e = (grib_expression_unop*)g; + return grib_expression_get_name(e->exp); +} + static void print(grib_context* c, grib_expression* g, grib_handle* f) { grib_expression_unop* e = (grib_expression_unop*)g; @@ -111,7 +119,6 @@ static void destroy(grib_context* c, grib_expression* g) grib_expression_free(c, e->exp); } - static void add_dependency(grib_expression* g, grib_accessor* observer) { grib_expression_unop* e = (grib_expression_unop*)g; diff --git a/src/grib_iterator_class_healpix.cc b/src/grib_iterator_class_healpix.cc index 7befaf894..6a545b6c5 100644 --- a/src/grib_iterator_class_healpix.cc +++ b/src/grib_iterator_class_healpix.cc @@ -83,9 +83,9 @@ grib_iterator_class* grib_iterator_class_healpix = &_grib_iterator_class_healpix static void init_class(grib_iterator_class* c) { - c->previous = (*(c->super))->previous; - c->reset = (*(c->super))->reset; - c->has_next = (*(c->super))->has_next; + c->previous = (*(c->super))->previous; + c->reset = (*(c->super))->reset; + c->has_next = (*(c->super))->has_next; } /* END_CLASS_IMP */ diff --git a/tools/grib_histogram.cc b/tools/grib_histogram.cc index fa77614d7..6c84da43a 100644 --- a/tools/grib_histogram.cc +++ b/tools/grib_histogram.cc @@ -62,7 +62,6 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h) size_t last_size = 0; long missingValuesPresent; double delta; - int err = 0; double* values = NULL; size_t size; From e152763d7c67452e810e8f56b4e33ac78eee1c80 Mon Sep 17 00:00:00 2001 From: shahramn Date: Fri, 3 May 2024 19:25:25 +0100 Subject: [PATCH 12/14] ECC-1818: Add test --- tests/grib_grid_lamb_az_eq_area.sh | 65 ++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/tests/grib_grid_lamb_az_eq_area.sh b/tests/grib_grid_lamb_az_eq_area.sh index f3ed52588..a580d0498 100755 --- a/tests/grib_grid_lamb_az_eq_area.sh +++ b/tests/grib_grid_lamb_az_eq_area.sh @@ -11,21 +11,21 @@ label="grib_grid_lamb_az_eq_area_test" -GRIB_INFILE=${data_dir}/regular_gaussian_pressure_level_constant.grib2 -REF_FILE=grib_lamb_az_eq_area.ref +input=${data_dir}/regular_gaussian_pressure_level_constant.grib2 +tempRef=grib_lamb_az_eq_area.ref # Temporary files created for this test -FILTER_FILE=temp.$label.filter -GRIB_OUTFILE=temp.$label.grib2 -DATA_OUTFILE=temp.$label.txt -rm -f $FILTER_FILE $GRIB_OUTFILE $DATA_OUTFILE +tempFilt=temp.$label.filter +tempGrib=temp.$label.grib2 +tempOut=temp.$label.txt +rm -f $tempFilt $tempGrib $tempOut # -------------------- # Spherical Earth # -------------------- # Create a filter -cat > $FILTER_FILE< $tempFilt< $DATA_OUTFILE +${tools_dir}/grib_get_data $tempGrib > $tempOut # Compare output with reference. If the diff fails, script will immediately exit with status 1 -diff $REF_FILE $DATA_OUTFILE +diff $tempRef $tempOut -grib_check_key_equals $GRIB_OUTFILE standardParallelInDegrees,centralLongitudeInDegrees '48 9' -grib_check_key_equals $GRIB_OUTFILE xDirectionGridLengthInMetres,yDirectionGridLengthInMetres '5000 5000' +grib_check_key_equals $tempGrib standardParallelInDegrees,centralLongitudeInDegrees '48 9' +grib_check_key_equals $tempGrib xDirectionGridLengthInMetres,yDirectionGridLengthInMetres '5000 5000' # Nearest -${tools_dir}/grib_ls -l 67,-33,1 $GRIB_OUTFILE +${tools_dir}/grib_ls -l 67,-33,1 $tempGrib # jPointsAreConsecutive tempOutA=temp.$label.A.txt tempOutB=temp.$label.B.txt -${tools_dir}/grib_get_data -s jPointsAreConsecutive=0 $GRIB_OUTFILE > $tempOutA -${tools_dir}/grib_get_data -s jPointsAreConsecutive=1 $GRIB_OUTFILE > $tempOutB +${tools_dir}/grib_get_data -s jPointsAreConsecutive=0 $tempGrib > $tempOutA +${tools_dir}/grib_get_data -s jPointsAreConsecutive=1 $tempGrib > $tempOutB # Results should be different. set +e diff $tempOutA $tempOutB > /dev/null @@ -80,7 +80,7 @@ rm -f $tempOutA $tempOutB # Oblate spheroid # -------------------- -cat > $FILTER_FILE< $tempFilt< $DATA_OUTFILE +${tools_dir}/grib_get_data $tempGrib > $tempOut + +# ECC-1818 +# --------- +cat > $tempFilt< $tempOut # Clean up -rm -f $FILTER_FILE $DATA_OUTFILE -rm -f $GRIB_OUTFILE +rm -f $tempFilt $tempOut $tempGrib From 599fbbf375b2f5549f0bd0209d4c7003394bf681 Mon Sep 17 00:00:00 2001 From: shahramn Date: Sat, 4 May 2024 14:33:13 +0100 Subject: [PATCH 13/14] ECC-1819: GRIB: Keys iScansPositively and jScansNegatively should be read-only --- definitions/grib1/scanning_mode.def | 4 +- definitions/grib2/template.3.healpix.def | 4 +- .../grib2/template.3.scanning_mode.def | 4 +- .../grib3/template.4.scanning_mode.def | 2 +- src/grib_accessor.cc | 4 +- tests/grib_change_scanning.sh | 40 ++++++++++++++++--- 6 files changed, 44 insertions(+), 14 deletions(-) diff --git a/definitions/grib1/scanning_mode.def b/definitions/grib1/scanning_mode.def index 31a56e27d..19a7f8167 100644 --- a/definitions/grib1/scanning_mode.def +++ b/definitions/grib1/scanning_mode.def @@ -9,8 +9,8 @@ flagbit jScansPositively(scanningMode,6) : dump; flagbit jPointsAreConsecutive(scanningMode,5) : dump; constant alternativeRowScanning=0 : dump; -transient iScansPositively = !iScansNegatively : constraint; -transient jScansNegatively = !jScansPositively : constraint; +transient iScansPositively = !iScansNegatively : constraint, read_only; +transient jScansNegatively = !jScansPositively : constraint, read_only; alias geography.iScansNegatively=iScansNegatively; alias geography.jScansPositively=jScansPositively; diff --git a/definitions/grib2/template.3.healpix.def b/definitions/grib2/template.3.healpix.def index bf0429a5b..136904194 100644 --- a/definitions/grib2/template.3.healpix.def +++ b/definitions/grib2/template.3.healpix.def @@ -32,8 +32,8 @@ alias geography.orderingConvention = orderingConvention; flags[1] scanningMode 'grib2/tables/[tablesVersion]/3.13.table'; flagbit iScansNegatively(scanningMode,7) : dump; # WMO bit 1 flagbit jScansPositively(scanningMode,6) : dump; # WMO bit 2 -transient iScansPositively = !iScansNegatively : constraint; -transient jScansNegatively = !jScansPositively : constraint; +transient iScansPositively = !iScansNegatively : constraint, read_only; +transient jScansNegatively = !jScansPositively : constraint, read_only; iterator healpix(numberOfPoints,missingValue,values,Nside,orderingConvention); nearest healpix(values,radius,Nx,Ny); diff --git a/definitions/grib2/template.3.scanning_mode.def b/definitions/grib2/template.3.scanning_mode.def index 2eb2ca71e..1be608f41 100644 --- a/definitions/grib2/template.3.scanning_mode.def +++ b/definitions/grib2/template.3.scanning_mode.def @@ -20,8 +20,8 @@ alias geography.iScansNegatively=iScansNegatively; alias geography.jScansPositively=jScansPositively; alias geography.jPointsAreConsecutive=jPointsAreConsecutive; -transient iScansPositively = !iScansNegatively : constraint; -transient jScansNegatively = !jScansPositively : constraint; +transient iScansPositively = !iScansNegatively : constraint, read_only; +transient jScansNegatively = !jScansPositively : constraint, read_only; flagbit scanningMode5(scanningMode,3) = 0: read_only; flagbit scanningMode6(scanningMode,2) = 0: read_only; diff --git a/definitions/grib3/template.4.scanning_mode.def b/definitions/grib3/template.4.scanning_mode.def index 4fcd2fabb..31414321f 100644 --- a/definitions/grib3/template.4.scanning_mode.def +++ b/definitions/grib3/template.4.scanning_mode.def @@ -20,7 +20,7 @@ alias geography.iScansNegatively=iScansNegatively; alias geography.jScansPositively=jScansPositively; alias geography.jPointsAreConsecutive=jPointsAreConsecutive; -transient iScansPositively = !iScansNegatively : constraint; +transient iScansPositively = !iScansNegatively : constraint, read_only; flagbit scanningMode5(scanningMode,3) = 0: read_only; flagbit scanningMode6(scanningMode,2) = 0: read_only; diff --git a/src/grib_accessor.cc b/src/grib_accessor.cc index a08f5348e..a684b9e1d 100644 --- a/src/grib_accessor.cc +++ b/src/grib_accessor.cc @@ -112,7 +112,9 @@ int grib_pack_float(grib_accessor* a, const float* v, size_t* len) int grib_pack_expression(grib_accessor* a, grib_expression* e) { grib_accessor_class* c = a->cclass; - //grib_context_log(a->context, GRIB_LOG_DEBUG, "(%s)%s is packing (double) %g",(a->parent->owner)?(a->parent->owner->name):"root", a->name ,v?(*v):0); + // grib_context_log(a->context, GRIB_LOG_INFO, "....(%s)%s is packing", + // (a->parent->owner)?(a->parent->owner->name):"root", + // a->name); while (c) { if (c->pack_expression) { return c->pack_expression(a, e); diff --git a/tests/grib_change_scanning.sh b/tests/grib_change_scanning.sh index 25c5e005b..5f1d46596 100755 --- a/tests/grib_change_scanning.sh +++ b/tests/grib_change_scanning.sh @@ -11,6 +11,12 @@ . ./include.ctest.sh label="grib_change_scanning_test" +tempFilt=temp.$label.filt +tempGribA=temp.$label.A.grib +tempGribB=temp.$label.B.grib +tempText=temp.$label.txt +tempRef=temp.$label.ref + editions="1 2" gridTypes="regular_ll rotated_ll" @@ -77,12 +83,6 @@ done # alternativeRowScanning # ----------------------- -tempFilt=temp.$label.filt -tempGribA=temp.$label.A.grib -tempGribB=temp.$label.B.grib -tempText=temp.$label.txt -tempRef=temp.$label.ref - cat > $tempFilt </dev/null cmp $tempGribA $tempGribB + +# Check constraint keys follow (observe) their expressions +# -------------------------------------------------------- +cat > $tempFilt <$tempText + status=$? + set -e + [ $status -ne 0 ] + grep -q "Value is read only" $tempText + rm $tempText + done +done + # Clean up rm -f $tempFilt $tempGribA $tempGribB $tempRef $tempText rm -f ${data_dir}/scan1.grib ${data_dir}/scan.grib From 7382fb3ab7476d9265aacb863b7348388981555f Mon Sep 17 00:00:00 2001 From: shahramn Date: Sat, 4 May 2024 15:30:56 +0100 Subject: [PATCH 14/14] Tools: Documentation --- tools/bufr_ls.cc | 2 +- tools/grib_ls.cc | 2 +- tools/grib_options.cc | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/bufr_ls.cc b/tools/bufr_ls.cc index c57114617..b3ebaf531 100644 --- a/tools/bufr_ls.cc +++ b/tools/bufr_ls.cc @@ -17,7 +17,7 @@ grib_option grib_options[] = { { "F:", 0, 0, 1, 1, "%g" }, { "P:", 0, 0, 0, 1, 0 }, { "w:", 0, 0, 0, 1, 0 }, - { "j", 0, "JSON output\n", 0, 1, 0 }, + { "j", 0, "JSON output.\n", 0, 1, 0 }, /* {"B:",0,0,0,1,0}, */ { "s:", 0, 0, 0, 1, 0 }, { "n:", 0, 0, 1, 1, "ls" }, diff --git a/tools/grib_ls.cc b/tools/grib_ls.cc index 59f25306b..c5d06df01 100644 --- a/tools/grib_ls.cc +++ b/tools/grib_ls.cc @@ -17,7 +17,7 @@ grib_option grib_options[] = { { "F:", 0, 0, 1, 1, "%g" }, { "P:", 0, 0, 0, 1, 0 }, { "w:", 0, 0, 0, 1, 0 }, - { "j", 0, "JSON output\n", 0, 1, 0 }, + { "j", 0, "JSON output.\n", 0, 1, 0 }, { "B:", 0, 0, 0, 1, 0 }, { "l:", 0, 0, 0, 1, 0 }, { "s:", 0, 0, 0, 1, 0 }, diff --git a/tools/grib_options.cc b/tools/grib_options.cc index c15de1d80..b612db63a 100644 --- a/tools/grib_options.cc +++ b/tools/grib_options.cc @@ -39,7 +39,7 @@ static grib_options_help grib_options_help_list[] = { { "e:", "tolerance", "\n\t\tOnly values whose difference is more than tolerance are considered different.\n" }, { "f", 0, "Force. Force the execution not to fail on error.\n" }, { "F:", "format", "\n\t\tC style format for floating-point values.\n" }, - { "g", 0, "Copy GTS header. \n" }, + { "g", 0, "Copy GTS header.\n" }, { "G", 0, "GRIBEX compatibility mode.\n" }, { "i:", "index", "\n\t\tData value corresponding to the given index is printed.\n" }, @@ -81,7 +81,7 @@ static grib_options_help grib_options_help_list[] = { "\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" }, { "v", 0, "Verbose.\n" }, - { "7", 0, "Does not fail when the message has wrong length\n" }, + { "7", 0, "Does not fail when the message has wrong length.\n" }, { "A:", "absolute error\n", "\tCompare floating-point values using the absolute error as tolerance.\n\t\tDefault is absolute error=0\n" }, { "C", 0, "C code mode. A C code program generating the message is dumped.\n" }, @@ -98,7 +98,7 @@ static grib_options_help grib_options_help_list[] = { { "S", 0, "Strict. Only messages matching all the constraints are copied to" "\n\t\tthe output file\n" }, - { "T:", "T | B | M | A", "Message type. T->GTS, B->BUFR, M->METAR (Experimental), A->Any (Experimental).\n\t\t\t\tThe input file is interpreted according to the message type.\n" }, + { "T:", "T | B | A", "Message type. T->GTS, B->BUFR, A->Any (Experimental).\n\t\t\tThe input file is interpreted according to the message type.\n" }, { "V", 0, "Version.\n" }, { "W:", "width", "\n\t\tMinimum width of each column in output. Default is 10.\n" }, { "X:", "offset", "\n\t\tInput file offset in bytes. Processing of the input file will start from the given offset.\n" },