diff --git a/src/grib_accessor_class_transient_darray.cc b/src/grib_accessor_class_transient_darray.cc index 9a316459b..ba830849a 100644 --- a/src/grib_accessor_class_transient_darray.cc +++ b/src/grib_accessor_class_transient_darray.cc @@ -19,7 +19,7 @@ IMPLEMENTS = unpack_double;pack_double IMPLEMENTS = unpack_long;pack_long;destroy IMPLEMENTS = init;dump;value_count - IMPLEMENTS = compare;get_native_type + IMPLEMENTS = get_native_type MEMBERS=grib_darray* arr MEMBERS=int type; END_CLASS_DEF @@ -45,7 +45,6 @@ static int value_count(grib_accessor*, long*); static void destroy(grib_context*, grib_accessor*); static void dump(grib_accessor*, grib_dumper*); static void init(grib_accessor*, const long, grib_arguments*); -static int compare(grib_accessor*, grib_accessor*); typedef struct grib_accessor_transient_darray { @@ -96,7 +95,7 @@ static grib_accessor_class _grib_accessor_class_transient_darray = { 0, /* resize */ 0, /* nearest_smaller_value */ 0, /* next accessor */ - &compare, /* compare vs. another accessor */ + 0, /* compare vs. another accessor */ 0, /* unpack only ith value (double) */ 0, /* unpack only ith value (float) */ 0, /* unpack a given set of elements (double) */ @@ -119,23 +118,20 @@ static void init(grib_accessor* a, const long length, grib_arguments* args) a->length = 0; } - static void dump(grib_accessor* a, grib_dumper* dumper) { - /* grib_accessor_transient_darray *self = (grib_accessor_transient_darray*)a; */ grib_dump_double(dumper, a, NULL); } static int pack_double(grib_accessor* a, const double* val, size_t* len) { grib_accessor_transient_darray* self = (grib_accessor_transient_darray*)a; - size_t i; if (self->arr) grib_darray_delete(a->context, self->arr); self->arr = grib_darray_new(a->context, *len, 10); - for (i = 0; i < *len; i++) + for (size_t i = 0; i < *len; i++) grib_darray_push(a->context, self->arr, val[i]); return GRIB_SUCCESS; @@ -144,13 +140,12 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) static int pack_long(grib_accessor* a, const long* val, size_t* len) { grib_accessor_transient_darray* self = (grib_accessor_transient_darray*)a; - size_t i; if (self->arr) grib_darray_delete(a->context, self->arr); self->arr = grib_darray_new(a->context, *len, 10); - for (i = 0; i < *len; i++) + for (size_t i = 0; i < *len; i++) grib_darray_push(a->context, self->arr, (double)val[i]); return GRIB_SUCCESS; @@ -159,8 +154,7 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) static int unpack_double(grib_accessor* a, double* val, size_t* len) { grib_accessor_transient_darray* self = (grib_accessor_transient_darray*)a; - long count = 0; - size_t i; + long count = 0; value_count(a, &count); @@ -170,17 +164,16 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) } *len = count; - for (i = 0; i < *len; i++) + for (size_t i = 0; i < *len; i++) val[i] = self->arr->v[i]; - return GRIB_SUCCESS; } + static int unpack_long(grib_accessor* a, long* val, size_t* len) { grib_accessor_transient_darray* self = (grib_accessor_transient_darray*)a; - long count = 0; - size_t i; + long count = 0; value_count(a, &count); @@ -190,14 +183,12 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) } *len = count; - for (i = 0; i < *len; i++) + for (size_t i = 0; i < *len; i++) val[i] = (long)self->arr->v[i]; - return GRIB_SUCCESS; } - static void destroy(grib_context* c, grib_accessor* a) { grib_accessor_transient_darray* self = (grib_accessor_transient_darray*)a; @@ -216,51 +207,8 @@ static int value_count(grib_accessor* a, long* count) return 0; } -static int compare(grib_accessor* a, grib_accessor* b) -{ - int retval = 0; - double* aval = 0; - double* bval = 0; - - size_t alen = 0; - size_t blen = 0; - int err = 0; - long count = 0; - - err = grib_value_count(a, &count); - if (err) - return err; - alen = count; - - err = grib_value_count(b, &count); - if (err) - return err; - blen = count; - - if (alen != blen) - return GRIB_COUNT_MISMATCH; - - aval = (double*)grib_context_malloc(a->context, alen * sizeof(double)); - bval = (double*)grib_context_malloc(b->context, blen * sizeof(double)); - - grib_unpack_double(a, aval, &alen); - grib_unpack_double(b, bval, &blen); - - retval = GRIB_SUCCESS; - while (alen != 0) { - if (*bval != *aval) - retval = GRIB_DOUBLE_VALUE_MISMATCH; - alen--; - } - - grib_context_free(a->context, aval); - grib_context_free(b->context, bval); - - return retval; -} - static int get_native_type(grib_accessor* a) { - grib_accessor_transient_darray* self = (grib_accessor_transient_darray*)a; + const grib_accessor_transient_darray* self = (grib_accessor_transient_darray*)a; return self->type; } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 01c2c59b2..7929676db 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -96,6 +96,7 @@ if( HAVE_BUILD_TOOLS ) grib_ifsParam grib_packing_order filter_substr + filter_transient_darray grib_uerra grib_ecpoint grib_s2s diff --git a/tests/filter_transient_darray.sh b/tests/filter_transient_darray.sh new file mode 100755 index 000000000..49024fa79 --- /dev/null +++ b/tests/filter_transient_darray.sh @@ -0,0 +1,43 @@ +#!/bin/sh +# (C) Copyright 2005- ECMWF. +# +# This software is licensed under the terms of the Apache Licence Version 2.0 +# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +# +# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by +# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. +# + +. ./include.ctest.sh + +label="filter_transient_darray_test" + +tempOut=temp.$label.out +tempRef=temp.$label.ref +tempFilt=temp.$label.filt +sample=$ECCODES_SAMPLES_PATH/GRIB2.tmpl + +cat > $tempFilt < $tempOut + +cat > $tempRef <