ECC-523: numberOfMissingValues incorrect with grid_complex_spatial_differencing

This commit is contained in:
Shahram Najm 2022-11-27 17:46:00 +00:00
parent e9af73633d
commit 0c5b8c0330
3 changed files with 38 additions and 5 deletions

View File

@ -45,3 +45,8 @@ meta values data_apply_bitmap(codedValues,
alias data.packedValues = codedValues;
template statistics "common/statistics_grid.def";
if(missingValueManagementUsed) {
remove numberOfMissing;
meta numberOfMissing count_missing(bitmap,unusedBitsInBitmap,numberOfDataPoints,missingValueManagementUsed) : dump;
alias numberOfMissingValues=numberOfMissing;
}

View File

@ -42,3 +42,8 @@ meta values data_apply_bitmap(codedValues,
alias data.packedValues=codedValues;
template statistics "common/statistics_grid.def";
if(missingValueManagementUsed) {
remove numberOfMissing;
meta numberOfMissing count_missing(bitmap,unusedBitsInBitmap,numberOfDataPoints,missingValueManagementUsed) : dump;
alias numberOfMissingValues=numberOfMissing;
}

View File

@ -21,6 +21,7 @@
MEMBERS = const char* bitmap
MEMBERS = const char* unusedBitsInBitmap
MEMBERS = const char* numberOfDataPoints
MEMBERS = const char* missingValueManagementUsed
END_CLASS_DEF
*/
@ -49,6 +50,7 @@ typedef struct grib_accessor_count_missing
const char* bitmap;
const char* unusedBitsInBitmap;
const char* numberOfDataPoints;
const char* missingValueManagementUsed;
} grib_accessor_count_missing;
extern grib_accessor_class* grib_accessor_class_long;
@ -181,11 +183,13 @@ static void init(grib_accessor* a, const long len, grib_arguments* arg)
{
int n = 0;
grib_accessor_count_missing* self = (grib_accessor_count_missing*)a;
grib_handle* h = grib_handle_of_accessor(a);
a->length = 0;
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
self->bitmap = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++);
self->unusedBitsInBitmap = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++);
self->numberOfDataPoints = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++);
self->bitmap = grib_arguments_get_name(h, arg, n++);
self->unusedBitsInBitmap = grib_arguments_get_name(h, arg, n++);
self->numberOfDataPoints = grib_arguments_get_name(h, arg, n++);
self->missingValueManagementUsed = grib_arguments_get_name(h, arg, n++); /* Can be NULL */
}
static const int used[] = { 0, 1, 3, 7, 15, 31, 63, 127, 255 };
@ -202,10 +206,29 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len)
grib_handle* h = grib_handle_of_accessor(a);
grib_accessor* bitmap = grib_find_accessor(h, self->bitmap);
*val = 0;
*val = 0; /* By default assume none are missing */
*len = 1;
if (!bitmap)
if (!bitmap) {
long mvmu = 0;
if (self->missingValueManagementUsed &&
grib_get_long(h, self->missingValueManagementUsed, &mvmu) == GRIB_SUCCESS && mvmu != 0)
{
long count_of_missing = 0;
size_t vsize = 0, ii=0;
double* values = NULL;
double mv = 0;
grib_get_double(h, "missingValue", &mv);
grib_get_size(h, "values", &vsize);
values = (double*)grib_context_malloc(h->context, vsize * sizeof(double));
grib_get_double_array(h, "values", values, &vsize);
for (ii = 0; ii < vsize; ii++) {
if (values[ii] == mv) ++count_of_missing;
}
grib_context_free(h->context, values);
*val = count_of_missing;
}
return GRIB_SUCCESS;
}
size = grib_byte_count(bitmap);
offset = grib_byte_offset(bitmap);