mirror of https://github.com/ecmwf/eccodes.git
ECC-992: get_concept_condition_string: Add optional argument for concept value
This commit is contained in:
parent
e9045909f3
commit
48020d09fd
|
@ -307,21 +307,27 @@ static grib_concept_value* get_concept(grib_handle* h, grib_action_concept* self
|
|||
}
|
||||
|
||||
/* Caller has to allocate space for the result.
|
||||
* INPUTS: h, key and value (can be NULL)
|
||||
* OUTPUT: result
|
||||
* Example: key='typeOfLevel' whose value is 'mixedLayerDepth',
|
||||
* result='typeOfFirstFixedSurface=169,typeOfSecondFixedSurface=255'
|
||||
*/
|
||||
int get_concept_condition_string(grib_handle* h, const char* key, char* result)
|
||||
int get_concept_condition_string(grib_handle* h, const char* key, const char* value, char* result)
|
||||
{
|
||||
int err = 0;
|
||||
int length = 0;
|
||||
char strVal[64]={0,};
|
||||
const char* pValue = value;
|
||||
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;
|
||||
|
||||
if (!value) {
|
||||
err = grib_get_string(h, key, strVal,&len);
|
||||
if (err) return GRIB_INTERNAL_ERROR;
|
||||
pValue = strVal;
|
||||
}
|
||||
|
||||
concept_value = action_concept_get_concept(acc);
|
||||
while (concept_value) {
|
||||
|
@ -329,10 +335,11 @@ int get_concept_condition_string(grib_handle* h, const char* key, char* result)
|
|||
long lres = 0;
|
||||
grib_concept_condition* concept_condition = concept_value->conditions;
|
||||
|
||||
if (strcmp(strVal, concept_value->name)==0) {
|
||||
if (strcmp(pValue, concept_value->name)==0) {
|
||||
while (concept_condition) {
|
||||
grib_expression* expression = concept_condition->expression;
|
||||
Assert(expression);
|
||||
/* TODO: Call concept_condition_expression_true to check if this condition is actually TRUE! */
|
||||
err = grib_expression_evaluate_long(h,expression,&lres);
|
||||
if (err) return err;
|
||||
length += sprintf(result+length, "%s%s=%ld",
|
||||
|
|
|
@ -615,6 +615,14 @@ static int unpack_string (grib_accessor* a, char* val, size_t *len)
|
|||
}
|
||||
strcpy(val,p);
|
||||
*len = slen;
|
||||
#if 0
|
||||
if (a->context->debug==1) {
|
||||
int err = 0;
|
||||
char result[1024] = {0,};
|
||||
err = get_concept_condition_string(grib_handle_of_accessor(a), a->name, val, result);
|
||||
if (!err) fprintf(stderr, "ECCODES DEBUG concept name=%s, value=%s, conditions=%s\n", a->name, val, result);
|
||||
}
|
||||
#endif
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ grib_action *grib_action_create_when(grib_context *context, grib_expression *exp
|
|||
grib_concept_value *action_concept_get_concept(grib_accessor *a);
|
||||
int action_concept_get_nofail(grib_accessor *a);
|
||||
grib_action *grib_action_create_concept(grib_context *context, const char *name, grib_concept_value *concept, const char *basename, const char *name_space, const char *defaultkey, const char *masterDir, const char *localDir, const char *ecmfDir, int flags, int nofail);
|
||||
int get_concept_condition_string(grib_handle* h, const char* key, char* result);
|
||||
int get_concept_condition_string(grib_handle* h, const char* key, const char* value, char* result);
|
||||
|
||||
/* action_class_hash_array.c */
|
||||
grib_action *grib_action_create_hash_array(grib_context *context, const char *name, grib_hash_array_value *hash_array, const char *basename, const char *name_space, const char *defaultkey, const char *masterDir, const char *localDir, const char *ecmfDir, int flags, int nofail);
|
||||
|
|
|
@ -2139,7 +2139,7 @@ int grib_util_grib_data_quality_check(grib_handle* h, double min_val, double max
|
|||
|
||||
if (min_val < dmin_allowed) {
|
||||
char description[1024] = {0,};
|
||||
if (get_concept_condition_string(h, "param_value_min", description)==GRIB_SUCCESS) {
|
||||
if (get_concept_condition_string(h, "param_value_min", NULL, 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);
|
||||
}
|
||||
|
@ -2149,7 +2149,7 @@ int grib_util_grib_data_quality_check(grib_handle* h, double min_val, double max
|
|||
}
|
||||
if (max_val > dmax_allowed) {
|
||||
char description[1024] = {0,};
|
||||
if (get_concept_condition_string(h, "param_value_max", description)==GRIB_SUCCESS) {
|
||||
if (get_concept_condition_string(h, "param_value_max", NULL, 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);
|
||||
}
|
||||
|
|
|
@ -1428,18 +1428,18 @@ static void test_assertion_catching()
|
|||
static void test_concept_condition_strings()
|
||||
{
|
||||
int err = 0;
|
||||
char result[128] = {0,};
|
||||
char result[1024] = {0,};
|
||||
grib_handle* h = grib_handle_new_from_samples(0, "GRIB2");
|
||||
|
||||
err = get_concept_condition_string(h, "typeOfLevel", result);
|
||||
err = get_concept_condition_string(h, "typeOfLevel", NULL, result);
|
||||
assert ( !err );
|
||||
assert( strcmp(result, "typeOfFirstFixedSurface=1,typeOfSecondFixedSurface=255")==0 );
|
||||
|
||||
err = get_concept_condition_string(h, "paramId", result);
|
||||
err = get_concept_condition_string(h, "paramId", NULL, result);
|
||||
assert ( !err );
|
||||
assert( strcmp(result, "discipline=0,parameterCategory=0,parameterNumber=0")==0 );
|
||||
|
||||
err = get_concept_condition_string(h, "gridType", result);
|
||||
err = get_concept_condition_string(h, "gridType", NULL, result);
|
||||
assert ( !err );
|
||||
/*printf("%s\n", result);*/
|
||||
assert( strcmp(result, "gridDefinitionTemplateNumber=0,PLPresent=0")==0 );
|
||||
|
|
Loading…
Reference in New Issue