mirror of https://github.com/ecmwf/eccodes.git
ECC-992: Fix case when concept condition has a string value
This commit is contained in:
parent
4308492cb0
commit
397ec353a6
|
@ -306,7 +306,8 @@ static grib_concept_value* get_concept(grib_handle* h, grib_action_concept* self
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int concept_condition_expression_true(grib_handle* h,grib_concept_condition* c) {
|
static int concept_condition_expression_true(grib_handle* h, grib_concept_condition* c, char* exprVal)
|
||||||
|
{
|
||||||
long lval;
|
long lval;
|
||||||
long lres=0;
|
long lres=0;
|
||||||
int ok = 0;
|
int ok = 0;
|
||||||
|
@ -319,6 +320,7 @@ static int concept_condition_expression_true(grib_handle* h,grib_concept_conditi
|
||||||
grib_expression_evaluate_long(h,c->expression,&lres);
|
grib_expression_evaluate_long(h,c->expression,&lres);
|
||||||
ok = (grib_get_long(h,c->name,&lval) == GRIB_SUCCESS) &&
|
ok = (grib_get_long(h,c->name,&lval) == GRIB_SUCCESS) &&
|
||||||
(lval == lres);
|
(lval == lres);
|
||||||
|
if (ok) sprintf(exprVal, "%ld", lres);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GRIB_TYPE_DOUBLE: {
|
case GRIB_TYPE_DOUBLE: {
|
||||||
|
@ -327,6 +329,7 @@ static int concept_condition_expression_true(grib_handle* h,grib_concept_conditi
|
||||||
grib_expression_evaluate_double(h,c->expression,&dres);
|
grib_expression_evaluate_double(h,c->expression,&dres);
|
||||||
ok = (grib_get_double(h,c->name,&dval) == GRIB_SUCCESS) &&
|
ok = (grib_get_double(h,c->name,&dval) == GRIB_SUCCESS) &&
|
||||||
(dval == dres);
|
(dval == dres);
|
||||||
|
if (ok) sprintf(exprVal, "%g", dres);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,6 +343,7 @@ static int concept_condition_expression_true(grib_handle* h,grib_concept_conditi
|
||||||
ok = (grib_get_string(h,c->name,buf,&len) == GRIB_SUCCESS) &&
|
ok = (grib_get_string(h,c->name,buf,&len) == GRIB_SUCCESS) &&
|
||||||
((cval = grib_expression_evaluate_string(h,c->expression,tmp,&size,&err)) != NULL) &&
|
((cval = grib_expression_evaluate_string(h,c->expression,tmp,&size,&err)) != NULL) &&
|
||||||
(err==0) && (strcmp(buf,cval) == 0);
|
(err==0) && (strcmp(buf,cval) == 0);
|
||||||
|
if (ok) sprintf(exprVal, "%s", cval);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,6 +365,7 @@ int get_concept_condition_string(grib_handle* h, const char* key, const char* va
|
||||||
int err = 0;
|
int err = 0;
|
||||||
int length = 0;
|
int length = 0;
|
||||||
char strVal[64]={0,};
|
char strVal[64]={0,};
|
||||||
|
char exprVal[256]={0,};
|
||||||
const char* pValue = value;
|
const char* pValue = value;
|
||||||
size_t len = sizeof(strVal);
|
size_t len = sizeof(strVal);
|
||||||
grib_concept_value* concept_value = NULL;
|
grib_concept_value* concept_value = NULL;
|
||||||
|
@ -375,19 +380,15 @@ int get_concept_condition_string(grib_handle* h, const char* key, const char* va
|
||||||
|
|
||||||
concept_value = action_concept_get_concept(acc);
|
concept_value = action_concept_get_concept(acc);
|
||||||
while (concept_value) {
|
while (concept_value) {
|
||||||
int err = 0;
|
|
||||||
long lres = 0;
|
|
||||||
grib_concept_condition* concept_condition = concept_value->conditions;
|
grib_concept_condition* concept_condition = concept_value->conditions;
|
||||||
|
|
||||||
if (strcmp(pValue, concept_value->name)==0) {
|
if (strcmp(pValue, concept_value->name)==0) {
|
||||||
while (concept_condition) {
|
while (concept_condition) {
|
||||||
grib_expression* expression = concept_condition->expression;
|
grib_expression* expression = concept_condition->expression;
|
||||||
Assert(expression);
|
Assert(expression);
|
||||||
if (concept_condition_expression_true(h, concept_condition)) {
|
if (concept_condition_expression_true(h, concept_condition, exprVal)) {
|
||||||
err = grib_expression_evaluate_long(h,expression,&lres);
|
length += sprintf(result+length, "%s%s=%s",
|
||||||
if (err) return err;
|
(length==0?"":","),concept_condition->name, exprVal);
|
||||||
length += sprintf(result+length, "%s%s=%ld",
|
|
||||||
(length==0?"":","),concept_condition->name, lres);
|
|
||||||
}
|
}
|
||||||
concept_condition = concept_condition->next;
|
concept_condition = concept_condition->next;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1443,6 +1443,11 @@ static void test_concept_condition_strings()
|
||||||
assert ( !err );
|
assert ( !err );
|
||||||
/*printf("%s\n", result);*/
|
/*printf("%s\n", result);*/
|
||||||
assert( strcmp(result, "gridDefinitionTemplateNumber=0,PLPresent=0")==0 );
|
assert( strcmp(result, "gridDefinitionTemplateNumber=0,PLPresent=0")==0 );
|
||||||
|
|
||||||
|
err = get_concept_condition_string(h, "stepType", NULL, result);
|
||||||
|
assert ( !err );
|
||||||
|
assert( strcmp(result, "selectStepTemplateInstant=1,stepTypeInternal=instant")==0 );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
|
|
Loading…
Reference in New Issue