diff --git a/data/statistics.out.good b/data/statistics.out.good index a564714b9..f7939dba8 100644 --- a/data/statistics.out.good +++ b/data/statistics.out.good @@ -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 diff --git a/src/accessor/grib_accessor_class_dirty.cc b/src/accessor/grib_accessor_class_dirty.cc index 73f11c9d7..80c51835e 100644 --- a/src/accessor/grib_accessor_class_dirty.cc +++ b/src/accessor/grib_accessor_class_dirty.cc @@ -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; - - *val = 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; } diff --git a/src/accessor/grib_accessor_class_statistics.cc b/src/accessor/grib_accessor_class_statistics.cc index 1e56f8a12..7e4a4eca8 100644 --- a/src/accessor/grib_accessor_class_statistics.cc +++ b/src/accessor/grib_accessor_class_statistics.cc @@ -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); diff --git a/src/accessor/grib_accessor_class_vector.cc b/src/accessor/grib_accessor_class_vector.cc index f08809f6f..a5def256f 100644 --- a/src/accessor/grib_accessor_class_vector.cc +++ b/src/accessor/grib_accessor_class_vector.cc @@ -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]; diff --git a/tests/grib_statistics.sh b/tests/grib_statistics.sh index 6863d591a..9cf7719e3 100755 --- a/tests/grib_statistics.sh +++ b/tests/grib_statistics.sh @@ -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< statistics.out