diff --git a/src/grib_util.c b/src/grib_util.c index fda2f3510..0fba4b86a 100644 --- a/src/grib_util.c +++ b/src/grib_util.c @@ -2113,16 +2113,24 @@ int grib_util_grib_data_quality_check(grib_handle* h, double min_val, double max int err = 0; long min_field_value_allowed=0, max_field_value_allowed=0; double dmin_allowed=0, dmax_allowed=0; + grib_context* ctx = h->context; + int is_error = 1; + /* + * If grib_data_quality_checks == 1, limits failure results in an error + * If grib_data_quality_checks == 2, limits failure results in a warning + */ + Assert( ctx->grib_data_quality_checks == 1 || ctx->grib_data_quality_checks == 2 ); + is_error = (ctx->grib_data_quality_checks == 1); /* The limit keys must exist if we are here */ err = grib_get_long(h, "param_value_min", &min_field_value_allowed); if (err) { - grib_context_log(h->context, GRIB_LOG_ERROR,"grib_data_quality_check: Could not get param_value_min"); + grib_context_log(ctx, GRIB_LOG_ERROR,"grib_data_quality_check: Could not get param_value_min"); return err; } err = grib_get_long(h, "param_value_max", &max_field_value_allowed); if (err) { - grib_context_log(h->context, GRIB_LOG_ERROR,"grib_data_quality_check: Could not get param_value_max"); + grib_context_log(ctx, GRIB_LOG_ERROR,"grib_data_quality_check: Could not get param_value_max"); return err; } @@ -2132,11 +2140,12 @@ int grib_util_grib_data_quality_check(grib_handle* h, double min_val, double max if (min_val < dmin_allowed || max_val > dmax_allowed) { long paramId = 0; if (grib_get_long(h, "paramId", ¶mId) == GRIB_SUCCESS) { - grib_context_log(h->context, GRIB_LOG_ERROR, - "Parameter %ld: min/max (%g, %g) is outside allowable limits (%g, %g)", - paramId, min_val, max_val, dmin_allowed, dmax_allowed); + fprintf(stderr, "ECCODES %s : Parameter %ld: min/max (%g, %g) is outside allowable limits (%g, %g)\n", + (is_error? "ERROR":"WARNING"), paramId, min_val, max_val, dmin_allowed, dmax_allowed); + } + if (is_error) { + return GRIB_OUT_OF_RANGE; /* Failure */ } - return GRIB_OUT_OF_RANGE; } return GRIB_SUCCESS; diff --git a/tests/grib_data_quality_checks.sh b/tests/grib_data_quality_checks.sh index 05f1e1cac..c76574f34 100755 --- a/tests/grib_data_quality_checks.sh +++ b/tests/grib_data_quality_checks.sh @@ -41,6 +41,13 @@ set -e [ $status -ne 0 ] grep -q 'outside allowable limits' $tempErr + +# Data quality checks enabled but only as a warning. Repacking should pass +export ECCODES_GRIB_DATA_QUALITY_CHECKS=2 +${tools_dir}/grib_copy -r $tempOut /dev/null 2>$tempErr +grep -q 'outside allowable limits' $tempErr + + # Data quality checks enabled. Scaling should fail export ECCODES_GRIB_DATA_QUALITY_CHECKS=1 set +e @@ -59,6 +66,7 @@ set -e grep -q 'GRIB2 simple packing: unable to set values' $tempErr grep -q 'outside allowable limits' $tempErr + # Override the defaults # ---------------------- tempDir=tempdir.$label