mirror of https://github.com/ecmwf/eccodes.git
ECC-1885: GRIB: The 'dirty_statistics' key is always 1
This commit is contained in:
parent
a85d671ace
commit
52ba802da4
|
@ -1,4 +1,7 @@
|
|||
Will set values...
|
||||
values=2 2 2 2
|
||||
max=2 min=2 average=2
|
||||
max=2 min=2 average=2
|
||||
Will set values...
|
||||
values=2 5 2 2
|
||||
max=5 min=2 average=2.75
|
||||
|
|
|
@ -30,9 +30,10 @@ int grib_accessor_class_dirty_t::pack_long(grib_accessor* a, const long* val, si
|
|||
grib_accessor_dirty_t* self = (grib_accessor_dirty_t*)a;
|
||||
grib_accessor* x = grib_find_accessor(grib_handle_of_accessor(a), self->accessor);
|
||||
|
||||
if (x)
|
||||
if (x) {
|
||||
//printf("\ngrib_accessor_class_dirty_t::pack_long: Setting dirty to %ld on %s\n", *val, x->name);
|
||||
x->dirty = *val;
|
||||
|
||||
}
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -41,10 +42,11 @@ int grib_accessor_class_dirty_t::unpack_long(grib_accessor* a, long* val, size_t
|
|||
grib_accessor_dirty_t* self = (grib_accessor_dirty_t*)a;
|
||||
grib_accessor* x = grib_find_accessor(grib_handle_of_accessor(a), self->accessor);
|
||||
|
||||
if (x)
|
||||
x->dirty = 1;
|
||||
|
||||
if (x) {
|
||||
//printf("\ngrib_accessor_class_dirty_t::unpack_long: Getting dirty for %s\n", x->name);
|
||||
*val = x->dirty;
|
||||
} else {
|
||||
*val = 1;
|
||||
|
||||
}
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -114,7 +114,7 @@ int grib_accessor_class_statistics_t::unpack_double(grib_accessor* a, double* va
|
|||
avg += value;
|
||||
}
|
||||
}
|
||||
/*printf("stats.......... number_of_missing=%ld\n", number_of_missing);*/
|
||||
|
||||
/* Don't divide by zero if all values are missing! */
|
||||
if (size != number_of_missing) {
|
||||
avg /= (size - number_of_missing);
|
||||
|
@ -148,6 +148,8 @@ int grib_accessor_class_statistics_t::unpack_double(grib_accessor* a, double* va
|
|||
skew = m3 / (sd * sd * sd);
|
||||
kurt = m4 / (m2 * m2) - 3.0;
|
||||
}
|
||||
|
||||
//printf("\ngrib_accessor_class_statistics_t::unpack_double Computed. So setting dirty to 0....... \n");
|
||||
a->dirty = 0;
|
||||
|
||||
grib_context_free(c, values);
|
||||
|
|
|
@ -46,6 +46,7 @@ int grib_accessor_class_vector_t::unpack_double(grib_accessor* a, double* val, s
|
|||
}
|
||||
|
||||
if (va->dirty) {
|
||||
//printf("\ngrib_accessor_class_vector_t::unpack_double accessor=%s is DIRTY\n",a->name);
|
||||
grib_get_size(grib_handle_of_accessor(a), self->vector, &size);
|
||||
stat = (double*)grib_context_malloc_clear(a->context, sizeof(double) * size);
|
||||
err = va->unpack_double(stat, &size);
|
||||
|
@ -53,6 +54,9 @@ int grib_accessor_class_vector_t::unpack_double(grib_accessor* a, double* val, s
|
|||
if (err)
|
||||
return err;
|
||||
}
|
||||
else {
|
||||
//printf("\ngrib_accessor_class_vector_t::unpack_double accessor=%s is CLEAN\n",a->name);
|
||||
}
|
||||
|
||||
*val = v->v[self->index];
|
||||
|
||||
|
|
|
@ -18,16 +18,28 @@ files="regular_latlon_surface.grib2 regular_latlon_surface.grib1"
|
|||
|
||||
for file in $files; do
|
||||
|
||||
# Note: When we get min,max etc for the 1st time, dirty_statistics is 1
|
||||
# so the statistics accessor will decode the data values (because dirty_statistics==1)
|
||||
# Once it is finished, it sets dirty_statistics to 0.
|
||||
# If you get min,max again, no computation is done (because dirty_statistics==0)
|
||||
# But once the data values are changed, then dirty_statistics is once again 1
|
||||
cat >statistics.filter<<EOF
|
||||
set Ni=2;
|
||||
set Nj=2;
|
||||
set decimalPrecision=4;
|
||||
print "Will set values...";
|
||||
set values={2.0,2.0,2.0,2.0};
|
||||
assert(dirty_statistics == 1);
|
||||
print "values=[values]";
|
||||
print "max=[max] min=[min] average=[average]";
|
||||
assert(dirty_statistics == 0);
|
||||
print "max=[max] min=[min] average=[average]";
|
||||
print "Will set values...";
|
||||
set values={2.0,5.0,2.0,2.0};
|
||||
assert(dirty_statistics == 1);
|
||||
print "values=[values]";
|
||||
print "max=[max] min=[min] average=[average]";
|
||||
assert(dirty_statistics == 0);
|
||||
EOF
|
||||
|
||||
${tools_dir}/grib_filter statistics.filter ${data_dir}/$file > statistics.out
|
||||
|
|
Loading…
Reference in New Issue