mirror of https://github.com/ecmwf/eccodes.git
ECC-992: Print details of matching concept
This commit is contained in:
parent
39eda000c8
commit
a1f28f4baf
|
@ -2108,6 +2108,44 @@ size_t sum_of_pl_array(const long* pl, size_t plsize)
|
|||
return count;
|
||||
}
|
||||
|
||||
static int get_concept_condition_string(grib_handle* h, const char* key, char* result)
|
||||
{
|
||||
int err = 0;
|
||||
int length = 0;
|
||||
char strVal[32]={0,};
|
||||
size_t len = sizeof(strVal);
|
||||
grib_concept_value* concept_value = NULL;
|
||||
grib_accessor* acc = grib_find_accessor(h, key);
|
||||
if (!acc) return GRIB_NOT_FOUND;
|
||||
|
||||
err = grib_get_string(h, key, strVal,&len);
|
||||
if (err) return GRIB_INTERNAL_ERROR;
|
||||
|
||||
concept_value = action_concept_get_concept(acc);
|
||||
while (concept_value) {
|
||||
int err = 0;
|
||||
long lres = 0;
|
||||
grib_concept_condition* concept_condition = concept_value->conditions;
|
||||
|
||||
if (strcmp(strVal, concept_value->name)==0) {
|
||||
while (concept_condition) {
|
||||
grib_expression* expression = concept_condition->expression;
|
||||
Assert(expression);
|
||||
err = grib_expression_evaluate_long(h,expression,&lres);
|
||||
if (err) return err;
|
||||
length += sprintf(result+length, "%s%s=%ld",
|
||||
(length==0?"":","),concept_condition->name, lres);
|
||||
|
||||
concept_condition = concept_condition->next;
|
||||
}
|
||||
}
|
||||
|
||||
concept_value = concept_value->next;
|
||||
}
|
||||
if (length == 0) return GRIB_CONCEPT_NO_MATCH;
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_util_grib_data_quality_check(grib_handle* h, double min_val, double max_val)
|
||||
{
|
||||
int err = 0;
|
||||
|
@ -2137,11 +2175,21 @@ int grib_util_grib_data_quality_check(grib_handle* h, double min_val, double max
|
|||
dmin_allowed = (double)min_field_value_allowed;
|
||||
dmax_allowed = (double)max_field_value_allowed;
|
||||
|
||||
if (min_val < dmin_allowed || max_val > dmax_allowed) {
|
||||
long paramId = 0;
|
||||
if (grib_get_long(h, "paramId", ¶mId) == GRIB_SUCCESS) {
|
||||
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 (min_val < dmin_allowed) {
|
||||
char description[1024] = {0,};
|
||||
if (get_concept_condition_string(h, "param_value_min", description)==GRIB_SUCCESS) {
|
||||
fprintf(stderr, "ECCODES %s : (%s): minimum (%g) is less than the allowable limit (%g)\n",
|
||||
(is_error? "ERROR":"WARNING"), description, min_val, dmin_allowed);
|
||||
}
|
||||
if (is_error) {
|
||||
return GRIB_OUT_OF_RANGE; /* Failure */
|
||||
}
|
||||
}
|
||||
if (max_val > dmax_allowed) {
|
||||
char description[1024] = {0,};
|
||||
if (get_concept_condition_string(h, "param_value_max", description)==GRIB_SUCCESS) {
|
||||
fprintf(stderr, "ECCODES %s : (%s): maximum (%g) is more than the allowable limit (%g)\n",
|
||||
(is_error? "ERROR":"WARNING"), description, max_val, dmax_allowed);
|
||||
}
|
||||
if (is_error) {
|
||||
return GRIB_OUT_OF_RANGE; /* Failure */
|
||||
|
|
|
@ -39,13 +39,13 @@ ${tools_dir}/grib_copy -r $tempOut /dev/null 2>$tempErr
|
|||
status=$?
|
||||
set -e
|
||||
[ $status -ne 0 ]
|
||||
grep -q 'outside allowable limits' $tempErr
|
||||
grep -q 'more than the allowable limit' $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
|
||||
grep -q 'more than the allowable limit' $tempErr
|
||||
|
||||
|
||||
# Data quality checks enabled. Scaling should fail
|
||||
|
@ -56,7 +56,7 @@ status=$?
|
|||
set -e
|
||||
[ $status -ne 0 ]
|
||||
grep -q 'GRIB1 simple packing: unable to set values' $tempErr
|
||||
grep -q 'outside allowable limits' $tempErr
|
||||
grep -q 'allowable limit' $tempErr
|
||||
|
||||
set +e
|
||||
${tools_dir}/grib_set -s scaleValuesBy=100 $input2 $tempOut 2>$tempErr
|
||||
|
@ -64,7 +64,7 @@ status=$?
|
|||
set -e
|
||||
[ $status -ne 0 ]
|
||||
grep -q 'GRIB2 simple packing: unable to set values' $tempErr
|
||||
grep -q 'outside allowable limits' $tempErr
|
||||
grep -q 'allowable limit' $tempErr
|
||||
|
||||
|
||||
# Override the defaults
|
||||
|
|
Loading…
Reference in New Issue