From fd98c80d525ee9de3e4a32db835df7dda01fd5b7 Mon Sep 17 00:00:00 2001 From: shahramn Date: Thu, 26 Dec 2024 11:14:30 +0000 Subject: [PATCH] ECC-1992: GRIB2: Concept array mapping --- src/accessor/grib_accessor_class_concept.cc | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/accessor/grib_accessor_class_concept.cc b/src/accessor/grib_accessor_class_concept.cc index 6b9313122..137f1f969 100644 --- a/src/accessor/grib_accessor_class_concept.cc +++ b/src/accessor/grib_accessor_class_concept.cc @@ -112,11 +112,12 @@ static int concept_condition_expression_true( return ok; } -// Return 1 (=True) or 0 (=False) +// Return 0 (=False) or >0 which is the count of matches +// See ECC-1992 static int concept_condition_iarray_true(grib_handle* h, grib_concept_condition* c) { long* val = NULL; - size_t size = 0, i; + size_t size = 0; int ret; //Boolean int err = 0; @@ -132,7 +133,7 @@ static int concept_condition_iarray_true(grib_handle* h, grib_concept_condition* return FALSE; } ret = TRUE; - for (i = 0; i < size; i++) { + for (size_t i = 0; i < size; i++) { if (val[i] != c->iarray->v[i]) { ret = FALSE; break; @@ -140,10 +141,11 @@ static int concept_condition_iarray_true(grib_handle* h, grib_concept_condition* } grib_context_free(h->context, val); - return ret; + if (ret) return (int)size; + return FALSE; } -// Return 1 (=True) or 0 (=False) +// Return 0 (=False) or >0 (=True) static int concept_condition_true( grib_handle* h, grib_concept_condition* c, std::unordered_map& memo) @@ -169,10 +171,11 @@ static const char* concept_evaluate(grib_accessor* a) grib_concept_condition* e = c->conditions; int cnt = 0; while (e) { - if (!concept_condition_true(h, e, memo)) + const int cc_count = concept_condition_true(h, e, memo); + if (cc_count == 0) // match failed break; e = e->next; - cnt++; + cnt += cc_count; // ECC-1992 } if (e == NULL) {