diff --git a/src/accessor/grib_accessor.h b/src/accessor/grib_accessor.h index 5f9c2481b..3a9578127 100644 --- a/src/accessor/grib_accessor.h +++ b/src/accessor/grib_accessor.h @@ -60,7 +60,6 @@ public: virtual grib_accessor* next_accessor() = 0; virtual void resize(size_t new_size) = 0; virtual void destroy(grib_context* ct) = 0; - virtual int compare_accessors(grib_accessor* a2, int compare_flags); virtual int compare(grib_accessor*) = 0; virtual int add_attribute(grib_accessor* attr, int nest_if_clash); @@ -78,8 +77,7 @@ public: virtual grib_accessor* make_clone(grib_section*, int*) = 0; public: - // private: - // TODO(maee): make members private + // TODO(maee): make private grib_context* context_; const char* name_; /** < name of the accessor */ const char* class_name_; /** < name of the class (Artifact from C version of ecCodes) */ diff --git a/src/accessor/grib_accessor_class_abstract_long_vector.h b/src/accessor/grib_accessor_class_abstract_long_vector.h index bf2786d82..743c9733b 100644 --- a/src/accessor/grib_accessor_class_abstract_long_vector.h +++ b/src/accessor/grib_accessor_class_abstract_long_vector.h @@ -21,6 +21,7 @@ public: grib_accessor* create_empty_accessor() override { return new grib_accessor_abstract_long_vector_t{}; } public: + // TODO(maee): make private long* v_; long pack_index_; int number_of_elements_; diff --git a/src/accessor/grib_accessor_class_abstract_vector.h b/src/accessor/grib_accessor_class_abstract_vector.h index 7d0f6a31e..4ea940323 100644 --- a/src/accessor/grib_accessor_class_abstract_vector.h +++ b/src/accessor/grib_accessor_class_abstract_vector.h @@ -21,6 +21,7 @@ public: grib_accessor* create_empty_accessor() override { return new grib_accessor_abstract_vector_t{}; } public: + // TODO(maee): make private double* v_; int number_of_elements_; }; diff --git a/src/accessor/grib_accessor_class_bitmap.cc b/src/accessor/grib_accessor_class_bitmap.cc index b4327c720..2b3682de7 100644 --- a/src/accessor/grib_accessor_class_bitmap.cc +++ b/src/accessor/grib_accessor_class_bitmap.cc @@ -14,15 +14,14 @@ grib_accessor_bitmap_t _grib_accessor_bitmap{}; grib_accessor* grib_accessor_bitmap = &_grib_accessor_bitmap; -static void compute_size(grib_accessor* a) +void grib_accessor_bitmap_t::compute_size() { - grib_accessor_bitmap_t* self = (grib_accessor_bitmap_t*)a; long slen = 0; long off = 0; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); - grib_get_long_internal(hand, self->offsetbsec_, &off); - grib_get_long_internal(hand, self->sLength_, &slen); + grib_get_long_internal(hand, offsetbsec_, &off); + grib_get_long_internal(hand, sLength_, &slen); if (slen == 0) { grib_accessor* seclen; @@ -30,7 +29,7 @@ static void compute_size(grib_accessor* a) /* Assume reparsing */ Assert(hand->loader != 0); if (hand->loader != 0) { - seclen = grib_find_accessor(hand, self->sLength_); + seclen = grib_find_accessor(hand, sLength_); Assert(seclen); grib_get_block_length(seclen->parent_, &size); slen = size; @@ -39,15 +38,15 @@ static void compute_size(grib_accessor* a) // printf("compute_size off=%ld slen=%ld a->offset_=%ld\n", (long)off,(long)slen,(long)offset_ ); - a->length_ = off + (slen - a->offset_); + length_ = off + (slen - offset_); - if (a->length_ < 0) { + if (length_ < 0) { /* Assume reparsing */ /*Assert(hand->loader != 0);*/ - a->length_ = 0; + length_ = 0; } - Assert(a->length_ >= 0); + Assert(length_ >= 0); } void grib_accessor_bitmap_t::init(const long len, grib_arguments* arg) @@ -61,7 +60,7 @@ void grib_accessor_bitmap_t::init(const long len, grib_arguments* arg) offsetbsec_ = grib_arguments_get_name(hand, arg, n++); sLength_ = grib_arguments_get_name(hand, arg, n++); - compute_size(this); + compute_size(); } long grib_accessor_bitmap_t::next_offset() diff --git a/src/accessor/grib_accessor_class_bitmap.h b/src/accessor/grib_accessor_class_bitmap.h index 06153ab50..b6b2ac721 100644 --- a/src/accessor/grib_accessor_class_bitmap.h +++ b/src/accessor/grib_accessor_class_bitmap.h @@ -30,10 +30,14 @@ public: void update_size(size_t) override; int unpack_double_element(size_t i, double* val) override; int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) override; - // TODO(maee): make members private -public: - const char* tableReference_; + +protected: const char* missing_value_; + +private: + const char* tableReference_; const char* offsetbsec_; const char* sLength_; + + void compute_size(); }; diff --git a/src/accessor/grib_accessor_class_bufr_data_array.cc b/src/accessor/grib_accessor_class_bufr_data_array.cc index 23e0d402e..e73d19432 100644 --- a/src/accessor/grib_accessor_class_bufr_data_array.cc +++ b/src/accessor/grib_accessor_class_bufr_data_array.cc @@ -11,6 +11,8 @@ #include "grib_scaling.h" #include "grib_accessor_class_bufr_data_array.h" #include "grib_accessor_class_expanded_descriptors.h" +#include "grib_accessor_class_bufr_data_element.h" +#include "grib_accessor_class_variable.h" grib_accessor_bufr_data_array_t _grib_accessor_bufr_data_array{}; grib_accessor* grib_accessor_bufr_data_array = &_grib_accessor_bufr_data_array; @@ -33,51 +35,49 @@ grib_accessor* grib_accessor_bufr_data_array = &_grib_accessor_bufr_data_array; return retval; \ } + static int process_elements(grib_accessor* a, int flag, long onlySubset, long startSubset, long endSubset); -typedef int (*codec_element_proc)(grib_context* c, grib_accessor_bufr_data_array_t* self, int subsetIndex, grib_buffer* b, unsigned char* data, long* pos, int i, bufr_descriptor* descriptor, long elementIndex, grib_darray* dval, grib_sarray* sval); -typedef int (*codec_replication_proc)(grib_context* c, grib_accessor_bufr_data_array_t* self, int subsetIndex, grib_buffer* buff, unsigned char* data, long* pos, int i, long elementIndex, grib_darray* dval, long* numberOfRepetitions); static int create_keys(const grib_accessor* a, long onlySubset, long startSubset, long endSubset); -static void restart_bitmap(grib_accessor_bufr_data_array_t* self) +void grib_accessor_bufr_data_array_t::restart_bitmap() { - self->bitmapCurrent_ = -1; - self->bitmapCurrentElementsDescriptorsIndex_ = self->bitmapStartElementsDescriptorsIndex_ - 1; + bitmapCurrent_ = -1; + bitmapCurrentElementsDescriptorsIndex_ = bitmapStartElementsDescriptorsIndex_ - 1; } -static void cancel_bitmap(grib_accessor_bufr_data_array_t* self) +void grib_accessor_bufr_data_array_t::cancel_bitmap() { - self->bitmapCurrent_ = -1; - self->bitmapStart_ = -1; + bitmapCurrent_ = -1; + bitmapStart_ = -1; } -static int is_bitmap_start_defined(grib_accessor_bufr_data_array_t* self) +int grib_accessor_bufr_data_array_t::is_bitmap_start_defined() { - return self->bitmapStart_ == -1 ? 0 : 1; + return bitmapStart_ == -1 ? 0 : 1; } -static size_t get_length(grib_accessor* a) +size_t grib_accessor_bufr_data_array_t::get_length() { - grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; - size_t len = 0; - const grib_handle* h = grib_handle_of_accessor(a); + size_t len = 0; + const grib_handle* h = grib_handle_of_accessor(this); - grib_get_size(h, self->bufrDataEncodedName_, &len); + grib_get_size(h, bufrDataEncodedName_, &len); return len; } /* Operator 203YYY: Store the TableB code and changed reference value in linked list */ -static void tableB_override_store_ref_val(grib_context* c, grib_accessor_bufr_data_array_t* self, int code, long new_ref_val) +void grib_accessor_bufr_data_array_t::tableB_override_store_ref_val(grib_context* c, int code, long new_ref_val) { bufr_tableb_override* tb = (bufr_tableb_override*)grib_context_malloc_clear(c, sizeof(bufr_tableb_override)); tb->code = code; tb->new_ref_val = new_ref_val; - if (!self->tableb_override_) { - self->tableb_override_ = tb; + if (!tableb_override_) { + tableb_override_ = tb; } else { /*Add to end of linked list*/ - bufr_tableb_override* q = self->tableb_override_; + bufr_tableb_override* q = tableb_override_; while (q->next) q = q->next; q->next = tb; @@ -85,9 +85,9 @@ static void tableB_override_store_ref_val(grib_context* c, grib_accessor_bufr_da } /* Operator 203YYY: Retrieve changed reference value from linked list */ -static int tableB_override_get_ref_val(grib_accessor_bufr_data_array_t* self, int code, long* out_ref_val) +int grib_accessor_bufr_data_array_t::tableB_override_get_ref_val(int code, long* out_ref_val) { - bufr_tableb_override* p = self->tableb_override_; + bufr_tableb_override* p = tableb_override_; while (p) { if (p->code == code) { *out_ref_val = p->new_ref_val; @@ -99,25 +99,25 @@ static int tableB_override_get_ref_val(grib_accessor_bufr_data_array_t* self, in } /* Operator 203YYY: Clear and free linked list */ -static void tableB_override_clear(grib_context* c, grib_accessor_bufr_data_array_t* self) +void grib_accessor_bufr_data_array_t::tableB_override_clear(grib_context* c) { - bufr_tableb_override* tb = self->tableb_override_; + bufr_tableb_override* tb = tableb_override_; while (tb) { bufr_tableb_override* n = tb->next; grib_context_free(c, tb); tb = n; } - self->tableb_override_ = NULL; + tableb_override_ = NULL; } /* Operator 203YYY: Copy contents of linked list to the transient array key */ -static int tableB_override_set_key(grib_handle* h, grib_accessor_bufr_data_array_t* self) +int grib_accessor_bufr_data_array_t::tableB_override_set_key(grib_handle* h) { int err = GRIB_SUCCESS; size_t size = 0; long* refVals = NULL; grib_iarray* refValArray = grib_iarray_new(h->context, 10, 10); - bufr_tableb_override* p = self->tableb_override_; + bufr_tableb_override* p = tableb_override_; while (p) { grib_iarray_push(refValArray, p->new_ref_val); p = p->next; @@ -209,7 +209,7 @@ void grib_accessor_bufr_data_array_t::init(const long v, grib_arguments* params) numericValues_ = 0; tempDoubleValues_ = 0; stringValues_ = 0; - cancel_bitmap(this); + cancel_bitmap(); expanded_ = 0; expandedAccessor_ = 0; dataAccessorsTrie_ = 0; @@ -221,7 +221,7 @@ void grib_accessor_bufr_data_array_t::init(const long v, grib_arguments* params) set_to_missing_if_out_of_range_ = 0; /* By default fail if out of range */ length_ = 0; - bitsToEndData_ = get_length(this) * 8; + bitsToEndData_ = get_length() * 8; unpackMode_ = CODES_BUFR_UNPACK_STRUCTURE; inputBitmap_ = NULL; /* Assert(length_ >=0); */ @@ -237,7 +237,7 @@ void grib_accessor_bufr_data_array_t::init(const long v, grib_arguments* params) // } // } -static int check_end_data(grib_context* c, bufr_descriptor* bd, grib_accessor_bufr_data_array_t* self, int size) +int check_end_data(grib_context* c, bufr_descriptor* bd, grib_accessor_bufr_data_array_t* self, int size) { const int saved_bitsToEndData = self->bitsToEndData_; if (c->debug == 1) @@ -252,34 +252,34 @@ static int check_end_data(grib_context* c, bufr_descriptor* bd, grib_accessor_bu return 0; } -void self_clear(grib_context* c, grib_accessor_bufr_data_array_t* self) +void grib_accessor_bufr_data_array_t::self_clear() { - grib_context_free(c, self->canBeMissing_); - grib_vdarray_delete_content(c, self->numericValues_); - grib_vdarray_delete(c, self->numericValues_); + grib_context_free(context_, canBeMissing_); + grib_vdarray_delete_content(context_, numericValues_); + grib_vdarray_delete(context_, numericValues_); - if (self->stringValues_) { - /*printf("dbg self_clear: clear %p\n", (void*)(self->stringValues_ ));*/ - grib_vsarray_delete_content(c, self->stringValues_); - grib_vsarray_delete(c, self->stringValues_); - self->stringValues_ = NULL; + if (stringValues_) { + /*printf("dbg self_clear: clear %p\n", (void*)(stringValues_ ));*/ + grib_vsarray_delete_content(context_, stringValues_); + grib_vsarray_delete(context_, stringValues_); + stringValues_ = NULL; } - grib_viarray_delete_content(c, self->elementsDescriptorsIndex_); - grib_viarray_delete(c, self->elementsDescriptorsIndex_); - if (self->inputReplications_) - grib_context_free(c, self->inputReplications_); - if (self->inputExtendedReplications_) - grib_context_free(c, self->inputExtendedReplications_); - if (self->inputShortReplications_) - grib_context_free(c, self->inputShortReplications_); - self->change_ref_value_operand_ = 0; - self->refValListSize_ = 0; - if (self->refValList_) - grib_context_free(c, self->refValList_); - self->refValIndex_ = 0; - tableB_override_clear(c, self); - self->set_to_missing_if_out_of_range_ = 0; - if (self->inputBitmap_) grib_context_free(c, self->inputBitmap_); + grib_viarray_delete_content(context_, elementsDescriptorsIndex_); + grib_viarray_delete(context_, elementsDescriptorsIndex_); + if (inputReplications_) + grib_context_free(context_, inputReplications_); + if (inputExtendedReplications_) + grib_context_free(context_, inputExtendedReplications_); + if (inputShortReplications_) + grib_context_free(context_, inputShortReplications_); + change_ref_value_operand_ = 0; + refValListSize_ = 0; + if (refValList_) + grib_context_free(context_, refValList_); + refValIndex_ = 0; + tableB_override_clear(context_); + set_to_missing_if_out_of_range_ = 0; + if (inputBitmap_) grib_context_free(context_, inputBitmap_); } long grib_accessor_bufr_data_array_t::get_native_type() @@ -312,97 +312,92 @@ int grib_accessor_bufr_data_array_t::pack_long(const long* val, size_t* len) int grib_accessor_bufr_data_array_t::pack_double(const double* val, size_t* len) { do_decode_ = 1; - return process_elements(this, PROCESS_ENCODE, 0, 0, 0); + return process_elements(PROCESS_ENCODE, 0, 0, 0); } -grib_vsarray* accessor_bufr_data_array_get_stringValues(grib_accessor* a) +grib_vsarray* grib_accessor_bufr_data_array_t::accessor_bufr_data_array_get_stringValues() { - grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; - process_elements(a, PROCESS_DECODE, 0, 0, 0); - return self->stringValues_; + process_elements(PROCESS_DECODE, 0, 0, 0); + return stringValues_; } -grib_accessors_list* accessor_bufr_data_array_get_dataAccessors(grib_accessor* a) +grib_accessors_list* grib_accessor_bufr_data_array_t::accessor_bufr_data_array_get_dataAccessors() { - grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; - return self->dataAccessors_; + return dataAccessors_; } -grib_trie_with_rank* accessor_bufr_data_array_get_dataAccessorsTrie(grib_accessor* a) +grib_trie_with_rank* grib_accessor_bufr_data_array_t::accessor_bufr_data_array_get_dataAccessorsTrie() { - grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; - return self->dataAccessorsTrie_; + return dataAccessorsTrie_; } -void accessor_bufr_data_array_set_unpackMode(grib_accessor* a, int unpackMode) +void grib_accessor_bufr_data_array_t::accessor_bufr_data_array_set_unpackMode(int unpackMode) { - grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; - self->unpackMode_ = unpackMode; + unpackMode_ = unpackMode; } -static int get_descriptors(grib_accessor* a) +int grib_accessor_bufr_data_array_t::get_descriptors() { - grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; - int ret = 0, i, numberOfDescriptors; - grib_handle* h = grib_handle_of_accessor(a); - grib_context* c = a->context_; + int ret = 0, i, numberOfDescriptors; + grib_handle* h = grib_handle_of_accessor(this); + grib_context* c = context_; - if (!self->expandedAccessor_) - self->expandedAccessor_ = grib_find_accessor(grib_handle_of_accessor(a), self->expandedDescriptorsName_); - self->expanded_ = grib_accessor_expanded_descriptors_get_expanded(self->expandedAccessor_, &ret); + if (!expandedAccessor_) + expandedAccessor_ = dynamic_cast(grib_find_accessor(grib_handle_of_accessor(this), expandedDescriptorsName_)); + expanded_ = expandedAccessor_->grib_accessor_expanded_descriptors_get_expanded(&ret); if (ret != GRIB_SUCCESS) return ret; - numberOfDescriptors = grib_bufr_descriptors_array_used_size(self->expanded_); - if (self->canBeMissing_) grib_context_free(c, self->canBeMissing_); - self->canBeMissing_ = (int*)grib_context_malloc_clear(c, numberOfDescriptors * sizeof(int)); + numberOfDescriptors = grib_bufr_descriptors_array_used_size(expanded_); + if (canBeMissing_) grib_context_free(c, canBeMissing_); + canBeMissing_ = (int*)grib_context_malloc_clear(c, numberOfDescriptors * sizeof(int)); for (i = 0; i < numberOfDescriptors; i++) - self->canBeMissing_[i] = grib_bufr_descriptor_can_be_missing(self->expanded_->v[i]); + canBeMissing_[i] = grib_bufr_descriptor_can_be_missing(expanded_->v[i]); - ret = grib_get_long(h, self->numberOfSubsetsName_, &(self->numberOfSubsets_)); + ret = grib_get_long(h, numberOfSubsetsName_, &(numberOfSubsets_)); if (ret != GRIB_SUCCESS) return ret; - ret = grib_get_long(h, self->compressedDataName_, &(self->compressedData_)); + ret = grib_get_long(h, compressedDataName_, &(compressedData_)); return ret; } -static int decode_string_array(grib_context* c, unsigned char* data, long* pos, bufr_descriptor* bd, - grib_accessor_bufr_data_array_t* self) +int grib_accessor_bufr_data_array_t::decode_string_array(grib_context* c, unsigned char* data, long* pos, bufr_descriptor* bd) { int ret = 0; int* err = &ret; char* sval = 0; int j, modifiedWidth, width; - grib_sarray* sa = grib_sarray_new(c, self->numberOfSubsets_, 10); + grib_sarray* sa = grib_sarray_new(c, numberOfSubsets_, 10); int bufr_multi_element_constant_arrays = c->bufr_multi_element_constant_arrays; modifiedWidth = bd->width; sval = (char*)grib_context_malloc_clear(c, modifiedWidth / 8 + 1); - CHECK_END_DATA_RETURN(c, bd, self, modifiedWidth, *err); + CHECK_END_DATA_RETURN(c, bd, this, modifiedWidth, *err); + if (*err) { grib_sarray_push(c, sa, sval); - grib_vsarray_push(c, self->stringValues_, sa); + grib_vsarray_push(c, stringValues_, sa); return ret; } grib_decode_string(data, pos, modifiedWidth / 8, sval); - CHECK_END_DATA_RETURN(c, bd, self, 6, *err); + CHECK_END_DATA_RETURN(c, bd, this, 6, *err); if (*err) { grib_sarray_push(c, sa, sval); - grib_vsarray_push(c, self->stringValues_, sa); + grib_vsarray_push(c, stringValues_, sa); return ret; } width = grib_decode_unsigned_long(data, pos, 6); if (width) { - CHECK_END_DATA_RETURN(c, bd, self, width * 8 * self->numberOfSubsets_, *err); + CHECK_END_DATA_RETURN(c, bd, this, width * 8 * numberOfSubsets_, *err); if (*err) { grib_sarray_push(c, sa, sval); - grib_vsarray_push(c, self->stringValues_, sa); + grib_vsarray_push(c, stringValues_, sa); return ret; } grib_context_free(c, sval); - for (j = 0; j < self->numberOfSubsets_; j++) { + for (j = 0; j < numberOfSubsets_; j++) { sval = (char*)grib_context_malloc_clear(c, width + 1); grib_decode_string(data, pos, width, sval); grib_sarray_push(c, sa, sval); @@ -410,7 +405,7 @@ static int decode_string_array(grib_context* c, unsigned char* data, long* pos, } else { if (bufr_multi_element_constant_arrays) { - for (j = 0; j < self->numberOfSubsets_; j++) { + for (j = 0; j < numberOfSubsets_; j++) { char* pStr = sval; if (j > 0) pStr = strdup(sval); @@ -421,13 +416,13 @@ static int decode_string_array(grib_context* c, unsigned char* data, long* pos, grib_sarray_push(c, sa, sval); } } - grib_vsarray_push(c, self->stringValues_, sa); + grib_vsarray_push(c, stringValues_, sa); return ret; } -grib_darray* decode_double_array(grib_context* c, unsigned char* data, long* pos, - bufr_descriptor* bd, int canBeMissing, - grib_accessor_bufr_data_array_t* self, int* err) +grib_darray* grib_accessor_bufr_data_array_t::decode_double_array(grib_context* c, unsigned char* data, long* pos, + bufr_descriptor* bd, int canBeMissing, + int* err) { grib_darray* ret = NULL; int j; @@ -442,7 +437,7 @@ grib_darray* decode_double_array(grib_context* c, unsigned char* data, long* pos modifiedFactor = bd->factor; modifiedWidth = bd->width; - CHECK_END_DATA_RETURN(c, bd, self, modifiedWidth + 6, NULL); + CHECK_END_DATA_RETURN(c, bd, this, modifiedWidth + 6, NULL); if (*err) { dval = GRIB_MISSING_DOUBLE; lval = 0; @@ -456,9 +451,9 @@ grib_darray* decode_double_array(grib_context* c, unsigned char* data, long* pos localReference = (long)lval + modifiedReference; localWidth = grib_decode_unsigned_long(data, pos, 6); grib_context_log(c, GRIB_LOG_DEBUG, "BUFR data decoding: \tlocalWidth=%d", localWidth); - ret = grib_darray_new(c, self->numberOfSubsets_, 50); + ret = grib_darray_new(c, numberOfSubsets_, 50); if (localWidth) { - CHECK_END_DATA_RETURN(c, bd, self, localWidth * self->numberOfSubsets_, NULL); + CHECK_END_DATA_RETURN(c, bd, this, localWidth * numberOfSubsets_, NULL); if (*err) { dval = GRIB_MISSING_DOUBLE; lval = 0; @@ -468,7 +463,7 @@ grib_darray* decode_double_array(grib_context* c, unsigned char* data, long* pos *err = 0; return ret; } - for (j = 0; j < self->numberOfSubsets_; j++) { + for (j = 0; j < numberOfSubsets_; j++) { lval = grib_decode_size_t(data, pos, localWidth); if (canBeMissing && grib_is_all_bits_one(lval, localWidth)) { dval = GRIB_MISSING_DOUBLE; @@ -495,7 +490,7 @@ grib_darray* decode_double_array(grib_context* c, unsigned char* data, long* pos if (bufr_multi_element_constant_arrays) { grib_context_log(c, GRIB_LOG_DEBUG, " modifiedWidth=%d lval=%ld dval=%g (const array multi values) %6.6ld", modifiedWidth, lval, dval, bd->code); - for (j = 0; j < self->numberOfSubsets_; j++) { + for (j = 0; j < numberOfSubsets_; j++) { grib_darray_push(c, ret, dval); } } @@ -508,20 +503,19 @@ grib_darray* decode_double_array(grib_context* c, unsigned char* data, long* pos return ret; } -static int encode_string_array(grib_context* c, grib_buffer* buff, long* pos, bufr_descriptor* bd, - grib_accessor_bufr_data_array_t* self, grib_sarray* stringValues) +int grib_accessor_bufr_data_array_t::encode_string_array(grib_context* c, grib_buffer* buff, long* pos, bufr_descriptor* bd, grib_sarray* stringValues) { int err = 0, n, ival; int k, j, modifiedWidth, width; - if (self->iss_list_ == NULL) { - grib_context_log(c, GRIB_LOG_ERROR, "encode_string_array: self->iss_list_ ==NULL"); + if (iss_list_ == NULL) { + grib_context_log(c, GRIB_LOG_ERROR, "encode_string_array: iss_list_ ==NULL"); return GRIB_INTERNAL_ERROR; } if (!stringValues) { return GRIB_INTERNAL_ERROR; } - n = grib_iarray_used_size(self->iss_list_); + n = grib_iarray_used_size(iss_list_); if (n <= 0) return GRIB_NO_VALUES; @@ -531,7 +525,7 @@ static int encode_string_array(grib_context* c, grib_buffer* buff, long* pos, bu ival = 0; } else { - ival = self->iss_list_->v[0]; + ival = iss_list_->v[0]; } if (n > grib_sarray_used_size(stringValues)) @@ -553,7 +547,7 @@ static int encode_string_array(grib_context* c, grib_buffer* buff, long* pos, bu if (width) { grib_buffer_set_ulength_bits(c, buff, buff->ulength_bits + width * n); for (j = 0; j < n; j++) { - k = self->iss_list_->v[j]; + k = iss_list_->v[j]; err = grib_encode_string(buff->data, pos, width / 8, stringValues->v[k]); if (err) { grib_context_log(c, GRIB_LOG_ERROR, "encode_string_array: %s. Failed to encode '%s'", @@ -591,8 +585,8 @@ static int descriptor_get_min_max(bufr_descriptor* bd, long width, long referenc return GRIB_SUCCESS; } -static int encode_double_array(grib_context* c, grib_buffer* buff, long* pos, bufr_descriptor* bd, - grib_accessor_bufr_data_array_t* self, grib_darray* dvalues) +int grib_accessor_bufr_data_array_t::encode_double_array(grib_context* c, grib_buffer* buff, long* pos, bufr_descriptor* bd, + grib_darray* dvalues) { int err = 0; int j, i; @@ -609,10 +603,10 @@ static int encode_double_array(grib_context* c, grib_buffer* buff, long* pos, bu bool is_constant = true; double val0; /* ECC-379, ECC-830 */ - const int dont_fail_if_out_of_range = self->set_to_missing_if_out_of_range_; + const int dont_fail_if_out_of_range = set_to_missing_if_out_of_range_; - if (self->iss_list_ == NULL) { - grib_context_log(c, GRIB_LOG_ERROR, "encode_double_array: self->iss_list_ ==NULL"); + if (iss_list_ == NULL) { + grib_context_log(c, GRIB_LOG_ERROR, "encode_double_array: iss_list_ ==NULL"); return GRIB_INTERNAL_ERROR; } @@ -624,7 +618,7 @@ static int encode_double_array(grib_context* c, grib_buffer* buff, long* pos, bu err = descriptor_get_min_max(bd, modifiedWidth, modifiedReference, modifiedFactor, &minAllowed, &maxAllowed); if (err) return err; - nvals = grib_iarray_used_size(self->iss_list_); + nvals = grib_iarray_used_size(iss_list_); if (nvals <= 0) return GRIB_NO_VALUES; @@ -670,10 +664,10 @@ static int encode_double_array(grib_context* c, grib_buffer* buff, long* pos, bu if (nvals > grib_darray_used_size(dvalues)) return GRIB_ARRAY_TOO_SMALL; values = (double*)grib_context_malloc_clear(c, sizeof(double) * nvals); - val0 = dvalues->v[self->iss_list_->v[0]]; + val0 = dvalues->v[iss_list_->v[0]]; is_constant = true; for (i = 0; i < nvals; i++) { - values[i] = dvalues->v[self->iss_list_->v[i]]; + values[i] = dvalues->v[iss_list_->v[i]]; if (val0 != values[i]) is_constant = false; } @@ -809,8 +803,8 @@ static int encode_double_array(grib_context* c, grib_buffer* buff, long* pos, bu return err; } -static int encode_double_value(grib_context* c, grib_buffer* buff, long* pos, bufr_descriptor* bd, - grib_accessor_bufr_data_array_t* self, double value) +int grib_accessor_bufr_data_array_t::encode_double_value(grib_context* c, grib_buffer* buff, long* pos, bufr_descriptor* bd, + double value) { size_t lval; double maxAllowed, minAllowed; @@ -818,7 +812,7 @@ static int encode_double_value(grib_context* c, grib_buffer* buff, long* pos, bu int modifiedWidth, modifiedReference; double modifiedFactor; /* ECC-379, ECC-830 */ - const int dont_fail_if_out_of_range = self->set_to_missing_if_out_of_range_; + const int dont_fail_if_out_of_range = set_to_missing_if_out_of_range_; modifiedReference = bd->reference; modifiedFactor = bd->factor; @@ -871,8 +865,8 @@ static int encode_string_value(grib_context* c, grib_buffer* buff, long* pos, bu return err; } -static char* decode_string_value(grib_context* c, unsigned char* data, long* pos, bufr_descriptor* bd, - grib_accessor_bufr_data_array_t* self, int* err) +char* grib_accessor_bufr_data_array_t::decode_string_value(grib_context* c, unsigned char* data, long* pos, bufr_descriptor* bd, + int* err) { char* sval = 0; int len; @@ -881,7 +875,7 @@ static char* decode_string_value(grib_context* c, unsigned char* data, long* pos len = bd->width / 8; - CHECK_END_DATA_RETURN(c, bd, self, bd->width, NULL); + CHECK_END_DATA_RETURN(c, bd, this, bd->width, NULL); sval = (char*)grib_context_malloc_clear(c, len + 1); if (*err) { *err = 0; @@ -894,9 +888,9 @@ static char* decode_string_value(grib_context* c, unsigned char* data, long* pos return sval; } -static double decode_double_value(grib_context* c, unsigned char* data, long* pos, - bufr_descriptor* bd, int canBeMissing, - grib_accessor_bufr_data_array_t* self, int* err) +double grib_accessor_bufr_data_array_t::decode_double_value(grib_context* c, unsigned char* data, long* pos, + bufr_descriptor* bd, int canBeMissing, + int* err) { size_t lval; int modifiedWidth, modifiedReference; @@ -909,7 +903,7 @@ static double decode_double_value(grib_context* c, unsigned char* data, long* po modifiedFactor = bd->factor; modifiedWidth = bd->width; - CHECK_END_DATA_RETURN(c, bd, self, modifiedWidth, 0); + CHECK_END_DATA_RETURN(c, bd, this, modifiedWidth, 0); if (*err) { *err = 0; return GRIB_MISSING_DOUBLE; @@ -925,9 +919,10 @@ static double decode_double_value(grib_context* c, unsigned char* data, long* po return dval; } -static int decode_element(grib_context* c, grib_accessor_bufr_data_array_t* self, int subsetIndex, - grib_buffer* b, unsigned char* data, long* pos, int i, bufr_descriptor* descriptor, long elementIndex, - grib_darray* dval, grib_sarray* sval) + +int decode_element(grib_context* c, grib_accessor_bufr_data_array_t* self, int subsetIndex, + grib_buffer* b, unsigned char* data, long* pos, int i, bufr_descriptor* descriptor, long elementIndex, + grib_darray* dval, grib_sarray* sval) { grib_darray* dar = 0; grib_sarray* sar = 0; @@ -945,7 +940,7 @@ static int decode_element(grib_context* c, grib_accessor_bufr_data_array_t* self grib_context_log(c, GRIB_LOG_DEBUG, "BUFR data decoding: -**- \tcode=203YYY width=%d pos=%ld -> %ld", number_of_bits, (long)*pos, (long)(*pos - self->offset_ * 8)); grib_context_log(c, GRIB_LOG_DEBUG, "Operator 203YYY: Store for code %6.6ld => new ref val %ld", bd->code, new_ref_val); - tableB_override_store_ref_val(c, self, bd->code, new_ref_val); + self->tableB_override_store_ref_val(c, bd->code, new_ref_val); bd->nokey = 1; err = check_end_data(c, NULL, self, number_of_bits); /*advance bitsToEnd*/ return err; @@ -956,7 +951,7 @@ static int decode_element(grib_context* c, grib_accessor_bufr_data_array_t* self if (bd->type == BUFR_DESCRIPTOR_TYPE_STRING) { /* string */ if (self->compressedData_) { - err = decode_string_array(c, data, pos, bd, self); + err = self->decode_string_array(c, data, pos, bd); index = grib_vsarray_used_size(self->stringValues_); dar = grib_darray_new(c, self->numberOfSubsets_, 10); index = self->numberOfSubsets_ * (index - 1); @@ -967,7 +962,7 @@ static int decode_element(grib_context* c, grib_accessor_bufr_data_array_t* self grib_vdarray_push(c, self->numericValues_, dar); } else { - csval = decode_string_value(c, data, pos, bd, self, &err); + csval = self->decode_string_value(c, data, pos, bd, &err); grib_context_log(c, GRIB_LOG_DEBUG, "BUFR data decoding: \t %s = %s", bd->shortName, csval); sar = grib_sarray_push(c, sar, csval); grib_vsarray_push(c, self->stringValues_, sar); @@ -983,7 +978,7 @@ static int decode_element(grib_context* c, grib_accessor_bufr_data_array_t* self else { /* numeric or codetable or flagtable */ /* Operator 203YYY: Check if we have changed ref value for this element. If so modify bd->reference */ - if (self->change_ref_value_operand_ != 0 && tableB_override_get_ref_val(self, bd->code, &(bd->reference)) == GRIB_SUCCESS) { + if (self->change_ref_value_operand_ != 0 && self->tableB_override_get_ref_val(bd->code, &(bd->reference)) == GRIB_SUCCESS) { grib_context_log(c, GRIB_LOG_DEBUG, "Operator 203YYY: For code %6.6ld, changed ref val: %ld", bd->code, bd->reference); } @@ -992,12 +987,12 @@ static int decode_element(grib_context* c, grib_accessor_bufr_data_array_t* self return GRIB_DECODING_ERROR; } if (self->compressedData_) { - dar = decode_double_array(c, data, pos, bd, self->canBeMissing_[i], self, &err); + dar = self->decode_double_array(c, data, pos, bd, self->canBeMissing_[i], &err); grib_vdarray_push(c, self->numericValues_, dar); } else { /* Uncompressed */ - cdval = decode_double_value(c, data, pos, bd, self->canBeMissing_[i], self, &err); + cdval = self->decode_double_value(c, data, pos, bd, self->canBeMissing_[i], &err); grib_context_log(c, GRIB_LOG_DEBUG, "BUFR data decoding: \t %s = %g", bd->shortName, cdval); grib_darray_push(c, dval, cdval); @@ -1006,8 +1001,8 @@ static int decode_element(grib_context* c, grib_accessor_bufr_data_array_t* self return err; } -static int decode_replication(grib_context* c, grib_accessor_bufr_data_array_t* self, int subsetIndex, - grib_buffer* buff, unsigned char* data, long* pos, int i, long elementIndex, grib_darray* dval, long* numberOfRepetitions) + +int decode_replication(grib_context* c, grib_accessor_bufr_data_array_t* self, int subsetIndex, grib_buffer* buff, unsigned char* data, long* pos, int i, long elementIndex, grib_darray* dval, long* numberOfRepetitions) { int ret = 0; int* err; @@ -1071,38 +1066,39 @@ static int decode_replication(grib_context* c, grib_accessor_bufr_data_array_t* return ret; } -static int encode_new_bitmap(grib_context* c, grib_buffer* buff, long* pos, int idx, grib_accessor_bufr_data_array_t* self) + +int grib_accessor_bufr_data_array_t::encode_new_bitmap(grib_context* c, grib_buffer* buff, long* pos, int idx) { grib_darray* doubleValues = NULL; int err = 0; double cdval = 0; - if (self->nInputBitmap_ > 0) { - if (self->nInputBitmap_ < self->iInputBitmap_) + if (nInputBitmap_ > 0) { + if (nInputBitmap_ < iInputBitmap_) return GRIB_ARRAY_TOO_SMALL; - cdval = self->inputBitmap_[self->iInputBitmap_++]; + cdval = inputBitmap_[iInputBitmap_++]; } - if (self->compressedData_) { + if (compressedData_) { doubleValues = grib_darray_new(c, 1, 1); grib_darray_push(c, doubleValues, cdval); - err = encode_double_array(c, buff, pos, self->expanded_->v[idx], self, doubleValues); + err = encode_double_array(c, buff, pos, expanded_->v[idx], doubleValues); grib_darray_delete(c, doubleValues); } else { - err = encode_double_value(c, buff, pos, self->expanded_->v[idx], self, cdval); + err = encode_double_value(c, buff, pos, expanded_->v[idx], cdval); } return err; } /* Operator 203YYY: Change Reference Values: Encoding definition phase */ -static int encode_overridden_reference_value(grib_context* c, grib_accessor_bufr_data_array_t* self, - grib_buffer* buff, long* pos, bufr_descriptor* bd) +int grib_accessor_bufr_data_array_t::encode_overridden_reference_value(grib_context* c, + grib_buffer* buff, long* pos, bufr_descriptor* bd) { int err = 0; long currRefVal = -1; - long numBits = self->change_ref_value_operand_; + long numBits = change_ref_value_operand_; /* We must be encoding between 203YYY and 203255 */ - Assert(self->change_ref_value_operand_ > 0 && self->change_ref_value_operand_ != 255); - if (self->refValListSize_ == 0) { + Assert(change_ref_value_operand_ > 0 && change_ref_value_operand_ != 255); + if (refValListSize_ == 0) { grib_context_log(c, GRIB_LOG_ERROR, "encode_new_element: Overridden Reference Values array is empty! " "(Hint: set the key '%s')", @@ -1112,30 +1108,30 @@ static int encode_overridden_reference_value(grib_context* c, grib_accessor_bufr "number of descriptors between operator 203YYY and 203255"); return GRIB_ENCODING_ERROR; } - if (self->refValIndex_ >= self->refValListSize_) { + if (refValIndex_ >= refValListSize_) { grib_context_log(c, GRIB_LOG_ERROR, "encode_new_element: Overridden Reference Values: index=%ld, size=%ld. " "\nThe number of overridden reference values must be equal to " "number of descriptors between operator 203YYY and 203255", - self->refValIndex_, self->refValListSize_); + refValIndex_, refValListSize_); return GRIB_ENCODING_ERROR; } - currRefVal = self->refValList_[self->refValIndex_]; - grib_context_log(c, GRIB_LOG_DEBUG, "encode_new_element: Operator 203YYY: writing ref val %ld (self->refValIndex_ =%ld)", - currRefVal, self->refValIndex_); + currRefVal = refValList_[refValIndex_]; + grib_context_log(c, GRIB_LOG_DEBUG, "encode_new_element: Operator 203YYY: writing ref val %ld (refValIndex_ =%ld)", + currRefVal, refValIndex_); grib_buffer_set_ulength_bits(c, buff, buff->ulength_bits + numBits); err = grib_encode_signed_longb(buff->data, currRefVal, pos, numBits); if (err) { grib_context_log(c, GRIB_LOG_ERROR, "Encoding overridden reference value %ld for %s (code=%6.6ld)", currRefVal, bd->shortName, bd->code); } - self->refValIndex_++; + refValIndex_++; return err; } -static int encode_new_element(grib_context* c, grib_accessor_bufr_data_array_t* self, int subsetIndex, - grib_buffer* buff, unsigned char* data, long* pos, int i, bufr_descriptor* descriptor, - long elementIndex, grib_darray* dval, grib_sarray* sval) +int encode_new_element(grib_context* c, grib_accessor_bufr_data_array_t* self, int subsetIndex, + grib_buffer* buff, unsigned char* data, long* pos, int i, bufr_descriptor* descriptor, + long elementIndex, grib_darray* dval, grib_sarray* sval) { int ii; char* csval = 0; @@ -1150,7 +1146,7 @@ static int encode_new_element(grib_context* c, grib_accessor_bufr_data_array_t* if (self->change_ref_value_operand_ > 0 && self->change_ref_value_operand_ != 255) { /* Operator 203YYY: Change Reference Values: Encoding definition phase */ - err = encode_overridden_reference_value(c, self, buff, pos, bd); + err = self->encode_overridden_reference_value(c, buff, pos, bd); return err; } @@ -1165,7 +1161,7 @@ static int encode_new_element(grib_context* c, grib_accessor_bufr_data_array_t* if (self->compressedData_) { grib_sarray* stringValues = grib_sarray_new(c, 1, 1); grib_sarray_push(c, stringValues, csval); - err = encode_string_array(c, buff, pos, bd, self, stringValues); + err = self->encode_string_array(c, buff, pos, bd, stringValues); grib_sarray_delete_content(c, stringValues); grib_sarray_delete(c, stringValues); } @@ -1179,22 +1175,23 @@ static int encode_new_element(grib_context* c, grib_accessor_bufr_data_array_t* grib_context_log(c, GRIB_LOG_DEBUG, "BUFR data encoding: \t %s = %g", bd->shortName, cdval); if (bd->code == 31031) - return encode_new_bitmap(c, buff, pos, i, self); + return self->encode_new_bitmap(c, buff, pos, i); if (self->compressedData_) { grib_darray* doubleValues = grib_darray_new(c, 1, 1); grib_darray_push(c, doubleValues, cdval); - err = encode_double_array(c, buff, pos, bd, self, doubleValues); + err = self->encode_double_array(c, buff, pos, bd, doubleValues); grib_darray_delete(c, doubleValues); } else { - err = encode_double_value(c, buff, pos, bd, self, cdval); + err = self->encode_double_value(c, buff, pos, bd, cdval); } } return err; } -static int encode_new_replication(grib_context* c, grib_accessor_bufr_data_array_t* self, int subsetIndex, - grib_buffer* buff, unsigned char* data, long* pos, int i, long elementIndex, grib_darray* dval, long* numberOfRepetitions) + +int encode_new_replication(grib_context* c, grib_accessor_bufr_data_array_t* self, int subsetIndex, + grib_buffer* buff, unsigned char* data, long* pos, int i, long elementIndex, grib_darray* dval, long* numberOfRepetitions) { int err = 0; unsigned long repetitions = 1; @@ -1256,9 +1253,10 @@ static int encode_new_replication(grib_context* c, grib_accessor_bufr_data_array return err; } -static int encode_element(grib_context* c, grib_accessor_bufr_data_array_t* self, int subsetIndex, - grib_buffer* buff, unsigned char* data, long* pos, int i, bufr_descriptor* descriptor, - long elementIndex, grib_darray* dval, grib_sarray* sval) + +int encode_element(grib_context* c, grib_accessor_bufr_data_array_t* self, int subsetIndex, + grib_buffer* buff, unsigned char* data, long* pos, int i, bufr_descriptor* descriptor, + long elementIndex, grib_darray* dval, grib_sarray* sval) { int idx, j; int err = 0; @@ -1270,7 +1268,7 @@ static int encode_element(grib_context* c, grib_accessor_bufr_data_array_t* self if (self->change_ref_value_operand_ > 0 && self->change_ref_value_operand_ != 255) { /* Operator 203YYY: Change Reference Values: Encoding definition phase */ - err = encode_overridden_reference_value(c, self, buff, pos, bd); + err = self->encode_overridden_reference_value(c, buff, pos, bd); return err; } @@ -1280,7 +1278,7 @@ static int encode_element(grib_context* c, grib_accessor_bufr_data_array_t* self bd->shortName,csval); */ if (self->compressedData_) { idx = ((int)self->numericValues_->v[elementIndex]->v[0] / 1000 - 1) / self->numberOfSubsets_; - err = encode_string_array(c, buff, pos, bd, self, self->stringValues_->v[idx]); + err = self->encode_string_array(c, buff, pos, bd, self->stringValues_->v[idx]); } else { if (self->numericValues_->v[subsetIndex] == NULL) { @@ -1298,7 +1296,7 @@ static int encode_element(grib_context* c, grib_accessor_bufr_data_array_t* self else { /* numeric or codetable or flagtable */ if (self->compressedData_) { - err = encode_double_array(c, buff, pos, bd, self, self->numericValues_->v[elementIndex]); + err = self->encode_double_array(c, buff, pos, bd, self->numericValues_->v[elementIndex]); if (err) { grib_darray* varr = self->numericValues_->v[elementIndex]; grib_context_log(c, GRIB_LOG_ERROR, "Encoding key '%s' ( code=%6.6ld width=%ld scale=%ld reference=%ld )", @@ -1318,7 +1316,7 @@ static int encode_element(grib_context* c, grib_accessor_bufr_data_array_t* self grib_context_log(c, GRIB_LOG_ERROR, "Invalid subset index %d (number of subsets=%ld)", subsetIndex, self->numberOfSubsets_); return GRIB_INVALID_ARGUMENT; } - err = encode_double_value(c, buff, pos, bd, self, self->numericValues_->v[subsetIndex]->v[elementIndex]); + err = self->encode_double_value(c, buff, pos, bd, self->numericValues_->v[subsetIndex]->v[elementIndex]); if (err) { grib_context_log(c, GRIB_LOG_ERROR, "Cannot encode %s=%g (subset=%d)", /*subsetIndex starts from 0*/ bd->shortName, self->numericValues_->v[subsetIndex]->v[elementIndex], subsetIndex + 1); @@ -1328,9 +1326,10 @@ static int encode_element(grib_context* c, grib_accessor_bufr_data_array_t* self return err; } -static int encode_replication(grib_context* c, grib_accessor_bufr_data_array_t* self, int subsetIndex, - grib_buffer* buff, unsigned char* data, long* pos, int i, long elementIndex, - grib_darray* dval, long* numberOfRepetitions) + +int encode_replication(grib_context* c, grib_accessor_bufr_data_array_t* self, int subsetIndex, + grib_buffer* buff, unsigned char* data, long* pos, int i, long elementIndex, + grib_darray* dval, long* numberOfRepetitions) { /* Assert( buff->data == data); */ if (self->compressedData_) { @@ -1344,15 +1343,14 @@ static int encode_replication(grib_context* c, grib_accessor_bufr_data_array_t* return encode_element(c, self, subsetIndex, buff, data, pos, i, 0, elementIndex, dval, 0); } -static int build_bitmap(grib_accessor_bufr_data_array_t* self, unsigned char* data, long* pos, - int iel, grib_iarray* elementsDescriptorsIndex, int iBitmapOperator) + +int grib_accessor_bufr_data_array_t::build_bitmap(unsigned char* data, long* pos, + int iel, grib_iarray* elementsDescriptorsIndex, int iBitmapOperator) { int bitmapSize = 0, iDelayedReplication = 0; int i, localReference, width, bitmapEndElementsDescriptorsIndex; long ppos, n; - grib_accessor* a = (grib_accessor*)self; - const grib_context* c = a->context_; - bufr_descriptor** descriptors = self->expanded_->v; + bufr_descriptor** descriptors = expanded_->v; const long* edi = elementsDescriptorsIndex->v; /* int iel=grib_iarray_used_size(elementsDescriptorsIndex)-1; */ int err = 0; @@ -1361,7 +1359,7 @@ static int build_bitmap(grib_accessor_bufr_data_array_t* self, unsigned char* da case 222000: case 223000: case 236000: - cancel_bitmap(self); + cancel_bitmap(); if (iel < 0) { return GRIB_ENCODING_ERROR; } @@ -1392,7 +1390,7 @@ static int build_bitmap(grib_accessor_bufr_data_array_t* self, unsigned char* da Assert(descriptors[iDelayedReplication]->code == 31001 || descriptors[iDelayedReplication]->code == 31002); i = iDelayedReplication; - if (self->compressedData_) { + if (compressedData_) { ppos = *pos; if (err) return err; @@ -1401,7 +1399,7 @@ static int build_bitmap(grib_accessor_bufr_data_array_t* self, unsigned char* da *pos = ppos; if (width) { /* delayed replication number is not constant. NOT IMPLEMENTED */ - grib_context_log(c, GRIB_LOG_ERROR, "Delayed replication number is not constant"); + grib_context_log(context_, GRIB_LOG_ERROR, "Delayed replication number is not constant"); return GRIB_NOT_IMPLEMENTED; } else { @@ -1431,32 +1429,32 @@ static int build_bitmap(grib_accessor_bufr_data_array_t* self, unsigned char* da n--; iel--; } - self->bitmapStartElementsDescriptorsIndex_ = iel; - restart_bitmap(self); + bitmapStartElementsDescriptorsIndex_ = iel; + restart_bitmap(); break; default: - grib_context_log(c, GRIB_LOG_ERROR, "build_bitmap: unsupported operator %ld\n", + grib_context_log(context_, GRIB_LOG_ERROR, "build_bitmap: unsupported operator %ld\n", descriptors[iBitmapOperator]->code); return GRIB_INTERNAL_ERROR; } return GRIB_SUCCESS; } -static int consume_bitmap(grib_accessor_bufr_data_array_t* self, int iBitmapOperator) +int grib_accessor_bufr_data_array_t::consume_bitmap(int iBitmapOperator) { int bitmapSize = 0, iDelayedReplication; int i; - bufr_descriptor** descriptors = self->expanded_->v; + bufr_descriptor** descriptors = expanded_->v; i = iBitmapOperator + 1; if (descriptors[i]->code == 101000) { iDelayedReplication = iBitmapOperator + 2; switch (descriptors[iDelayedReplication]->code) { case 31001: - bitmapSize = self->inputReplications_[self->iInputReplications_]; + bitmapSize = inputReplications_[iInputReplications_]; break; case 31002: - bitmapSize = self->inputExtendedReplications_[self->iInputExtendedReplications_]; + bitmapSize = inputExtendedReplications_[iInputExtendedReplications_]; break; default: Assert(0); @@ -1469,19 +1467,17 @@ static int consume_bitmap(grib_accessor_bufr_data_array_t* self, int iBitmapOper i++; } } - self->bitmapCurrent_ += bitmapSize; + bitmapCurrent_ += bitmapSize; return GRIB_SUCCESS; } -static int build_bitmap_new_data(grib_accessor* a, unsigned char* data, long* pos, - int iel, grib_iarray* elementsDescriptorsIndex, int iBitmapOperator) +int grib_accessor_bufr_data_array_t::build_bitmap_new_data(unsigned char* data, long* pos, + int iel, grib_iarray* elementsDescriptorsIndex, int iBitmapOperator) { - grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; int bitmapSize = 0, iDelayedReplication = 0; int i, bitmapEndElementsDescriptorsIndex; long n; - const grib_context* c = a->context_; - bufr_descriptor** descriptors = self->expanded_->v; + bufr_descriptor** descriptors = expanded_->v; const long* edi = elementsDescriptorsIndex->v; switch (descriptors[iBitmapOperator]->code) { @@ -1517,18 +1513,18 @@ static int build_bitmap_new_data(grib_accessor* a, unsigned char* data, long* po iDelayedReplication = iBitmapOperator + 2; switch (descriptors[iDelayedReplication]->code) { case 31001: - if (!self->inputReplications_) { - grib_context_log(c, GRIB_LOG_ERROR, "build_bitmap_new_data: No inputReplications"); + if (!inputReplications_) { + grib_context_log(context_, GRIB_LOG_ERROR, "build_bitmap_new_data: No inputReplications"); return GRIB_ENCODING_ERROR; } - bitmapSize = self->inputReplications_[self->iInputReplications_]; + bitmapSize = inputReplications_[iInputReplications_]; break; case 31002: - if (!self->inputExtendedReplications_) { - grib_context_log(c, GRIB_LOG_ERROR, "build_bitmap_new_data: No inputExtendedReplications"); + if (!inputExtendedReplications_) { + grib_context_log(context_, GRIB_LOG_ERROR, "build_bitmap_new_data: No inputExtendedReplications"); return GRIB_ENCODING_ERROR; } - bitmapSize = self->inputExtendedReplications_[self->iInputExtendedReplications_]; + bitmapSize = inputExtendedReplications_[iInputExtendedReplications_]; break; default: Assert(0); @@ -1548,11 +1544,11 @@ static int build_bitmap_new_data(grib_accessor* a, unsigned char* data, long* po n--; iel--; } - self->bitmapStartElementsDescriptorsIndex_ = iel; - self->bitmapCurrentElementsDescriptorsIndex_ = iel - 1; + bitmapStartElementsDescriptorsIndex_ = iel; + bitmapCurrentElementsDescriptorsIndex_ = iel - 1; break; default: - grib_context_log(c, GRIB_LOG_ERROR, "build_bitmap_new_data: unsupported operator %ld\n", + grib_context_log(context_, GRIB_LOG_ERROR, "build_bitmap_new_data: unsupported operator %ld\n", descriptors[iBitmapOperator]->code); return GRIB_INTERNAL_ERROR; } @@ -1560,104 +1556,101 @@ static int build_bitmap_new_data(grib_accessor* a, unsigned char* data, long* po } /* ECC-1304: Will return an index if successful. In case of an error, a negative number is returned e.g. GRIB_WRONG_BITMAP_SIZE */ -static int get_next_bitmap_descriptor_index_new_bitmap(grib_accessor_bufr_data_array_t* self, grib_iarray* elementsDescriptorsIndex, int compressedData) +int grib_accessor_bufr_data_array_t::get_next_bitmap_descriptor_index_new_bitmap(grib_iarray* elementsDescriptorsIndex, int compressedData) { int i; - bufr_descriptor** descriptors = self->expanded_->v; + bufr_descriptor** descriptors = expanded_->v; - self->bitmapCurrent_++; - self->bitmapCurrentElementsDescriptorsIndex_++; - i = self->bitmapCurrent_; + bitmapCurrent_++; + bitmapCurrentElementsDescriptorsIndex_++; + i = bitmapCurrent_; - if (self->compressedData_) { - DEBUG_ASSERT(i < self->nInputBitmap_); - if (i >= self->nInputBitmap_) + if (compressedData_) { + DEBUG_ASSERT(i < nInputBitmap_); + if (i >= nInputBitmap_) return GRIB_WRONG_BITMAP_SIZE; - while (self->inputBitmap_[i] == 1) { - self->bitmapCurrent_++; - self->bitmapCurrentElementsDescriptorsIndex_++; - while (descriptors[elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex_]]->code > 100000) - self->bitmapCurrentElementsDescriptorsIndex_++; + while (inputBitmap_[i] == 1) { + bitmapCurrent_++; + bitmapCurrentElementsDescriptorsIndex_++; + while (descriptors[elementsDescriptorsIndex->v[bitmapCurrentElementsDescriptorsIndex_]]->code > 100000) + bitmapCurrentElementsDescriptorsIndex_++; i++; } } else { - if (i >= self->nInputBitmap_) + if (i >= nInputBitmap_) return GRIB_WRONG_BITMAP_SIZE; - while (self->inputBitmap_[i] == 1) { - self->bitmapCurrent_++; - self->bitmapCurrentElementsDescriptorsIndex_++; - while (descriptors[elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex_]]->code > 100000) - self->bitmapCurrentElementsDescriptorsIndex_++; + while (inputBitmap_[i] == 1) { + bitmapCurrent_++; + bitmapCurrentElementsDescriptorsIndex_++; + while (descriptors[elementsDescriptorsIndex->v[bitmapCurrentElementsDescriptorsIndex_]]->code > 100000) + bitmapCurrentElementsDescriptorsIndex_++; i++; } } - while (descriptors[elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex_]]->code > 100000) - self->bitmapCurrentElementsDescriptorsIndex_++; - return elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex_]; + while (descriptors[elementsDescriptorsIndex->v[bitmapCurrentElementsDescriptorsIndex_]]->code > 100000) + bitmapCurrentElementsDescriptorsIndex_++; + return elementsDescriptorsIndex->v[bitmapCurrentElementsDescriptorsIndex_]; } /* ECC-1304: Will return an index if successful. In case of an error, a negative number is returned e.g. GRIB_WRONG_BITMAP_SIZE */ -static int get_next_bitmap_descriptor_index(grib_accessor_bufr_data_array_t* self, grib_iarray* elementsDescriptorsIndex, grib_darray* numericValues) +int grib_accessor_bufr_data_array_t::get_next_bitmap_descriptor_index(grib_iarray* elementsDescriptorsIndex, grib_darray* numericValues) { int i; - bufr_descriptor** descriptors = self->expanded_->v; + bufr_descriptor** descriptors = expanded_->v; - if (self->compressedData_) { - if (self->numericValues_->n == 0) - return get_next_bitmap_descriptor_index_new_bitmap(self, elementsDescriptorsIndex, 1); + if (compressedData_) { + if (numericValues_->n == 0) + return get_next_bitmap_descriptor_index_new_bitmap(elementsDescriptorsIndex, 1); - self->bitmapCurrent_++; - self->bitmapCurrentElementsDescriptorsIndex_++; - i = self->bitmapCurrent_ + self->bitmapStart_; - DEBUG_ASSERT(i < self->numericValues_->n); - while (self->numericValues_->v[i]->v[0] == 1) { - self->bitmapCurrent_++; - self->bitmapCurrentElementsDescriptorsIndex_++; - while (descriptors[elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex_]]->code > 100000) - self->bitmapCurrentElementsDescriptorsIndex_++; + bitmapCurrent_++; + bitmapCurrentElementsDescriptorsIndex_++; + i = bitmapCurrent_ + bitmapStart_; + DEBUG_ASSERT(i < numericValues_->n); + while (numericValues_->v[i]->v[0] == 1) { + bitmapCurrent_++; + bitmapCurrentElementsDescriptorsIndex_++; + while (descriptors[elementsDescriptorsIndex->v[bitmapCurrentElementsDescriptorsIndex_]]->code > 100000) + bitmapCurrentElementsDescriptorsIndex_++; i++; } } else { if (numericValues->n == 0) - return get_next_bitmap_descriptor_index_new_bitmap(self, elementsDescriptorsIndex, 0); + return get_next_bitmap_descriptor_index_new_bitmap(elementsDescriptorsIndex, 0); - self->bitmapCurrent_++; - self->bitmapCurrentElementsDescriptorsIndex_++; - i = self->bitmapCurrent_ + self->bitmapStart_; + bitmapCurrent_++; + bitmapCurrentElementsDescriptorsIndex_++; + i = bitmapCurrent_ + bitmapStart_; DEBUG_ASSERT(i < numericValues->n); while (numericValues->v[i] == 1) { - self->bitmapCurrent_++; - self->bitmapCurrentElementsDescriptorsIndex_++; - while (descriptors[elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex_]]->code > 100000) - self->bitmapCurrentElementsDescriptorsIndex_++; + bitmapCurrent_++; + bitmapCurrentElementsDescriptorsIndex_++; + while (descriptors[elementsDescriptorsIndex->v[bitmapCurrentElementsDescriptorsIndex_]]->code > 100000) + bitmapCurrentElementsDescriptorsIndex_++; i++; } } - while (descriptors[elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex_]]->code > 100000) - self->bitmapCurrentElementsDescriptorsIndex_++; - return elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex_]; + while (descriptors[elementsDescriptorsIndex->v[bitmapCurrentElementsDescriptorsIndex_]]->code > 100000) + bitmapCurrentElementsDescriptorsIndex_++; + return elementsDescriptorsIndex->v[bitmapCurrentElementsDescriptorsIndex_]; } -static void push_zero_element(grib_accessor* a, grib_darray* dval) +void grib_accessor_bufr_data_array_t::push_zero_element(grib_darray* dval) { - grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; - grib_darray* d = 0; - grib_context* c = a->context_; - if (self->compressedData_) { - d = grib_darray_new(c, 1, 100); - grib_darray_push(c, d, 0); - grib_vdarray_push(c, self->numericValues_, d); + grib_darray* d = 0; + if (compressedData_) { + d = grib_darray_new(context_, 1, 100); + grib_darray_push(context_, d, 0); + grib_vdarray_push(context_, numericValues_, d); } else { - grib_darray_push(c, dval, 0); + grib_darray_push(context_, dval, 0); } } -static grib_accessor* create_attribute_variable(const char* name, grib_section* section, int type, char* sval, double dval, long lval, unsigned long flags) +grib_accessor* grib_accessor_bufr_data_array_t::create_attribute_variable(const char* name, grib_section* section, int type, char* sval, double dval, long lval, unsigned long flags) { - grib_accessor* a = NULL; grib_action creator = { 0, }; @@ -1667,11 +1660,12 @@ static grib_accessor* create_attribute_variable(const char* name, grib_section* creator.flags = GRIB_ACCESSOR_FLAG_READ_ONLY | flags; creator.set = 0; - creator.name = (char*)name; - a = grib_accessor_factory(section, &creator, 0, NULL); - a->parent_ = NULL; - a->h_ = section->h; - accessor_variable_set_type(a, type); + creator.name = (char*)name; + grib_accessor* a = grib_accessor_factory(section, &creator, 0, NULL); + a->parent_ = NULL; + a->h_ = section->h; + grib_accessor_variable_t* va = dynamic_cast(a); + va->accessor_variable_set_type(type); len = 1; switch (type) { case GRIB_TYPE_LONG: @@ -1776,12 +1770,11 @@ static int adding_extra_key_attributes(grib_handle* h) return (!skip); } -static grib_accessor* create_accessor_from_descriptor(const grib_accessor* a, grib_accessor* attribute, grib_section* section, - long ide, long subset, int add_dump_flag, int add_coord_flag, - int count, int add_extra_attributes) +grib_accessor* grib_accessor_bufr_data_array_t::create_accessor_from_descriptor(grib_accessor* attribute, grib_section* section, + long ide, long subset, int add_dump_flag, int add_coord_flag, + int count, int add_extra_attributes) { - grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; - char code[10] = { + char code[10] = { 0, }; char* temp_str = NULL; @@ -1790,7 +1783,9 @@ static grib_accessor* create_accessor_from_descriptor(const grib_accessor* a, gr grib_action operatorCreator = { 0, }; - grib_accessor* elementAccessor = NULL; + grib_accessor* accessor = NULL; + grib_accessor_bufr_data_element_t* elementAccessor = NULL; + grib_accessor_variable_t* variableAccessor = NULL; grib_action creator = { 0, }; @@ -1816,164 +1811,169 @@ static grib_accessor* create_accessor_from_descriptor(const grib_accessor* a, gr creator.flags |= GRIB_ACCESSOR_FLAG_BUFR_COORD; // ECC-1611 } - idx = self->compressedData_ ? self->elementsDescriptorsIndex_->v[0]->v[ide] : self->elementsDescriptorsIndex_->v[subset]->v[ide]; + idx = compressedData_ ? elementsDescriptorsIndex_->v[0]->v[ide] : elementsDescriptorsIndex_->v[subset]->v[ide]; - switch (self->expanded_->v[idx]->F) { + switch (expanded_->v[idx]->F) { case 0: case 1: - creator.name = grib_context_strdup(a->context_, self->expanded_->v[idx]->shortName); + creator.name = grib_context_strdup(context_, expanded_->v[idx]->shortName); /* ECC-325: store alloc'd string (due to strdup) for clean up later */ - grib_sarray_push(a->context_, self->tempStrings_, creator.name); - elementAccessor = grib_accessor_factory(section, &creator, 0, NULL); - if (self->canBeMissing_[idx]) - elementAccessor->flags_ |= GRIB_ACCESSOR_FLAG_CAN_BE_MISSING; - if (self->expanded_->v[idx]->code == 31000 || self->expanded_->v[idx]->code == 31001 || self->expanded_->v[idx]->code == 31002 || self->expanded_->v[idx]->code == 31031) - elementAccessor->flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; - accessor_bufr_data_element_set_index(elementAccessor, ide); - accessor_bufr_data_element_set_descriptors(elementAccessor, self->expanded_); - accessor_bufr_data_element_set_elementsDescriptorsIndex(elementAccessor, self->elementsDescriptorsIndex_); - accessor_bufr_data_element_set_numericValues(elementAccessor, self->numericValues_); - accessor_bufr_data_element_set_stringValues(elementAccessor, self->stringValues_); - accessor_bufr_data_element_set_compressedData(elementAccessor, self->compressedData_); - accessor_bufr_data_element_set_type(elementAccessor, self->expanded_->v[idx]->type); - accessor_bufr_data_element_set_numberOfSubsets(elementAccessor, self->numberOfSubsets_); - accessor_bufr_data_element_set_subsetNumber(elementAccessor, subset); + grib_sarray_push(context_, tempStrings_, creator.name); + accessor = grib_accessor_factory(section, &creator, 0, NULL); + if (canBeMissing_[idx]) + accessor->flags_ |= GRIB_ACCESSOR_FLAG_CAN_BE_MISSING; + if (expanded_->v[idx]->code == 31000 || expanded_->v[idx]->code == 31001 || expanded_->v[idx]->code == 31002 || expanded_->v[idx]->code == 31031) + accessor->flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + elementAccessor = dynamic_cast(accessor); + elementAccessor->index(ide); + elementAccessor->descriptors(expanded_); + elementAccessor->elementsDescriptorsIndex(elementsDescriptorsIndex_); + elementAccessor->numericValues(numericValues_); + elementAccessor->stringValues(stringValues_); + elementAccessor->compressedData(compressedData_); + elementAccessor->type(expanded_->v[idx]->type); + elementAccessor->numberOfSubsets(numberOfSubsets_); + elementAccessor->subsetNumber(subset); - self->expanded_->v[idx]->a = elementAccessor; + expanded_->v[idx]->a = accessor; if (attribute) { - /* attribute->parent=elementAccessor->parent; */ + /* attribute->parent=accessor->parent; */ /* for (i=0;iattributes[i]) attribute->attributes[i]->parent=elementAccessor->parent; + if (attribute->attributes[i]) attribute->attributes[i]->parent=accessor->parent; } */ - elementAccessor->add_attribute(attribute, 0); + accessor->add_attribute(attribute, 0); } attribute = create_attribute_variable("index", section, GRIB_TYPE_LONG, 0, 0, count, flags); if (!attribute) return NULL; - elementAccessor->add_attribute(attribute, 0); + accessor->add_attribute(attribute, 0); - snprintf(code, sizeof(code), "%06ld", self->expanded_->v[idx]->code); - temp_str = grib_context_strdup(a->context_, code); + snprintf(code, sizeof(code), "%06ld", expanded_->v[idx]->code); + temp_str = grib_context_strdup(context_, code); attribute = create_attribute_variable("code", section, GRIB_TYPE_STRING, temp_str, 0, 0, flags); if (!attribute) return NULL; - grib_sarray_push(a->context_, self->tempStrings_, temp_str); /* ECC-325: store alloc'd string (due to strdup) for clean up later */ - elementAccessor->add_attribute(attribute, 0); + grib_sarray_push(context_, tempStrings_, temp_str); /* ECC-325: store alloc'd string (due to strdup) for clean up later */ + accessor->add_attribute(attribute, 0); if (add_extra_attributes) { - attribute = create_attribute_variable("units", section, GRIB_TYPE_STRING, self->expanded_->v[idx]->units, 0, 0, GRIB_ACCESSOR_FLAG_DUMP | flags); + attribute = create_attribute_variable("units", section, GRIB_TYPE_STRING, expanded_->v[idx]->units, 0, 0, GRIB_ACCESSOR_FLAG_DUMP | flags); if (!attribute) return NULL; - elementAccessor->add_attribute(attribute, 0); + accessor->add_attribute(attribute, 0); - attribute = create_attribute_variable("scale", section, GRIB_TYPE_LONG, 0, 0, self->expanded_->v[idx]->scale, flags); + attribute = create_attribute_variable("scale", section, GRIB_TYPE_LONG, 0, 0, expanded_->v[idx]->scale, flags); if (!attribute) return NULL; - elementAccessor->add_attribute(attribute, 0); + accessor->add_attribute(attribute, 0); - attribute = create_attribute_variable("reference", section, GRIB_TYPE_DOUBLE, 0, self->expanded_->v[idx]->reference, 0, flags); + attribute = create_attribute_variable("reference", section, GRIB_TYPE_DOUBLE, 0, expanded_->v[idx]->reference, 0, flags); if (!attribute) return NULL; - elementAccessor->add_attribute(attribute, 0); + accessor->add_attribute(attribute, 0); - attribute = create_attribute_variable("width", section, GRIB_TYPE_LONG, 0, 0, self->expanded_->v[idx]->width, flags); + attribute = create_attribute_variable("width", section, GRIB_TYPE_LONG, 0, 0, expanded_->v[idx]->width, flags); if (!attribute) return NULL; - elementAccessor->add_attribute(attribute, 0); + accessor->add_attribute(attribute, 0); } break; case 2: - set_creator_name(&creator, self->expanded_->v[idx]->code); - if (bufr_descriptor_is_marker(self->expanded_->v[idx])) { - elementAccessor = grib_accessor_factory(section, &creator, 0, NULL); - if (self->canBeMissing_[idx]) - elementAccessor->flags_ |= GRIB_ACCESSOR_FLAG_CAN_BE_MISSING; - accessor_bufr_data_element_set_index(elementAccessor, ide); - accessor_bufr_data_element_set_descriptors(elementAccessor, self->expanded_); - accessor_bufr_data_element_set_elementsDescriptorsIndex(elementAccessor, self->elementsDescriptorsIndex_); - accessor_bufr_data_element_set_numericValues(elementAccessor, self->numericValues_); - accessor_bufr_data_element_set_stringValues(elementAccessor, self->stringValues_); - accessor_bufr_data_element_set_compressedData(elementAccessor, self->compressedData_); - accessor_bufr_data_element_set_type(elementAccessor, self->expanded_->v[idx]->type); - accessor_bufr_data_element_set_numberOfSubsets(elementAccessor, self->numberOfSubsets_); - accessor_bufr_data_element_set_subsetNumber(elementAccessor, subset); + set_creator_name(&creator, expanded_->v[idx]->code); + if (bufr_descriptor_is_marker(expanded_->v[idx])) { + accessor = grib_accessor_factory(section, &creator, 0, NULL); + if (canBeMissing_[idx]) + accessor->flags_ |= GRIB_ACCESSOR_FLAG_CAN_BE_MISSING; + elementAccessor = dynamic_cast(accessor); + elementAccessor->index(ide); + elementAccessor->descriptors(expanded_); + elementAccessor->elementsDescriptorsIndex(elementsDescriptorsIndex_); + elementAccessor->numericValues(numericValues_); + elementAccessor->stringValues(stringValues_); + elementAccessor->compressedData(compressedData_); + elementAccessor->type(expanded_->v[idx]->type); + elementAccessor->numberOfSubsets(numberOfSubsets_); + elementAccessor->subsetNumber(subset); attribute = create_attribute_variable("index", section, GRIB_TYPE_LONG, 0, 0, count, flags); if (!attribute) return NULL; - elementAccessor->add_attribute(attribute, 0); + accessor->add_attribute(attribute, 0); } else { - elementAccessor = grib_accessor_factory(section, &operatorCreator, 0, NULL); - accessor_variable_set_type(elementAccessor, GRIB_TYPE_LONG); + accessor = grib_accessor_factory(section, &operatorCreator, 0, NULL); + variableAccessor = dynamic_cast(accessor); + variableAccessor->accessor_variable_set_type(GRIB_TYPE_LONG); attribute = create_attribute_variable("index", section, GRIB_TYPE_LONG, 0, 0, count, flags); if (!attribute) return NULL; - elementAccessor->add_attribute(attribute, 0); + accessor->add_attribute(attribute, 0); - snprintf(code, sizeof(code), "%06ld", self->expanded_->v[idx]->code); + snprintf(code, sizeof(code), "%06ld", expanded_->v[idx]->code); attribute = create_attribute_variable("code", section, GRIB_TYPE_STRING, code, 0, 0, flags); if (!attribute) return NULL; - elementAccessor->add_attribute(attribute, 0); + accessor->add_attribute(attribute, 0); } - self->expanded_->v[idx]->a = elementAccessor; + expanded_->v[idx]->a = accessor; break; case 9: - set_creator_name(&creator, self->expanded_->v[idx]->code); - elementAccessor = grib_accessor_factory(section, &creator, 0, NULL); - accessor_bufr_data_element_set_index(elementAccessor, ide); - accessor_bufr_data_element_set_descriptors(elementAccessor, self->expanded_); - accessor_bufr_data_element_set_elementsDescriptorsIndex(elementAccessor, self->elementsDescriptorsIndex_); - accessor_bufr_data_element_set_numericValues(elementAccessor, self->numericValues_); - accessor_bufr_data_element_set_stringValues(elementAccessor, self->stringValues_); - accessor_bufr_data_element_set_compressedData(elementAccessor, self->compressedData_); - accessor_bufr_data_element_set_type(elementAccessor, self->expanded_->v[idx]->type); - accessor_bufr_data_element_set_numberOfSubsets(elementAccessor, self->numberOfSubsets_); - accessor_bufr_data_element_set_subsetNumber(elementAccessor, subset); + set_creator_name(&creator, expanded_->v[idx]->code); + accessor = grib_accessor_factory(section, &creator, 0, NULL); + elementAccessor = dynamic_cast(accessor); + + elementAccessor->index(ide); + elementAccessor->descriptors(expanded_); + elementAccessor->elementsDescriptorsIndex(elementsDescriptorsIndex_); + elementAccessor->numericValues(numericValues_); + elementAccessor->stringValues(stringValues_); + elementAccessor->compressedData(compressedData_); + elementAccessor->type(expanded_->v[idx]->type); + elementAccessor->numberOfSubsets(numberOfSubsets_); + elementAccessor->subsetNumber(subset); attribute = create_attribute_variable("index", section, GRIB_TYPE_LONG, 0, 0, count, flags); if (!attribute) return NULL; - elementAccessor->add_attribute(attribute, 0); + accessor->add_attribute(attribute, 0); - snprintf(code, sizeof(code), "%06ld", self->expanded_->v[idx]->code); + snprintf(code, sizeof(code), "%06ld", expanded_->v[idx]->code); attribute = create_attribute_variable("code", section, GRIB_TYPE_STRING, code, 0, 0, flags); if (!attribute) return NULL; - elementAccessor->add_attribute(attribute, 0); + accessor->add_attribute(attribute, 0); if (add_extra_attributes) { - attribute = create_attribute_variable("units", section, GRIB_TYPE_STRING, self->expanded_->v[idx]->units, 0, 0, GRIB_ACCESSOR_FLAG_DUMP); + attribute = create_attribute_variable("units", section, GRIB_TYPE_STRING, expanded_->v[idx]->units, 0, 0, GRIB_ACCESSOR_FLAG_DUMP); if (!attribute) return NULL; - elementAccessor->add_attribute(attribute, 0); + accessor->add_attribute(attribute, 0); - attribute = create_attribute_variable("scale", section, GRIB_TYPE_LONG, 0, 0, self->expanded_->v[idx]->scale, flags); + attribute = create_attribute_variable("scale", section, GRIB_TYPE_LONG, 0, 0, expanded_->v[idx]->scale, flags); if (!attribute) return NULL; - elementAccessor->add_attribute(attribute, 0); + accessor->add_attribute(attribute, 0); - attribute = create_attribute_variable("reference", section, GRIB_TYPE_DOUBLE, 0, self->expanded_->v[idx]->reference, 0, flags); + attribute = create_attribute_variable("reference", section, GRIB_TYPE_DOUBLE, 0, expanded_->v[idx]->reference, 0, flags); if (!attribute) return NULL; - elementAccessor->add_attribute(attribute, 0); + accessor->add_attribute(attribute, 0); - attribute = create_attribute_variable("width", section, GRIB_TYPE_LONG, 0, 0, self->expanded_->v[idx]->width, flags); + attribute = create_attribute_variable("width", section, GRIB_TYPE_LONG, 0, 0, expanded_->v[idx]->width, flags); if (!attribute) return NULL; - elementAccessor->add_attribute(attribute, 0); + accessor->add_attribute(attribute, 0); } break; } - return elementAccessor; + return accessor; } /* Section 3.1.2.2 of WMO BUFR guide: classes 03 and 09 at present reserved for future use */ @@ -1998,14 +1998,8 @@ static GRIB_INLINE void reset_deeper_qualifiers( } } -typedef struct bitmap_s -{ - grib_accessors_list* cursor; - grib_accessors_list* referredElement; - grib_accessors_list* referredElementStart; -} bitmap_s; -static grib_accessor* get_element_from_bitmap(const grib_accessor* a, bitmap_s* bitmap) +static grib_accessor* get_element_from_bitmap(bitmap_s* bitmap) { int ret; long bitmapVal = 1; @@ -2045,11 +2039,11 @@ static void grib_convert_to_attribute(grib_accessor* a) } /* subsetList can be NULL in which case subsetListSize will be 0 */ -static grib_iarray* set_subset_list( - grib_context* c, grib_accessor_bufr_data_array_t* self, +grib_iarray* grib_accessor_bufr_data_array_t::set_subset_list( + grib_context* c, long onlySubset, long startSubset, long endSubset, const long* subsetList, size_t subsetListSize) { - grib_iarray* list = grib_iarray_new(c, self->numberOfSubsets_, 10); + grib_iarray* list = grib_iarray_new(c, numberOfSubsets_, 10); long s = 0; #ifdef DEBUG @@ -2077,7 +2071,7 @@ static grib_iarray* set_subset_list( } if (grib_iarray_used_size(list) == 0) { - for (s = 0; s < self->numberOfSubsets_; s++) + for (s = 0; s < numberOfSubsets_; s++) grib_iarray_push(list, s); } @@ -2248,10 +2242,9 @@ static int grib_data_accessors_trie_push(grib_trie_with_rank* accessorsTrie, gri return grib_trie_with_rank_insert(accessorsTrie, a->name_, a); } -static int create_keys(const grib_accessor* a, long onlySubset, long startSubset, long endSubset) +int grib_accessor_bufr_data_array_t::create_keys(long onlySubset, long startSubset, long endSubset) { - grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; - int err = 0; + int err = 0; int rank; grib_accessor* elementAccessor = 0; grib_accessor* associatedFieldAccessor = 0; @@ -2267,7 +2260,7 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset int depth; int max_depth = -1; /* highest value of depth */ int idx; - grib_context* c = a->context_; + grib_context* c = context_; int qualityPresent = 0; bitmap_s bitmap = { 0, @@ -2302,7 +2295,7 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset int bitmapIndex = -1; int incrementBitmapIndex = 1; grib_accessor* elementFromBitmap = NULL; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); /*int reuseBitmap=0;*/ int add_dump_flag = 1, add_coord_flag = 0, count = 0; /*int forceGroupClosure=0;*/ @@ -2313,28 +2306,28 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset creatorGroup.flags = GRIB_ACCESSOR_FLAG_DUMP; creatorGroup.set = 0; - if (self->dataAccessors_) { - grib_accessors_list_delete(c, self->dataAccessors_); + if (dataAccessors_) { + grib_accessors_list_delete(c, dataAccessors_); } - self->dataAccessors_ = grib_accessors_list_create(c); + dataAccessors_ = grib_accessors_list_create(c); - if (self->dataAccessorsTrie_) { + if (dataAccessorsTrie_) { /* ECC-989: do not call grib_trie_with_rank_delete */ - grib_trie_with_rank_delete_container(self->dataAccessorsTrie_); + grib_trie_with_rank_delete_container(dataAccessorsTrie_); } - self->dataAccessorsTrie_ = grib_trie_with_rank_new(c); + dataAccessorsTrie_ = grib_trie_with_rank_new(c); - if (self->tempStrings_) { - grib_sarray_delete_content(c, self->tempStrings_); - grib_sarray_delete(c, self->tempStrings_); - self->tempStrings_ = NULL; + if (tempStrings_) { + grib_sarray_delete_content(c, tempStrings_); + grib_sarray_delete(c, tempStrings_); + tempStrings_ = NULL; } - self->tempStrings_ = self->numberOfSubsets_ ? grib_sarray_new(c, self->numberOfSubsets_, 500) : NULL; + tempStrings_ = numberOfSubsets_ ? grib_sarray_new(c, numberOfSubsets_, 500) : NULL; - end = self->compressedData_ ? 1 : self->numberOfSubsets_; + end = compressedData_ ? 1 : numberOfSubsets_; // groupNumber = 1; - gaGroup = grib_accessor_factory(self->dataKeys_, &creatorGroup, 0, NULL); + gaGroup = grib_accessor_factory(dataKeys_, &creatorGroup, 0, NULL); // gaGroup->bufr_group_number = groupNumber; gaGroup->sub_section_ = grib_section_create(hand, gaGroup); section = gaGroup->sub_section_; @@ -2345,8 +2338,8 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset /* ECC-765: Don't empty out the section_4 keys otherwise there will be memory leaks. */ /* Setting first and last to zero effectively masks out those section 4 keys! */ /* self->dataKeys_->block->first=0; */ - /* self->dataKeys_->block->last=0; */ - grib_push_accessor(gaGroup, self->dataKeys_->block); /* Add group accessors to section 4 */ + /* dataKeys_->block->last=0; */ + grib_push_accessor(gaGroup, dataKeys_->block); /* Add group accessors to section 4 */ /*indexOfGroupNumber=0;*/ depth = 0; @@ -2356,7 +2349,7 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset for (iss = 0; iss < end; iss++) { qualityPresent = 0; /*forceGroupClosure=0;*/ - elementsInSubset = self->compressedData_ ? grib_iarray_used_size(self->elementsDescriptorsIndex_->v[0]) : grib_iarray_used_size(self->elementsDescriptorsIndex_->v[iss]); + elementsInSubset = compressedData_ ? grib_iarray_used_size(elementsDescriptorsIndex_->v[0]) : grib_iarray_used_size(elementsDescriptorsIndex_->v[iss]); /*if (associatedFieldAccessor) grib_accessor_delete(c, associatedFieldAccessor);*/ associatedFieldAccessor = NULL; if (associatedFieldSignificanceAccessor) { @@ -2364,16 +2357,16 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset associatedFieldSignificanceAccessor = NULL; } for (ide = 0; ide < elementsInSubset; ide++) { - idx = self->compressedData_ ? self->elementsDescriptorsIndex_->v[0]->v[ide] : self->elementsDescriptorsIndex_->v[iss]->v[ide]; + idx = compressedData_ ? elementsDescriptorsIndex_->v[0]->v[ide] : elementsDescriptorsIndex_->v[iss]->v[ide]; - descriptor = self->expanded_->v[idx]; + descriptor = expanded_->v[idx]; if (descriptor->nokey == 1) { continue; /* Descriptor does not have an associated key e.g. inside op 203YYY */ } elementFromBitmap = NULL; add_coord_flag = 0; if (descriptor->F == 0 && IS_COORDINATE_DESCRIPTOR(descriptor->X) && - self->unpackMode_ == CODES_BUFR_UNPACK_STRUCTURE) { + unpackMode_ == CODES_BUFR_UNPACK_STRUCTURE) { const int sidx = descriptor->Y + significanceQualifierIndexArray[descriptor->X] * NUMBER_OF_QUALIFIERS_PER_CATEGORY; DEBUG_ASSERT(sidx > 0); // groupNumber++; @@ -2428,9 +2421,9 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset // return err; bitmapIndex--; } - bitmapStart[bitmapIndex] = self->dataAccessors_->last(); + bitmapStart[bitmapIndex] = dataAccessors_->last(); bitmapSize[bitmapIndex] = 1; - if (self->expanded_->v[idx - 1]->code == 31002 || self->expanded_->v[idx - 1]->code == 31001) + if (expanded_->v[idx - 1]->code == 31002 || expanded_->v[idx - 1]->code == 31001) extraElement += 1; if (bitmapGroup[bitmapIndex]) { @@ -2487,7 +2480,7 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset else if ((descriptor->X == 33 || bufr_descriptor_is_marker(descriptor)) && qualityPresent) { if (!bitmap.referredElement) bitmap_init(c, &bitmap, bitmapStart[bitmapIndex], bitmapSize[bitmapIndex], lastAccessorInList); - elementFromBitmap = get_element_from_bitmap(a, &bitmap); + elementFromBitmap = get_element_from_bitmap(&bitmap); add_dump_flag = 1; /* } else if ( descriptor->Y==1 && IS_COORDINATE_DESCRIPTOR(self->expanded_ ->v[idx-1]->X)==0) { */ /* forceGroupClosure=1; */ @@ -2497,8 +2490,8 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset add_dump_flag = 1; /* ECC-690: percentConfidence WITHOUT a bitmap! e.g. NOAA GOES16 BUFR */ } - if (ide == 0 && !self->compressedData_) { - grib_accessor* asn = NULL; + if (ide == 0 && !compressedData_) { + long subsetNumber = iss + 1; size_t len = 1; grib_action creatorsn = { @@ -2509,16 +2502,17 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset creatorsn.flags = GRIB_ACCESSOR_FLAG_READ_ONLY | GRIB_ACCESSOR_FLAG_DUMP; creatorsn.set = 0; - creatorsn.name = (char*)"subsetNumber"; - asn = grib_accessor_factory(section, &creatorsn, 0, NULL); - accessor_variable_set_type(asn, GRIB_TYPE_LONG); + creatorsn.name = (char*)"subsetNumber"; + grib_accessor* a = grib_accessor_factory(section, &creatorsn, 0, NULL); + grib_accessor_variable_t* asn = dynamic_cast(a); + asn->accessor_variable_set_type(GRIB_TYPE_LONG); asn->pack_long(&subsetNumber, &len); grib_push_accessor(asn, section->block); - rank = grib_data_accessors_trie_push(self->dataAccessorsTrie_, asn); - self->dataAccessors_->push(asn, rank); + rank = grib_data_accessors_trie_push(dataAccessorsTrie_, asn); + dataAccessors_->push(asn, rank); } count++; - elementAccessor = create_accessor_from_descriptor(a, associatedFieldAccessor, section, ide, iss, + elementAccessor = create_accessor_from_descriptor(associatedFieldAccessor, section, ide, iss, add_dump_flag, add_coord_flag, count, add_extra_attributes); if (!elementAccessor) { err = GRIB_DECODING_ERROR; @@ -2530,16 +2524,16 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset /*if (associatedFieldAccessor) grib_accessor_delete(c, associatedFieldAccessor);*/ associatedFieldAccessor = NULL; - if (elementFromBitmap && self->unpackMode_ == CODES_BUFR_UNPACK_STRUCTURE) { + if (elementFromBitmap && unpackMode_ == CODES_BUFR_UNPACK_STRUCTURE) { if (descriptor->code != 33007 && descriptor->code != 223255) { char* aname = grib_context_strdup(c, elementFromBitmap->name_); grib_accessor* newAccessor = elementAccessor->clone(section, &err); newAccessor->parent_ = groupSection; newAccessor->name_ = aname; - grib_sarray_push(a->context_, self->tempStrings_, aname); + grib_sarray_push(context_, tempStrings_, aname); grib_push_accessor(newAccessor, groupSection->block); - rank = grib_data_accessors_trie_push(self->dataAccessorsTrie_, newAccessor); - self->dataAccessors_->push(newAccessor, rank); + rank = grib_data_accessors_trie_push(dataAccessorsTrie_, newAccessor); + dataAccessors_->push(newAccessor, rank); } // err = grib_accessor_add_attribute(accessor_or_attribute_with_same_name(elementFromBitmap, elementAccessor->name), elementAccessor, 1); @@ -2555,7 +2549,7 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset if (associatedFieldSignificanceAccessor) { grib_accessor* newAccessor = associatedFieldSignificanceAccessor->clone(section, &err); if (err) { - grib_context_log(a->context_, GRIB_LOG_ERROR, "Unable to clone accessor '%s'\n", associatedFieldSignificanceAccessor->name_); + grib_context_log(context_, GRIB_LOG_ERROR, "Unable to clone accessor '%s'\n", associatedFieldSignificanceAccessor->name_); return err; } associatedFieldAccessor->add_attribute(newAccessor, 1); @@ -2580,9 +2574,9 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset } if (add_key) { grib_push_accessor(elementAccessor, section->block); - rank = grib_data_accessors_trie_push(self->dataAccessorsTrie_, elementAccessor); - self->dataAccessors_->push(elementAccessor, rank); - lastAccessorInList = self->dataAccessors_->last(); + rank = grib_data_accessors_trie_push(dataAccessorsTrie_, elementAccessor); + dataAccessors_->push(elementAccessor, rank); + lastAccessorInList = dataAccessors_->last(); } } } @@ -2592,67 +2586,67 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset return err; } -static void set_input_replications(grib_handle* h, grib_accessor_bufr_data_array_t* self) +void grib_accessor_bufr_data_array_t::set_input_replications(grib_handle* h) { size_t nInputReplications; size_t nInputExtendedReplications; size_t nInputShortReplications; - self->nInputReplications_ = -1; - self->nInputExtendedReplications_ = -1; - self->nInputShortReplications_ = -1; - self->iInputReplications_ = 0; - self->iInputExtendedReplications_ = 0; - self->iInputShortReplications_ = 0; + nInputReplications_ = -1; + nInputExtendedReplications_ = -1; + nInputShortReplications_ = -1; + iInputReplications_ = 0; + iInputExtendedReplications_ = 0; + iInputShortReplications_ = 0; if (grib_get_size(h, "inputDelayedDescriptorReplicationFactor", &nInputReplications) == 0 && nInputReplications != 0) { - if (self->inputReplications_) - grib_context_free(h->context, self->inputReplications_); - self->inputReplications_ = (long*)grib_context_malloc_clear(h->context, sizeof(long) * nInputReplications); - grib_get_long_array(h, "inputDelayedDescriptorReplicationFactor", self->inputReplications_, &nInputReplications); + if (inputReplications_) + grib_context_free(h->context, inputReplications_); + inputReplications_ = (long*)grib_context_malloc_clear(h->context, sizeof(long) * nInputReplications); + grib_get_long_array(h, "inputDelayedDescriptorReplicationFactor", inputReplications_, &nInputReplications); /* default-> no input replications*/ - if (self->inputReplications_[0] < 0) - self->nInputReplications_ = -1; + if (inputReplications_[0] < 0) + nInputReplications_ = -1; else - self->nInputReplications_ = nInputReplications; + nInputReplications_ = nInputReplications; } if (grib_get_size(h, "inputExtendedDelayedDescriptorReplicationFactor", &nInputExtendedReplications) == 0 && nInputExtendedReplications != 0) { - if (self->inputExtendedReplications_) - grib_context_free(h->context, self->inputExtendedReplications_); - self->inputExtendedReplications_ = (long*)grib_context_malloc_clear(h->context, sizeof(long) * nInputExtendedReplications); - grib_get_long_array(h, "inputExtendedDelayedDescriptorReplicationFactor", self->inputExtendedReplications_, &nInputExtendedReplications); + if (inputExtendedReplications_) + grib_context_free(h->context, inputExtendedReplications_); + inputExtendedReplications_ = (long*)grib_context_malloc_clear(h->context, sizeof(long) * nInputExtendedReplications); + grib_get_long_array(h, "inputExtendedDelayedDescriptorReplicationFactor", inputExtendedReplications_, &nInputExtendedReplications); /* default-> no input replications*/ - if (self->inputExtendedReplications_[0] < 0) - self->nInputExtendedReplications_ = -1; + if (inputExtendedReplications_[0] < 0) + nInputExtendedReplications_ = -1; else - self->nInputExtendedReplications_ = nInputExtendedReplications; + nInputExtendedReplications_ = nInputExtendedReplications; } if (grib_get_size(h, "inputShortDelayedDescriptorReplicationFactor", &nInputShortReplications) == 0 && nInputShortReplications != 0) { - if (self->inputShortReplications_) - grib_context_free(h->context, self->inputShortReplications_); - self->inputShortReplications_ = (long*)grib_context_malloc_clear(h->context, sizeof(long) * nInputShortReplications); - grib_get_long_array(h, "inputShortDelayedDescriptorReplicationFactor", self->inputShortReplications_, &nInputShortReplications); + if (inputShortReplications_) + grib_context_free(h->context, inputShortReplications_); + inputShortReplications_ = (long*)grib_context_malloc_clear(h->context, sizeof(long) * nInputShortReplications); + grib_get_long_array(h, "inputShortDelayedDescriptorReplicationFactor", inputShortReplications_, &nInputShortReplications); /* default-> no input replications*/ - if (self->inputShortReplications_[0] < 0) - self->nInputShortReplications_ = -1; + if (inputShortReplications_[0] < 0) + nInputShortReplications_ = -1; else - self->nInputShortReplications_ = nInputShortReplications; + nInputShortReplications_ = nInputShortReplications; } } -static void set_input_bitmap(grib_handle* h, grib_accessor_bufr_data_array_t* self) +void grib_accessor_bufr_data_array_t::set_input_bitmap(grib_handle* h) { size_t nInputBitmap; - self->nInputBitmap_ = -1; - self->iInputBitmap_ = 0; + nInputBitmap_ = -1; + iInputBitmap_ = 0; if (grib_get_size(h, "inputDataPresentIndicator", &nInputBitmap) == 0 && nInputBitmap != 0) { - if (self->inputBitmap_) - grib_context_free(h->context, self->inputBitmap_); - self->inputBitmap_ = (double*)grib_context_malloc_clear(h->context, sizeof(double) * nInputBitmap); - grib_get_double_array(h, "inputDataPresentIndicator", self->inputBitmap_, &nInputBitmap); + if (inputBitmap_) + grib_context_free(h->context, inputBitmap_); + inputBitmap_ = (double*)grib_context_malloc_clear(h->context, sizeof(double) * nInputBitmap); + grib_get_double_array(h, "inputDataPresentIndicator", inputBitmap_, &nInputBitmap); /* default-> no input bitmap*/ - if (self->inputBitmap_[0] < 0) - self->nInputBitmap_ = -1; + if (inputBitmap_[0] < 0) + nInputBitmap_ = -1; else - self->nInputBitmap_ = nInputBitmap; + nInputBitmap_ = nInputBitmap; } } @@ -2668,10 +2662,9 @@ static int set_to_missing_if_out_of_range(grib_handle* h) return h->context->bufr_set_to_missing_if_out_of_range; } -static int process_elements(grib_accessor* a, int flag, long onlySubset, long startSubset, long endSubset) +int grib_accessor_bufr_data_array_t::process_elements(int flag, long onlySubset, long startSubset, long endSubset) { - grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; - int err = 0; + int err = 0; long inr, innr, ir, ip; long n[MAX_NESTED_REPLICATIONS] = { 0, @@ -2711,20 +2704,20 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st grib_darray* dval = NULL; grib_sarray* sval = NULL; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); grib_context* c = h->context; - totalSize = self->bitsToEndData_; + totalSize = bitsToEndData_; switch (flag) { case PROCESS_DECODE: - if (!self->do_decode_) + if (!do_decode_) return 0; - self->do_decode_ = 0; - buffer = h->buffer; - decoding = 1; - do_clean = 1; - dataAccessor = grib_find_accessor(grib_handle_of_accessor(a), self->bufrDataEncodedName_); + do_decode_ = 0; + buffer = h->buffer; + decoding = 1; + do_clean = 1; + dataAccessor = grib_find_accessor(grib_handle_of_accessor(this), bufrDataEncodedName_); DEBUG_ASSERT(dataAccessor); dataOffset = accessor_raw_get_offset(dataAccessor); pos = dataOffset * 8; @@ -2732,38 +2725,38 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st codec_replication = &decode_replication; break; case PROCESS_NEW_DATA: - buffer = grib_create_growable_buffer(c); - decoding = 0; - do_clean = 1; - self->do_decode_ = 1; - self->set_to_missing_if_out_of_range_ = set_to_missing_if_out_of_range(h); - pos = 0; - codec_element = &encode_new_element; - codec_replication = &encode_new_replication; + buffer = grib_create_growable_buffer(c); + decoding = 0; + do_clean = 1; + do_decode_ = 1; + set_to_missing_if_out_of_range_ = set_to_missing_if_out_of_range(h); + pos = 0; + codec_element = &encode_new_element; + codec_replication = &encode_new_replication; - set_input_replications(h, self); - set_input_bitmap(h, self); + set_input_replications(h); + set_input_bitmap(h); break; case PROCESS_ENCODE: - buffer = grib_create_growable_buffer(c); - decoding = 0; - do_clean = 0; - self->do_decode_ = 0; - self->set_to_missing_if_out_of_range_ = set_to_missing_if_out_of_range(h); - pos = 0; - codec_element = &encode_element; - grib_get_long(grib_handle_of_accessor(a), "extractSubset", &onlySubset); - grib_get_long(grib_handle_of_accessor(a), "extractSubsetIntervalStart", &startSubset); - grib_get_long(grib_handle_of_accessor(a), "extractSubsetIntervalEnd", &endSubset); - err = grib_get_size(grib_handle_of_accessor(a), "extractSubsetList", &subsetListSize); + buffer = grib_create_growable_buffer(c); + decoding = 0; + do_clean = 0; + do_decode_ = 0; + set_to_missing_if_out_of_range_ = set_to_missing_if_out_of_range(h); + pos = 0; + codec_element = &encode_element; + grib_get_long(grib_handle_of_accessor(this), "extractSubset", &onlySubset); + grib_get_long(grib_handle_of_accessor(this), "extractSubsetIntervalStart", &startSubset); + grib_get_long(grib_handle_of_accessor(this), "extractSubsetIntervalEnd", &endSubset); + err = grib_get_size(grib_handle_of_accessor(this), "extractSubsetList", &subsetListSize); if (err) return err; if (subsetList) grib_context_free(c, subsetList); if (subsetListSize) { subsetList = (long*)grib_context_malloc_clear(c, subsetListSize * sizeof(long)); - err = grib_get_long_array(grib_handle_of_accessor(a), "extractSubsetList", subsetList, &subsetListSize); + err = grib_get_long_array(grib_handle_of_accessor(this), "extractSubsetList", subsetList, &subsetListSize); if (err) return err; } codec_replication = &encode_replication; @@ -2773,88 +2766,88 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st } data = buffer->data; - err = get_descriptors(a); + err = get_descriptors(); if (err) return err; - descriptors = self->expanded_->v; + descriptors = expanded_->v; if (!descriptors) { grib_context_log(c, GRIB_LOG_ERROR, "No descriptors found!"); return GRIB_INTERNAL_ERROR; } - if (do_clean == 1 && self->numericValues_) { - grib_vdarray_delete_content(c, self->numericValues_); - grib_vdarray_delete(c, self->numericValues_); - /*printf("dbg process_elements: clear %p\n", (void*)(self->stringValues_ ));*/ - grib_vsarray_delete_content(c, self->stringValues_); - grib_vsarray_delete(c, self->stringValues_); - self->stringValues_ = NULL; + if (do_clean == 1 && numericValues_) { + grib_vdarray_delete_content(c, numericValues_); + grib_vdarray_delete(c, numericValues_); + /*printf("dbg process_elements: clear %p\n", (void*)(stringValues_ ));*/ + grib_vsarray_delete_content(c, stringValues_); + grib_vsarray_delete(c, stringValues_); + stringValues_ = NULL; } if (flag != PROCESS_ENCODE) { - self->numericValues_ = grib_vdarray_new(c, 1000, 1000); - self->stringValues_ = grib_vsarray_new(c, 10, 10); + numericValues_ = grib_vdarray_new(c, 1000, 1000); + stringValues_ = grib_vsarray_new(c, 10, 10); - if (self->elementsDescriptorsIndex_) { - grib_viarray_delete_content(c, self->elementsDescriptorsIndex_); - grib_viarray_delete(c, self->elementsDescriptorsIndex_); + if (elementsDescriptorsIndex_) { + grib_viarray_delete_content(c, elementsDescriptorsIndex_); + grib_viarray_delete(c, elementsDescriptorsIndex_); } - self->elementsDescriptorsIndex_ = grib_viarray_new(c, 100, 100); + elementsDescriptorsIndex_ = grib_viarray_new(c, 100, 100); } if (flag == PROCESS_NEW_DATA) { - self->tempDoubleValues_ = grib_vdarray_new(c, 1000, 1000); + tempDoubleValues_ = grib_vdarray_new(c, 1000, 1000); } if (flag != PROCESS_DECODE) { /* Operator 203YYY: key OVERRIDDEN_REFERENCE_VALUES_KEY */ - err = grib_get_size(h, OVERRIDDEN_REFERENCE_VALUES_KEY, &self->refValListSize_); + err = grib_get_size(h, OVERRIDDEN_REFERENCE_VALUES_KEY, &refValListSize_); if (err) return err; - if (self->refValList_) - grib_context_free(c, self->refValList_); - if (self->refValListSize_ > 0) { - self->refValList_ = (long*)grib_context_malloc_clear(c, self->refValListSize_ * sizeof(long)); - err = grib_get_long_array(grib_handle_of_accessor(a), OVERRIDDEN_REFERENCE_VALUES_KEY, self->refValList_, &self->refValListSize_); + if (refValList_) + grib_context_free(c, refValList_); + if (refValListSize_ > 0) { + refValList_ = (long*)grib_context_malloc_clear(c, refValListSize_ * sizeof(long)); + err = grib_get_long_array(grib_handle_of_accessor(this), OVERRIDDEN_REFERENCE_VALUES_KEY, refValList_, &refValListSize_); if (err) return err; } } - numberOfDescriptors = grib_bufr_descriptors_array_used_size(self->expanded_); + numberOfDescriptors = grib_bufr_descriptors_array_used_size(expanded_); - if (self->iss_list_) { - grib_iarray_delete(self->iss_list_); - self->iss_list_ = 0; + if (iss_list_) { + grib_iarray_delete(iss_list_); + iss_list_ = 0; } - end = self->compressedData_ == 1 ? 1 : self->numberOfSubsets_; + end = compressedData_ == 1 ? 1 : numberOfSubsets_; if (flag != PROCESS_DECODE) { - self->iss_list_ = set_subset_list(c, self, onlySubset, startSubset, endSubset, subsetList, subsetListSize); - end = self->compressedData_ == 1 ? 1 : grib_iarray_used_size(self->iss_list_); + iss_list_ = set_subset_list(c, onlySubset, startSubset, endSubset, subsetList, subsetListSize); + end = compressedData_ == 1 ? 1 : grib_iarray_used_size(iss_list_); } /* Go through all subsets */ for (iiss = 0; iiss < end; iiss++) { icount = 1; - if (self->compressedData_ == 0 && self->iss_list_) { - iss = self->iss_list_->v[iiss]; + if (compressedData_ == 0 && iss_list_) { + iss = iss_list_->v[iiss]; } else { iss = iiss; } grib_context_log(c, GRIB_LOG_DEBUG, "BUFR data processing: subsetNumber=%ld", iss + 1); - self->refValIndex_ = 0; + refValIndex_ = 0; if (flag != PROCESS_ENCODE) { elementsDescriptorsIndex = grib_iarray_new(c, DYN_ARRAY_SIZE_INIT, DYN_ARRAY_SIZE_INCR); - if (!self->compressedData_) { + if (!compressedData_) { dval = grib_darray_new(c, DYN_ARRAY_SIZE_INIT, DYN_ARRAY_SIZE_INCR); } } else { - if (self->elementsDescriptorsIndex_ == NULL) { + if (elementsDescriptorsIndex_ == NULL) { return GRIB_ENCODING_ERROR; /* See ECC-359 */ } - elementsDescriptorsIndex = self->elementsDescriptorsIndex_->v[iss]; - dval = self->numericValues_->v[iss]; + elementsDescriptorsIndex = elementsDescriptorsIndex_->v[iss]; + dval = numericValues_->v[iss]; } elementIndex = 0; @@ -2866,18 +2859,18 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st switch (descriptors[i]->F) { case 0: /* Table B element */ - op203_definition_phase = (self->change_ref_value_operand_ > 0 && self->change_ref_value_operand_ != 255); + op203_definition_phase = (change_ref_value_operand_ > 0 && change_ref_value_operand_ != 255); if (flag != PROCESS_ENCODE) { if (!op203_definition_phase) grib_iarray_push(elementsDescriptorsIndex, i); } - if (descriptors[i]->code == 31031 && !is_bitmap_start_defined(self)) { - /* self->bitmapStart_ =grib_iarray_used_size(elementsDescriptorsIndex)-1; */ - self->bitmapStart_ = elementIndex; + if (descriptors[i]->code == 31031 && !is_bitmap_start_defined()) { + /* bitmapStart_ =grib_iarray_used_size(elementsDescriptorsIndex)-1; */ + bitmapStart_ = elementIndex; } - err = codec_element(c, self, iss, buffer, data, &pos, i, 0, elementIndex, dval, sval); + err = codec_element(c, this, iss, buffer, data, &pos, i, 0, elementIndex, dval, sval); if (err) return err; if (!op203_definition_phase) elementIndex++; @@ -2892,7 +2885,7 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st i++; data = buffer->data; /* ECC-517 */ - err = codec_replication(c, self, iss, buffer, data, &pos, i, elementIndex, dval, &(numberOfRepetitions[inr])); + err = codec_replication(c, this, iss, buffer, data, &pos, i, elementIndex, dval, &(numberOfRepetitions[inr])); if (err) return err; startRepetition[inr] = i; @@ -2926,42 +2919,42 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st /* Operator */ switch (descriptors[i]->X) { case 3: /* Change reference values */ - if (self->compressedData_ == 1 && flag != PROCESS_DECODE) { + if (compressedData_ == 1 && flag != PROCESS_DECODE) { grib_context_log(c, GRIB_LOG_ERROR, "process_elements: operator %d not supported for encoding compressed data", descriptors[i]->X); return GRIB_INTERNAL_ERROR; } if (descriptors[i]->Y == 255) { grib_context_log(c, GRIB_LOG_DEBUG, "Operator 203YYY: Y=255, definition of new reference values is concluded"); - self->change_ref_value_operand_ = 255; + change_ref_value_operand_ = 255; /*if (c->debug) tableB_override_dump(self);*/ if (iss == 0 && flag == PROCESS_DECODE) { /*Write out the contents of the TableB overridden reference values to the transient array key*/ - err = tableB_override_set_key(h, self); + err = tableB_override_set_key(h); if (err) return err; } if (flag != PROCESS_DECODE) { /* Encoding operator 203YYY */ - if (self->refValIndex_ != self->refValListSize_) { + if (refValIndex_ != refValListSize_) { grib_context_log(c, GRIB_LOG_ERROR, "process_elements: The number of overridden reference values (%ld) different from" " number of descriptors between operator 203YYY and 203255 (%ld)", - self->refValListSize_, self->refValIndex_); + refValListSize_, refValIndex_); return GRIB_ENCODING_ERROR; } } } else if (descriptors[i]->Y == 0) { grib_context_log(c, GRIB_LOG_DEBUG, "Operator 203YYY: Y=0, clearing override of table B"); - tableB_override_clear(c, self); - self->change_ref_value_operand_ = 0; + tableB_override_clear(c); + change_ref_value_operand_ = 0; } else { const int numBits = descriptors[i]->Y; grib_context_log(c, GRIB_LOG_DEBUG, "Operator 203YYY: Definition phase: Num bits=%d", numBits); - self->change_ref_value_operand_ = numBits; - tableB_override_clear(c, self); + change_ref_value_operand_ = numBits; + tableB_override_clear(c); if (flag != PROCESS_DECODE) { - err = check_overridden_reference_values(c, self->refValList_, self->refValListSize_, numBits); + err = check_overridden_reference_values(c, refValList_, refValListSize_, numBits); if (err) return err; } } @@ -2971,7 +2964,7 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st case 5: /* Signify character */ descriptors[i]->width = descriptors[i]->Y * 8; descriptors[i]->type = BUFR_DESCRIPTOR_TYPE_STRING; - err = codec_element(c, self, iss, buffer, data, &pos, i, 0, elementIndex, dval, sval); + err = codec_element(c, this, iss, buffer, data, &pos, i, 0, elementIndex, dval, sval); if (err) return err; if (flag != PROCESS_ENCODE) grib_iarray_push(elementsDescriptorsIndex, i); @@ -2981,16 +2974,16 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st if (descriptors[i]->Y == 0) { if (flag == PROCESS_DECODE) { grib_iarray_push(elementsDescriptorsIndex, i); - push_zero_element(self, dval); + push_zero_element(dval); } else if (flag == PROCESS_ENCODE) { if (descriptors[i + 1] && descriptors[i + 1]->code != 236000 && descriptors[i + 1]->code != 237000) - restart_bitmap(self); + restart_bitmap(); } else if (flag == PROCESS_NEW_DATA) { grib_iarray_push(elementsDescriptorsIndex, i); if (descriptors[i + 1] && descriptors[i + 1]->code != 236000 && descriptors[i + 1]->code != 237000) - consume_bitmap(self, i); + consume_bitmap(i); } elementIndex++; } @@ -3010,20 +3003,20 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st if (flag != PROCESS_ENCODE) grib_iarray_push(elementsDescriptorsIndex, i); if (decoding) - push_zero_element(self, dval); + push_zero_element(dval); elementIndex++; break; case 24: /* First-order statistical values marker operator */ case 32: /* Replaced/retained values marker operator */ if (descriptors[i]->Y == 255) { - index = get_next_bitmap_descriptor_index(self, elementsDescriptorsIndex, dval); + index = get_next_bitmap_descriptor_index(elementsDescriptorsIndex, dval); if (index < 0) { /* Return value is an error code not an index */ err = index; return err; } - err = codec_element(c, self, iss, buffer, data, &pos, index, 0, elementIndex, dval, sval); + err = codec_element(c, this, iss, buffer, data, &pos, index, 0, elementIndex, dval, sval); if (err) return err; - /* self->expanded_ ->v[index] */ + /* expanded_ ->v[index] */ if (flag != PROCESS_ENCODE) grib_iarray_push(elementsDescriptorsIndex, i); elementIndex++; @@ -3032,21 +3025,21 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st if (flag != PROCESS_ENCODE) grib_iarray_push(elementsDescriptorsIndex, i); if (decoding) { - push_zero_element(self, dval); + push_zero_element(dval); } elementIndex++; } break; case 23: /* Substituted values operator */ if (descriptors[i]->Y == 255) { - index = get_next_bitmap_descriptor_index(self, elementsDescriptorsIndex, dval); + index = get_next_bitmap_descriptor_index(elementsDescriptorsIndex, dval); if (index < 0) { /* Return value is an error code not an index */ err = index; return err; } - err = codec_element(c, self, iss, buffer, data, &pos, index, 0, elementIndex, dval, sval); + err = codec_element(c, this, iss, buffer, data, &pos, index, 0, elementIndex, dval, sval); if (err) return err; - /* self->expanded_ ->v[index] */ + /* expanded_ ->v[index] */ if (flag != PROCESS_ENCODE) grib_iarray_push(elementsDescriptorsIndex, i); elementIndex++; @@ -3054,20 +3047,20 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st else { if (flag == PROCESS_DECODE) { grib_iarray_push(elementsDescriptorsIndex, i); - push_zero_element(self, dval); + push_zero_element(dval); if (descriptors[i + 1] && descriptors[i + 1]->code != 236000 && descriptors[i + 1]->code != 237000) { - err = build_bitmap(self, data, &pos, elementIndex, elementsDescriptorsIndex, i); + err = build_bitmap(data, &pos, elementIndex, elementsDescriptorsIndex, i); if (err) return err; } } else if (flag == PROCESS_ENCODE) { if (descriptors[i + 1] && descriptors[i + 1]->code != 236000 && descriptors[i + 1]->code != 237000) - restart_bitmap(self); + restart_bitmap(); } else if (flag == PROCESS_NEW_DATA) { grib_iarray_push(elementsDescriptorsIndex, i); if (descriptors[i + 1] && descriptors[i + 1]->code != 236000 && descriptors[i + 1]->code != 237000) { - err = build_bitmap_new_data(self, data, &pos, elementIndex, elementsDescriptorsIndex, i); + err = build_bitmap_new_data(data, &pos, elementIndex, elementsDescriptorsIndex, i); if (err) return err; } } @@ -3076,19 +3069,19 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st break; case 25: /* Difference statistical values marker operator */ if (descriptors[i]->Y == 255) { - index = get_next_bitmap_descriptor_index(self, elementsDescriptorsIndex, dval); + index = get_next_bitmap_descriptor_index(elementsDescriptorsIndex, dval); if (index < 0) { /* Return value is an error code not an index */ err = index; return err; } - bd = grib_bufr_descriptor_clone(self->expanded_->v[index]); + bd = grib_bufr_descriptor_clone(expanded_->v[index]); bd->reference = -codes_power(bd->width, 2); bd->width++; - err = codec_element(c, self, iss, buffer, data, &pos, index, bd, elementIndex, dval, sval); + err = codec_element(c, this, iss, buffer, data, &pos, index, bd, elementIndex, dval, sval); grib_bufr_descriptor_delete(bd); if (err) return err; - /* self->expanded_ ->v[index] */ + /* expanded_ ->v[index] */ if (flag != PROCESS_ENCODE) grib_iarray_push(elementsDescriptorsIndex, i); elementIndex++; @@ -3097,7 +3090,7 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st if (flag != PROCESS_ENCODE) grib_iarray_push(elementsDescriptorsIndex, i); if (decoding) - push_zero_element(self, dval); + push_zero_element(dval); elementIndex++; } break; @@ -3105,9 +3098,9 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st if (flag != PROCESS_ENCODE) { grib_iarray_push(elementsDescriptorsIndex, i); if (decoding) - push_zero_element(self, dval); + push_zero_element(dval); if (descriptors[i]->Y == 0) - cancel_bitmap(self); + cancel_bitmap(); } elementIndex++; break; @@ -3115,16 +3108,16 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st if (flag == PROCESS_DECODE) { grib_iarray_push(elementsDescriptorsIndex, i); if (decoding) - push_zero_element(self, dval); - err = build_bitmap(self, data, &pos, elementIndex, elementsDescriptorsIndex, i); + push_zero_element(dval); + err = build_bitmap(data, &pos, elementIndex, elementsDescriptorsIndex, i); if (err) return err; } else if (flag == PROCESS_ENCODE) { - restart_bitmap(self); + restart_bitmap(); } else if (flag == PROCESS_NEW_DATA) { grib_iarray_push(elementsDescriptorsIndex, i); - err = build_bitmap_new_data(self, data, &pos, elementIndex, elementsDescriptorsIndex, i); + err = build_bitmap_new_data(data, &pos, elementIndex, elementsDescriptorsIndex, i); if (err) return err; } elementIndex++; @@ -3133,13 +3126,13 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st if (flag != PROCESS_ENCODE) { grib_iarray_push(elementsDescriptorsIndex, i); if (decoding) - push_zero_element(self, dval); + push_zero_element(dval); } if (descriptors[i]->Y == 0) - restart_bitmap(self); + restart_bitmap(); /* cancel reuse */ else - cancel_bitmap(self); + cancel_bitmap(); elementIndex++; break; default: @@ -3150,7 +3143,7 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st case 9: /* Associated field */ if (descriptors[i]->X == 99 && descriptors[i]->Y == 999) { - err = codec_element(c, self, iss, buffer, data, &pos, i, 0, elementIndex, dval, sval); + err = codec_element(c, this, iss, buffer, data, &pos, i, 0, elementIndex, dval, sval); if (err) return err; if (flag != PROCESS_ENCODE) grib_iarray_push(elementsDescriptorsIndex, i); @@ -3202,31 +3195,31 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st } /* for all descriptors */ if (flag != PROCESS_ENCODE) { - grib_viarray_push(c, self->elementsDescriptorsIndex_, elementsDescriptorsIndex); + grib_viarray_push(c, elementsDescriptorsIndex_, elementsDescriptorsIndex); /*grib_iarray_print("DBG process_elements::elementsDescriptorsIndex", elementsDescriptorsIndex);*/ } - if (decoding && !self->compressedData_) { - grib_vdarray_push(c, self->numericValues_, dval); + if (decoding && !compressedData_) { + grib_vdarray_push(c, numericValues_, dval); /*grib_darray_print("DBG process_elements::dval", dval);*/ } - if (flag == PROCESS_NEW_DATA && !self->compressedData_) { - grib_vdarray_push(c, self->tempDoubleValues_, dval); /* ECC-1172 */ + if (flag == PROCESS_NEW_DATA && !compressedData_) { + grib_vdarray_push(c, tempDoubleValues_, dval); /* ECC-1172 */ } } /* for all subsets */ - /*grib_vdarray_print("DBG process_elements: self->numericValues", self->numericValues_ );*/ - /*grib_viarray_print("DBG process_elements: self->elementsDescriptorsIndex", self->elementsDescriptorsIndex_ );*/ + /*grib_vdarray_print("DBG process_elements: numericValues", numericValues_ );*/ + /*grib_viarray_print("DBG process_elements: elementsDescriptorsIndex", elementsDescriptorsIndex_ );*/ if (decoding) { - err = create_keys(a, 0, 0, 0); - self->bitsToEndData_ = totalSize; + err = create_keys(0, 0, 0); + bitsToEndData_ = totalSize; } else { - self->bitsToEndData_ = buffer->ulength * 8; - grib_set_bytes(grib_handle_of_accessor(a), self->bufrDataEncodedName_, buffer->data, &(buffer->ulength)); + bitsToEndData_ = buffer->ulength * 8; + grib_set_bytes(grib_handle_of_accessor(this), bufrDataEncodedName_, buffer->data, &(buffer->ulength)); grib_buffer_delete(c, buffer); - if (self->numberOfSubsets_ != grib_iarray_used_size(self->iss_list_)) { - grib_set_long(h, self->numberOfSubsetsName_, grib_iarray_used_size(self->iss_list_)); + if (numberOfSubsets_ != grib_iarray_used_size(iss_list_)) { + grib_set_long(h, numberOfSubsetsName_, grib_iarray_used_size(iss_list_)); } } @@ -3249,7 +3242,7 @@ int grib_accessor_bufr_data_array_t::value_count(long* count) int err = 0, l; long i; - err = process_elements(this, PROCESS_DECODE, 0, 0, 0); + err = process_elements(PROCESS_DECODE, 0, 0, 0); if (err) return err; @@ -3277,7 +3270,7 @@ int grib_accessor_bufr_data_array_t::unpack_double(double* val, size_t* len) if (unpackMode_ == CODES_BUFR_NEW_DATA) proc_flag = PROCESS_NEW_DATA; - err = process_elements(this, proc_flag, 0, 0, 0); + err = process_elements(proc_flag, 0, 0, 0); if (err) return err; if (!val) @@ -3322,7 +3315,7 @@ int grib_accessor_bufr_data_array_t::unpack_double(double* val, size_t* len) void grib_accessor_bufr_data_array_t::destroy(grib_context* c) { - self_clear(c, this); + self_clear(); if (dataAccessors_) grib_accessors_list_delete(c, dataAccessors_); if (dataAccessorsTrie_) { diff --git a/src/accessor/grib_accessor_class_bufr_data_array.h b/src/accessor/grib_accessor_class_bufr_data_array.h index 35e3a21ca..039332130 100644 --- a/src/accessor/grib_accessor_class_bufr_data_array.h +++ b/src/accessor/grib_accessor_class_bufr_data_array.h @@ -11,6 +11,22 @@ #pragma once #include "grib_accessor_class_gen.h" +#include "grib_accessor_class_expanded_descriptors.h" + +typedef struct bitmap_s +{ + grib_accessors_list* cursor; + grib_accessors_list* referredElement; + grib_accessors_list* referredElementStart; +} bitmap_s; + + +class grib_accessor_bufr_data_array_t; + +typedef int (*codec_element_proc)(grib_context*, grib_accessor_bufr_data_array_t*, int, grib_buffer*, unsigned char*, long*, int, bufr_descriptor*, long, grib_darray*, grib_sarray*); + +typedef int (*codec_replication_proc)(grib_context*, grib_accessor_bufr_data_array_t*, int, grib_buffer*, unsigned char*, long*, int, long, grib_darray*, long*); + class grib_accessor_bufr_data_array_t : public grib_accessor_gen_t { @@ -30,7 +46,12 @@ public: void dump(grib_dumper*) override; void init(const long, grib_arguments*) override; -public: + void accessor_bufr_data_array_set_unpackMode(int); + grib_accessors_list* accessor_bufr_data_array_get_dataAccessors(); + grib_trie_with_rank* accessor_bufr_data_array_get_dataAccessorsTrie(); + grib_vsarray* accessor_bufr_data_array_get_stringValues(); + +private: const char* bufrDataEncodedName_; const char* numberOfSubsetsName_; const char* expandedDescriptorsName_; @@ -39,7 +60,7 @@ public: const char* elementsDescriptorsIndexName_; const char* compressedDataName_; bufr_descriptors_array* expanded_; - grib_accessor* expandedAccessor_; + grib_accessor_expanded_descriptors_t* expandedAccessor_; int* canBeMissing_; long numberOfSubsets_; long compressedData_; @@ -78,9 +99,47 @@ public: long refValIndex_; bufr_tableb_override* tableb_override_; int set_to_missing_if_out_of_range_; -}; -grib_vsarray* accessor_bufr_data_array_get_stringValues(grib_accessor*); -grib_accessors_list* accessor_bufr_data_array_get_dataAccessors(grib_accessor*); -grib_trie_with_rank* accessor_bufr_data_array_get_dataAccessorsTrie(grib_accessor*); -void accessor_bufr_data_array_set_unpackMode(grib_accessor*, int unpackMode); + void restart_bitmap(); + void cancel_bitmap(); + int is_bitmap_start_defined(); + size_t get_length(); + void tableB_override_store_ref_val(grib_context*, int, long); + int tableB_override_get_ref_val(int, long*); + void tableB_override_clear(grib_context*); + int tableB_override_set_key(grib_handle*); + int get_descriptors(); + int decode_string_array(grib_context*, unsigned char*, long*, bufr_descriptor*); + int encode_string_array(grib_context*, grib_buffer*, long*, bufr_descriptor*, grib_sarray*); + int encode_double_array(grib_context*, grib_buffer*, long*, bufr_descriptor*, grib_darray*); + int encode_double_value(grib_context*, grib_buffer*, long*, bufr_descriptor*, double); + char* decode_string_value(grib_context*, unsigned char*, long*, bufr_descriptor*, int*); + double decode_double_value(grib_context*, unsigned char*, long*, bufr_descriptor*, int, int*); + int encode_new_bitmap(grib_context*, grib_buffer*, long*, int); + grib_darray* doubleValues = NULL; + int encode_overridden_reference_value(grib_context*, grib_buffer*, long*, bufr_descriptor*); + int build_bitmap(unsigned char*, long*, int, grib_iarray*, int); + int consume_bitmap(int); + int build_bitmap_new_data(unsigned char*, long*, int, grib_iarray*, int); + int get_next_bitmap_descriptor_index_new_bitmap(grib_iarray*, int); + int get_next_bitmap_descriptor_index(grib_iarray*, grib_darray*); + void push_zero_element(grib_darray*); + grib_accessor* create_attribute_variable(const char*, grib_section*, int, char*, double, long, unsigned long); + grib_accessor* create_accessor_from_descriptor(grib_accessor*, grib_section*, long, long, int, int, int, int); + grib_iarray* set_subset_list( grib_context*, long, long, long, const long*, size_t); + void print_bitmap_debug_info(grib_context*, bitmap_s*, grib_accessors_list*, int); + int create_keys(long, long, long); + void set_input_replications(grib_handle*); + void set_input_bitmap(grib_handle*); + int process_elements(int, long, long, long); + void self_clear(); + grib_darray* decode_double_array(grib_context* c, unsigned char* data, long* pos, bufr_descriptor* bd, int canBeMissing, int*); + + friend int check_end_data(grib_context*, bufr_descriptor*, grib_accessor_bufr_data_array_t*, int); + friend int decode_element(grib_context*, grib_accessor_bufr_data_array_t*, int, grib_buffer*, unsigned char*, long*, int, bufr_descriptor*, long, grib_darray*, grib_sarray*); + friend int decode_replication(grib_context*, grib_accessor_bufr_data_array_t*, int, grib_buffer*, unsigned char*, long*, int, long, grib_darray*, long*); + friend int encode_new_element(grib_context*, grib_accessor_bufr_data_array_t*, int, grib_buffer*, unsigned char*, long*, int, bufr_descriptor*, long, grib_darray*, grib_sarray*); + friend int encode_new_replication(grib_context*, grib_accessor_bufr_data_array_t*, int, grib_buffer*, unsigned char*, long*, int, long, grib_darray*, long*); + friend int encode_element(grib_context*, grib_accessor_bufr_data_array_t*, int, grib_buffer*, unsigned char*, long*, int, bufr_descriptor*, long, grib_darray*, grib_sarray*); + friend int encode_replication(grib_context*, grib_accessor_bufr_data_array_t*, int, grib_buffer*, unsigned char*, long*, int, long, grib_darray*, long*); +}; diff --git a/src/accessor/grib_accessor_class_bufr_data_element.cc b/src/accessor/grib_accessor_class_bufr_data_element.cc index 350a54fda..5c168861a 100644 --- a/src/accessor/grib_accessor_class_bufr_data_element.cc +++ b/src/accessor/grib_accessor_class_bufr_data_element.cc @@ -18,7 +18,6 @@ grib_accessor* grib_accessor_bufr_data_element_t::make_clone(grib_section* s, in grib_accessor* the_clone = NULL; grib_accessor* attribute = NULL; grib_accessor_bufr_data_element_t* elementAccessor; - grib_accessor_bufr_data_element_t* self; char* copied_name = NULL; int i; grib_action creator = { @@ -36,20 +35,19 @@ grib_accessor* grib_accessor_bufr_data_element_t::make_clone(grib_section* s, in the_clone = grib_accessor_factory(s, &creator, 0, NULL); copied_name = grib_context_strdup(context_, name_); the_clone->name_ = copied_name; - elementAccessor = (grib_accessor_bufr_data_element_t*)the_clone; - self = (grib_accessor_bufr_data_element_t*)this; + elementAccessor = dynamic_cast(the_clone); the_clone->flags_ = flags_; the_clone->parent_ = NULL; the_clone->h_ = s->h; - elementAccessor->index_ = self->index_; - elementAccessor->type_ = self->type_; - elementAccessor->numberOfSubsets_ = self->numberOfSubsets_; - elementAccessor->subsetNumber_ = self->subsetNumber_; - elementAccessor->compressedData_ = self->compressedData_; - elementAccessor->descriptors_ = self->descriptors_; - elementAccessor->numericValues_ = self->numericValues_; - elementAccessor->stringValues_ = self->stringValues_; - elementAccessor->elementsDescriptorsIndex_ = self->elementsDescriptorsIndex_; + elementAccessor->index_ = index_; + elementAccessor->type_ = type_; + elementAccessor->numberOfSubsets_ = numberOfSubsets_; + elementAccessor->subsetNumber_ = subsetNumber_; + elementAccessor->compressedData_ = compressedData_; + elementAccessor->descriptors_ = descriptors_; + elementAccessor->numericValues_ = numericValues_; + elementAccessor->stringValues_ = stringValues_; + elementAccessor->elementsDescriptorsIndex_ = elementsDescriptorsIndex_; elementAccessor->cname_ = copied_name; /* ECC-765 */ i = 0; @@ -63,60 +61,6 @@ grib_accessor* grib_accessor_bufr_data_element_t::make_clone(grib_section* s, in return the_clone; } -void accessor_bufr_data_element_set_index(grib_accessor* a, long index) -{ - grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; - self->index_ = index; -} - -void accessor_bufr_data_element_set_type(grib_accessor* a, int type) -{ - grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; - self->type_ = type; -} - -void accessor_bufr_data_element_set_numberOfSubsets(grib_accessor* a, long numberOfSubsets) -{ - grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; - self->numberOfSubsets_ = numberOfSubsets; -} - -void accessor_bufr_data_element_set_subsetNumber(grib_accessor* a, long subsetNumber) -{ - grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; - self->subsetNumber_ = subsetNumber; -} - -void accessor_bufr_data_element_set_compressedData(grib_accessor* a, int compressedData) -{ - grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; - self->compressedData_ = compressedData; -} - -void accessor_bufr_data_element_set_descriptors(grib_accessor* a, bufr_descriptors_array* descriptors) -{ - grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; - self->descriptors_ = descriptors; -} - -void accessor_bufr_data_element_set_numericValues(grib_accessor* a, grib_vdarray* numericValues) -{ - grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; - self->numericValues_ = numericValues; -} - -void accessor_bufr_data_element_set_stringValues(grib_accessor* a, grib_vsarray* stringValues) -{ - grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; - self->stringValues_ = stringValues; -} - -void accessor_bufr_data_element_set_elementsDescriptorsIndex(grib_accessor* a, grib_viarray* elementsDescriptorsIndex) -{ - grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; - self->elementsDescriptorsIndex_ = elementsDescriptorsIndex; -} - void grib_accessor_bufr_data_element_t::init(const long len, grib_arguments* params) { grib_accessor_gen_t::init(len, params); diff --git a/src/accessor/grib_accessor_class_bufr_data_element.h b/src/accessor/grib_accessor_class_bufr_data_element.h index 6c70ee200..86e69d2b0 100644 --- a/src/accessor/grib_accessor_class_bufr_data_element.h +++ b/src/accessor/grib_accessor_class_bufr_data_element.h @@ -37,7 +37,17 @@ public: int unpack_double_element(size_t i, double* val) override; grib_accessor* make_clone(grib_section*, int*) override; -public: + void index(long index) { index_ = index; } + void type(int type) { type_ = type; } + void numberOfSubsets(long numberOfSubsets) { numberOfSubsets_ = numberOfSubsets; } + void subsetNumber(long subsetNumber) { subsetNumber_ = subsetNumber; } + void compressedData(int compressedData) { compressedData_ = compressedData; } + void descriptors(bufr_descriptors_array* descriptors) { descriptors_ = descriptors; } + void numericValues(grib_vdarray* numericValues) { numericValues_ = numericValues; } + void stringValues(grib_vsarray* stringValues) { stringValues_ = stringValues; } + void elementsDescriptorsIndex(grib_viarray* elementsDescriptorsIndex) { elementsDescriptorsIndex_ = elementsDescriptorsIndex; } + +private: long index_; int type_; long compressedData_; diff --git a/src/accessor/grib_accessor_class_bufr_elements_table.cc b/src/accessor/grib_accessor_class_bufr_elements_table.cc index 244d42f7b..e286ae3d4 100644 --- a/src/accessor/grib_accessor_class_bufr_elements_table.cc +++ b/src/accessor/grib_accessor_class_bufr_elements_table.cc @@ -55,9 +55,8 @@ void grib_accessor_bufr_elements_table_t::init(const long len, grib_arguments* p flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -static grib_trie* load_bufr_elements_table(grib_accessor* a, int* err) +grib_trie* grib_accessor_bufr_elements_table_t::load_bufr_elements_table(int* err) { - grib_accessor_bufr_elements_table_t* self = (grib_accessor_bufr_elements_table_t*)a; char* filename = NULL; char line[1024] = { 0, @@ -83,17 +82,17 @@ static grib_trie* load_bufr_elements_table(grib_accessor* a, int* err) size_t len = 1024; grib_trie* dictionary = NULL; FILE* f = NULL; - grib_handle* h = grib_handle_of_accessor(a); - grib_context* c = a->context_; + grib_handle* h = grib_handle_of_accessor(this); + grib_context* c = context_; *err = GRIB_SUCCESS; len = 1024; - if (self->masterDir_ != NULL) - grib_get_string(h, self->masterDir_, masterDir, &len); + if (masterDir_ != NULL) + grib_get_string(h, masterDir_, masterDir, &len); len = 1024; - if (self->localDir_ != NULL) - grib_get_string(h, self->localDir_, localDir, &len); + if (localDir_ != NULL) + grib_get_string(h, localDir_, localDir, &len); GRIB_MUTEX_INIT_ONCE(&once, &init_mutex); GRIB_MUTEX_LOCK(&mutex1); @@ -102,19 +101,19 @@ static grib_trie* load_bufr_elements_table(grib_accessor* a, int* err) char name[4096] = { 0, }; - snprintf(name, 4096, "%s/%s", masterDir, self->dictionary_); + snprintf(name, 4096, "%s/%s", masterDir, dictionary_); grib_recompose_name(h, NULL, name, masterRecomposed, 0); filename = grib_context_full_defs_path(c, masterRecomposed); } else { - filename = grib_context_full_defs_path(c, self->dictionary_); + filename = grib_context_full_defs_path(c, dictionary_); } if (*localDir != 0) { char localName[2048] = { 0, }; - snprintf(localName, 2048, "%s/%s", localDir, self->dictionary_); + snprintf(localName, 2048, "%s/%s", localDir, dictionary_); grib_recompose_name(h, NULL, localName, localRecomposed, 0); localFilename = grib_context_full_defs_path(c, localRecomposed); snprintf(dictName, 1024, "%s:%s", localFilename, filename); @@ -124,7 +123,7 @@ static grib_trie* load_bufr_elements_table(grib_accessor* a, int* err) } if (!filename) { - grib_context_log(c, GRIB_LOG_ERROR, "Unable to find definition file %s", self->dictionary_); + grib_context_log(c, GRIB_LOG_ERROR, "Unable to find definition file %s", dictionary_); if (strlen(masterRecomposed) > 0) grib_context_log(c, GRIB_LOG_DEBUG, "master path=%s", masterRecomposed); if (strlen(localRecomposed) > 0) grib_context_log(c, GRIB_LOG_DEBUG, "local path=%s", localRecomposed); *err = GRIB_FILE_NOT_FOUND; @@ -138,7 +137,7 @@ static grib_trie* load_bufr_elements_table(grib_accessor* a, int* err) goto the_end; } else { - grib_context_log(c, GRIB_LOG_DEBUG, "using dictionary %s from file %s", self->dictionary_, filename); + grib_context_log(c, GRIB_LOG_DEBUG, "using dictionary %s from file %s", dictionary_, filename); } f = codes_fopen(filename, "r"); @@ -229,14 +228,14 @@ static long atol_fast(const char* input) return atol(input); } -static int bufr_get_from_table(grib_accessor* a, bufr_descriptor* v) +int grib_accessor_bufr_elements_table_t::bufr_get_from_table(bufr_descriptor* v) { int ret = 0; char** list = 0; char code[7] = { 0 }; const size_t codeLen = sizeof(code); - grib_trie* table = load_bufr_elements_table(a, &ret); + grib_trie* table = load_bufr_elements_table(&ret); if (ret) return ret; @@ -288,6 +287,7 @@ int bufr_descriptor_is_marker(bufr_descriptor* d) bufr_descriptor* accessor_bufr_elements_table_get_descriptor(grib_accessor* a, int code, int* err) { + grib_accessor_bufr_elements_table_t* self = (grib_accessor_bufr_elements_table_t*)a; grib_context* c; bufr_descriptor* v = NULL; @@ -310,7 +310,7 @@ bufr_descriptor* accessor_bufr_elements_table_get_descriptor(grib_accessor* a, i switch (v->F) { case 0: - *err = bufr_get_from_table(a, v); + *err = self->bufr_get_from_table(v); break; case 1: v->type = BUFR_DESCRIPTOR_TYPE_REPLICATION; diff --git a/src/accessor/grib_accessor_class_bufr_elements_table.h b/src/accessor/grib_accessor_class_bufr_elements_table.h index 5d3684684..36c566622 100644 --- a/src/accessor/grib_accessor_class_bufr_elements_table.h +++ b/src/accessor/grib_accessor_class_bufr_elements_table.h @@ -25,12 +25,16 @@ public: int unpack_string(char*, size_t* len) override; int value_count(long*) override; void init(const long, grib_arguments*) override; - // TODO(maee): make members private - // private: -public: + +private: const char* dictionary_; const char* masterDir_; const char* localDir_; + + grib_trie* load_bufr_elements_table(int* err); + int bufr_get_from_table(bufr_descriptor* v); + + friend bufr_descriptor* accessor_bufr_elements_table_get_descriptor(grib_accessor* a, int code, int* err); }; int bufr_descriptor_is_marker(bufr_descriptor* d); diff --git a/src/accessor/grib_accessor_class_bufr_extract_area_subsets.cc b/src/accessor/grib_accessor_class_bufr_extract_area_subsets.cc index 3bc01645a..6e747efec 100644 --- a/src/accessor/grib_accessor_class_bufr_extract_area_subsets.cc +++ b/src/accessor/grib_accessor_class_bufr_extract_area_subsets.cc @@ -48,12 +48,11 @@ static void fill_in(double a[], long length) a[i] = a[0]; } -static int select_area(grib_accessor* a) +int grib_accessor_bufr_extract_area_subsets_t::select_area() { - grib_accessor_bufr_extract_area_subsets_t* self = (grib_accessor_bufr_extract_area_subsets_t*)a; int ret = 0; long compressed = 0; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); grib_context* c = h->context; double* lat = NULL; @@ -73,7 +72,7 @@ static int select_area(grib_accessor* a) ret = grib_get_long(h, "compressedData", &compressed); if (ret) return ret; - ret = grib_get_long(h, self->numberOfSubsets_, &numberOfSubsets); + ret = grib_get_long(h, numberOfSubsets_, &numberOfSubsets); if (ret) return ret; subsets = grib_iarray_new(c, numberOfSubsets, 10); @@ -82,10 +81,10 @@ static int select_area(grib_accessor* a) if (ret) return ret; if (compressed) { - ret = grib_get_long(h, self->extractAreaLongitudeRank_, &lonRank); + ret = grib_get_long(h, extractAreaLongitudeRank_, &lonRank); if (ret) return ret; snprintf(lonstr, sizeof(lonstr), "#%ld#longitude", lonRank); - ret = grib_get_long(h, self->extractAreaLatitudeRank_, &latRank); + ret = grib_get_long(h, extractAreaLatitudeRank_, &latRank); if (ret) return ret; snprintf(latstr, sizeof(latstr), "#%ld#latitude", latRank); } @@ -142,13 +141,13 @@ static int select_area(grib_accessor* a) } } - ret = grib_get_double(h, self->extractAreaWestLongitude_, &lonWest); + ret = grib_get_double(h, extractAreaWestLongitude_, &lonWest); if (ret) return ret; - ret = grib_get_double(h, self->extractAreaEastLongitude_, &lonEast); + ret = grib_get_double(h, extractAreaEastLongitude_, &lonEast); if (ret) return ret; - ret = grib_get_double(h, self->extractAreaNorthLatitude_, &latNorth); + ret = grib_get_double(h, extractAreaNorthLatitude_, &latNorth); if (ret) return ret; - ret = grib_get_double(h, self->extractAreaSouthLatitude_, &latSouth); + ret = grib_get_double(h, extractAreaSouthLatitude_, &latSouth); if (ret) return ret; for (i = 0; i < numberOfSubsets; i++) { @@ -160,16 +159,16 @@ static int select_area(grib_accessor* a) } nsubsets = grib_iarray_used_size(subsets); - ret = grib_set_long(h, self->extractedAreaNumberOfSubsets_, nsubsets); + ret = grib_set_long(h, extractedAreaNumberOfSubsets_, nsubsets); if (ret) return ret; if (nsubsets != 0) { long* subsets_ar = grib_iarray_get_array(subsets); - ret = grib_set_long_array(h, self->extractSubsetList_, subsets_ar, nsubsets); + ret = grib_set_long_array(h, extractSubsetList_, subsets_ar, nsubsets); grib_context_free(c, subsets_ar); if (ret) return ret; - ret = grib_set_long(h, self->doExtractSubsets_, 1); + ret = grib_set_long(h, doExtractSubsets_, 1); if (ret) return ret; } @@ -183,9 +182,7 @@ static int select_area(grib_accessor* a) int grib_accessor_bufr_extract_area_subsets_t::pack_long(const long* val, size_t* len) { - /*grib_accessor_bufr_extract_area_subsets_t *self =(grib_accessor_bufr_extract_area_subsets_t*)a;*/ - if (*len == 0) return GRIB_SUCCESS; - return select_area(this); + return select_area(); } diff --git a/src/accessor/grib_accessor_class_bufr_extract_area_subsets.h b/src/accessor/grib_accessor_class_bufr_extract_area_subsets.h index 325c857b3..d3da8f49f 100644 --- a/src/accessor/grib_accessor_class_bufr_extract_area_subsets.h +++ b/src/accessor/grib_accessor_class_bufr_extract_area_subsets.h @@ -23,7 +23,7 @@ public: int pack_long(const long* val, size_t* len) override; void init(const long, grib_arguments*) override; -public: +private: const char* doExtractSubsets_; const char* numberOfSubsets_; const char* extractSubsetList_; @@ -34,4 +34,6 @@ public: const char* extractAreaLongitudeRank_; const char* extractAreaLatitudeRank_; const char* extractedAreaNumberOfSubsets_; + + int select_area(); }; diff --git a/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.cc b/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.cc index 91037c0bb..c319644bd 100644 --- a/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.cc +++ b/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.cc @@ -106,12 +106,11 @@ static int build_long_array(grib_context* c, grib_handle* h, int compressed, return err; } -static int select_datetime(grib_accessor* a) +int grib_accessor_bufr_extract_datetime_subsets_t::select_datetime() { - grib_accessor_bufr_extract_datetime_subsets_t* self = (grib_accessor_bufr_extract_datetime_subsets_t*)a; int ret = 0; long compressed = 0; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); grib_context* c = h->context; size_t n; double julianStart = 0, julianEnd = 0, julianDT = 0; @@ -142,7 +141,7 @@ static int select_datetime(grib_accessor* a) ret = grib_get_long(h, "compressedData", &compressed); if (ret) return ret; - ret = grib_get_long(h, self->numberOfSubsets_, &numberOfSubsets); + ret = grib_get_long(h, numberOfSubsets_, &numberOfSubsets); if (ret) return ret; subsets = grib_iarray_new(c, numberOfSubsets, 10); @@ -322,11 +321,11 @@ static int select_datetime(grib_accessor* a) if (nsubsets != 0) { long* subsets_ar = grib_iarray_get_array(subsets); - ret = grib_set_long_array(h, self->extractSubsetList_, subsets_ar, nsubsets); + ret = grib_set_long_array(h, extractSubsetList_, subsets_ar, nsubsets); grib_context_free(c, subsets_ar); if (ret) return ret; - ret = grib_set_long(h, self->doExtractSubsets_, 1); + ret = grib_set_long(h, doExtractSubsets_, 1); if (ret) return ret; } @@ -349,5 +348,5 @@ int grib_accessor_bufr_extract_datetime_subsets_t::pack_long(const long* val, si if (*len == 0) return GRIB_SUCCESS; - return select_datetime(this); + return select_datetime(); } diff --git a/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.h b/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.h index 553866caf..05a4e83ae 100644 --- a/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.h +++ b/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.h @@ -23,8 +23,10 @@ public: int pack_long(const long* val, size_t* len) override; void init(const long, grib_arguments*) override; -public: +private: const char* doExtractSubsets_; const char* numberOfSubsets_; const char* extractSubsetList_; + + int select_datetime(); }; diff --git a/src/accessor/grib_accessor_class_bufr_extract_subsets.cc b/src/accessor/grib_accessor_class_bufr_extract_subsets.cc index 02ecbb092..738715215 100644 --- a/src/accessor/grib_accessor_class_bufr_extract_subsets.cc +++ b/src/accessor/grib_accessor_class_bufr_extract_subsets.cc @@ -14,15 +14,14 @@ grib_accessor_bufr_extract_subsets_t _grib_accessor_bufr_extract_subsets{}; grib_accessor* grib_accessor_bufr_extract_subsets = &_grib_accessor_bufr_extract_subsets; -void get_accessors(grib_accessor* a) +void grib_accessor_bufr_extract_subsets_t::get_accessors() { - const grib_handle* h = grib_handle_of_accessor(a); - grib_accessor_bufr_extract_subsets_t* self = (grib_accessor_bufr_extract_subsets_t*)a; + const grib_handle* h = grib_handle_of_accessor(this); - if (self->packAccessor_) + if (packAccessor_) return; - self->numericValuesAccessor_ = grib_find_accessor(h, self->numericValues_); - self->packAccessor_ = grib_find_accessor(h, self->pack_); + numericValuesAccessor_ = grib_find_accessor(h, numericValues_); + packAccessor_ = grib_find_accessor(h, pack_); } void grib_accessor_bufr_extract_subsets_t::init(const long len, grib_arguments* arg) @@ -49,7 +48,7 @@ int grib_accessor_bufr_extract_subsets_t::pack_long(const long* val, size_t* len size_t l = 1; long v[1]; - get_accessors(this); + get_accessors(); v[0] = 1; int err = packAccessor_->pack_long(v, &l); diff --git a/src/accessor/grib_accessor_class_bufr_extract_subsets.h b/src/accessor/grib_accessor_class_bufr_extract_subsets.h index 3915195c6..e91f18b87 100644 --- a/src/accessor/grib_accessor_class_bufr_extract_subsets.h +++ b/src/accessor/grib_accessor_class_bufr_extract_subsets.h @@ -23,9 +23,11 @@ public: int pack_long(const long* val, size_t* len) override; void init(const long, grib_arguments*) override; -public: +private: const char* numericValues_; const char* pack_; grib_accessor* numericValuesAccessor_; grib_accessor* packAccessor_; + + void get_accessors(); }; diff --git a/src/accessor/grib_accessor_class_bufr_simple_thinning.cc b/src/accessor/grib_accessor_class_bufr_simple_thinning.cc index 451d3a6c7..543e1d97b 100644 --- a/src/accessor/grib_accessor_class_bufr_simple_thinning.cc +++ b/src/accessor/grib_accessor_class_bufr_simple_thinning.cc @@ -36,12 +36,10 @@ long grib_accessor_bufr_simple_thinning_t::get_native_type() return GRIB_TYPE_LONG; } -static int apply_thinning(grib_accessor* a) +int grib_accessor_bufr_simple_thinning_t::apply_thinning() { - const grib_accessor_bufr_simple_thinning_t* self = (grib_accessor_bufr_simple_thinning_t*)a; - long skip; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); grib_context* c = h->context; long compressed = 0, nsubsets; grib_iarray* subsets; @@ -53,21 +51,21 @@ static int apply_thinning(grib_accessor* a) return ret; if (compressed) { long numberOfSubsets = 0; - ret = grib_get_long(h, self->numberOfSubsets_, &numberOfSubsets); + ret = grib_get_long(h, numberOfSubsets_, &numberOfSubsets); if (ret) return ret; - ret = grib_get_long(h, self->simpleThinningStart_, &start); + ret = grib_get_long(h, simpleThinningStart_, &start); if (ret) return ret; - ret = grib_get_long(h, self->simpleThinningSkip_, &skip); + ret = grib_get_long(h, simpleThinningSkip_, &skip); if (ret) return ret; if (skip <= 0) return GRIB_INVALID_KEY_VALUE; - ret = grib_get_long(h, self->simpleThinningMissingRadius_, &radius); + ret = grib_get_long(h, simpleThinningMissingRadius_, &radius); if (ret) return ret; @@ -80,7 +78,7 @@ static int apply_thinning(grib_accessor* a) if (nsubsets != 0) { subsets_ar = grib_iarray_get_array(subsets); - ret = grib_set_long_array(h, self->extractSubsetList_, subsets_ar, nsubsets); + ret = grib_set_long_array(h, extractSubsetList_, subsets_ar, nsubsets); grib_context_free(c, subsets_ar); if (ret) return ret; @@ -89,7 +87,7 @@ static int apply_thinning(grib_accessor* a) if (ret) return ret; - ret = grib_set_long(h, self->doExtractSubsets_, 1); + ret = grib_set_long(h, doExtractSubsets_, 1); if (ret) return ret; } @@ -106,7 +104,7 @@ int grib_accessor_bufr_simple_thinning_t::pack_long(const long* val, size_t* len { if (*len == 0) return GRIB_SUCCESS; - int err = apply_thinning(this); + int err = apply_thinning(); if (err) return err; diff --git a/src/accessor/grib_accessor_class_bufr_simple_thinning.h b/src/accessor/grib_accessor_class_bufr_simple_thinning.h index f28af36f7..612d41937 100644 --- a/src/accessor/grib_accessor_class_bufr_simple_thinning.h +++ b/src/accessor/grib_accessor_class_bufr_simple_thinning.h @@ -23,11 +23,13 @@ public: int pack_long(const long* val, size_t* len) override; void init(const long, grib_arguments*) override; -public: +private: const char* doExtractSubsets_; const char* numberOfSubsets_; const char* extractSubsetList_; const char* simpleThinningStart_; const char* simpleThinningMissingRadius_; const char* simpleThinningSkip_; + + int apply_thinning(); }; diff --git a/src/accessor/grib_accessor_class_bufr_string_values.cc b/src/accessor/grib_accessor_class_bufr_string_values.cc index 4f3cebeea..0530cec87 100644 --- a/src/accessor/grib_accessor_class_bufr_string_values.cc +++ b/src/accessor/grib_accessor_class_bufr_string_values.cc @@ -30,29 +30,28 @@ void grib_accessor_bufr_string_values_t::dump(grib_dumper* dumper) grib_dump_string_array(dumper, this, NULL); } -static grib_accessor* get_accessor(grib_accessor* a) +grib_accessor* grib_accessor_bufr_string_values_t::get_accessor() { - grib_accessor_bufr_string_values_t* self = (grib_accessor_bufr_string_values_t*)a; - if (!self->dataAccessor_) { - self->dataAccessor_ = grib_find_accessor(grib_handle_of_accessor(a), self->dataAccessorName_); + if (!dataAccessor_) { + dataAccessor_ = grib_find_accessor(grib_handle_of_accessor(this), dataAccessorName_); } - return self->dataAccessor_; + return dataAccessor_; } int grib_accessor_bufr_string_values_t::unpack_string_array(char** buffer, size_t* len) { - grib_accessor* data = 0; - grib_context* c = context_; - grib_vsarray* stringValues = NULL; - size_t l = 0, tl; + grib_accessor_bufr_data_array_t* data = 0; + grib_context* c = context_; + grib_vsarray* stringValues = NULL; + size_t l = 0, tl; size_t i, j, n = 0; char** b = buffer; - data = get_accessor(this); + data = dynamic_cast(get_accessor()); if (!data) return GRIB_NOT_FOUND; - stringValues = accessor_bufr_data_array_get_stringValues(data); + stringValues = data->accessor_bufr_data_array_get_stringValues(); n = grib_vsarray_used_size(stringValues); @@ -80,7 +79,7 @@ int grib_accessor_bufr_string_values_t::unpack_string(char* val, size_t* len) int grib_accessor_bufr_string_values_t::value_count(long* rlen) { - grib_accessor* descriptors = get_accessor(this); + grib_accessor* descriptors = get_accessor(); return descriptors->value_count(rlen); } diff --git a/src/accessor/grib_accessor_class_bufr_string_values.h b/src/accessor/grib_accessor_class_bufr_string_values.h index a3c4d50e0..e794213a4 100644 --- a/src/accessor/grib_accessor_class_bufr_string_values.h +++ b/src/accessor/grib_accessor_class_bufr_string_values.h @@ -26,7 +26,9 @@ public: void dump(grib_dumper*) override; void init(const long, grib_arguments*) override; -public: +private: const char* dataAccessorName_; grib_accessor* dataAccessor_; + + grib_accessor* get_accessor(); }; diff --git a/src/accessor/grib_accessor_class_bufrdc_expanded_descriptors.cc b/src/accessor/grib_accessor_class_bufrdc_expanded_descriptors.cc index 4234f0378..0d36208d1 100644 --- a/src/accessor/grib_accessor_class_bufrdc_expanded_descriptors.cc +++ b/src/accessor/grib_accessor_class_bufrdc_expanded_descriptors.cc @@ -24,13 +24,12 @@ void grib_accessor_bufrdc_expanded_descriptors_t::init(const long len, grib_argu flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -static grib_accessor* get_accessor(grib_accessor* a) +grib_accessor* grib_accessor_bufrdc_expanded_descriptors_t::get_accessor() { - grib_accessor_bufrdc_expanded_descriptors_t* self = (grib_accessor_bufrdc_expanded_descriptors_t*)a; - if (!self->expandedDescriptorsAccessor_) { - self->expandedDescriptorsAccessor_ = grib_find_accessor(grib_handle_of_accessor(a), self->expandedDescriptors_); + if (!expandedDescriptorsAccessor_) { + expandedDescriptorsAccessor_ = grib_find_accessor(grib_handle_of_accessor(this), expandedDescriptors_); } - return self->expandedDescriptorsAccessor_; + return expandedDescriptorsAccessor_; } int grib_accessor_bufrdc_expanded_descriptors_t::unpack_long(long* val, size_t* len) @@ -42,7 +41,7 @@ int grib_accessor_bufrdc_expanded_descriptors_t::unpack_long(long* val, size_t* long* v = 0; grib_context* c = context_; - descriptors = get_accessor(this); + descriptors = get_accessor(); if (!descriptors) return GRIB_NOT_FOUND; value_count(&lenall); @@ -73,7 +72,7 @@ int grib_accessor_bufrdc_expanded_descriptors_t::unpack_string_array(char** buff }; grib_context* c = context_; - descriptors = get_accessor(this); + descriptors = get_accessor(); if (!descriptors) return GRIB_NOT_FOUND; err = value_count(&lenall); @@ -97,7 +96,7 @@ int grib_accessor_bufrdc_expanded_descriptors_t::unpack_string_array(char** buff int grib_accessor_bufrdc_expanded_descriptors_t::value_count(long* rlen) { - grib_accessor* descriptors = get_accessor(this); + grib_accessor* descriptors = get_accessor(); return descriptors->value_count(rlen); } diff --git a/src/accessor/grib_accessor_class_bufrdc_expanded_descriptors.h b/src/accessor/grib_accessor_class_bufrdc_expanded_descriptors.h index c20cd2f74..f8170e774 100644 --- a/src/accessor/grib_accessor_class_bufrdc_expanded_descriptors.h +++ b/src/accessor/grib_accessor_class_bufrdc_expanded_descriptors.h @@ -25,7 +25,9 @@ public: void destroy(grib_context*) override; void init(const long, grib_arguments*) override; -public: +private: const char* expandedDescriptors_; grib_accessor* expandedDescriptorsAccessor_; + + grib_accessor* get_accessor(); }; diff --git a/src/accessor/grib_accessor_class_cf_var_name.h b/src/accessor/grib_accessor_class_cf_var_name.h index f536bfec9..8073d91d1 100644 --- a/src/accessor/grib_accessor_class_cf_var_name.h +++ b/src/accessor/grib_accessor_class_cf_var_name.h @@ -22,7 +22,7 @@ public: size_t string_length() override; void init(const long, grib_arguments*) override; -public: +private: /* Members defined in cf_var_name */ const char* defaultKey_; }; diff --git a/src/accessor/grib_accessor_class_codeflag.cc b/src/accessor/grib_accessor_class_codeflag.cc index 95ca77364..6921c5b17 100644 --- a/src/accessor/grib_accessor_class_codeflag.cc +++ b/src/accessor/grib_accessor_class_codeflag.cc @@ -28,9 +28,8 @@ static int test_bit(long a, long b) return a & (1 << b); } -static int grib_get_codeflag(grib_accessor* a, long code, char* codename) +int grib_accessor_codeflag_t::grib_get_codeflag(long code, char* codename) { - const grib_accessor_codeflag_t* self = (grib_accessor_codeflag_t*)a; FILE* f = NULL; char fname[1024]; char bval[50]; @@ -41,21 +40,21 @@ static int grib_get_codeflag(grib_accessor* a, long code, char* codename) int j = 0; int err = 0; - err = grib_recompose_name(grib_handle_of_accessor(a), NULL, self->tablename_, fname, 1); + err = grib_recompose_name(grib_handle_of_accessor(this), NULL, tablename_, fname, 1); if (err) { - strncpy(fname, self->tablename_, sizeof(fname) - 1); + strncpy(fname, tablename_, sizeof(fname) - 1); fname[sizeof(fname) - 1] = '\0'; } - if ((filename = grib_context_full_defs_path(a->context_, fname)) == NULL) { - grib_context_log(a->context_, GRIB_LOG_WARNING, "Cannot open flag table %s", filename); + if ((filename = grib_context_full_defs_path(context_, fname)) == NULL) { + grib_context_log(context_, GRIB_LOG_WARNING, "Cannot open flag table %s", filename); strcpy(codename, "Cannot open flag table"); return GRIB_FILE_NOT_FOUND; } f = codes_fopen(filename, "r"); if (!f) { - grib_context_log(a->context_, (GRIB_LOG_WARNING) | (GRIB_LOG_PERROR), "Cannot open flag table %s", filename); + grib_context_log(context_, (GRIB_LOG_WARNING) | (GRIB_LOG_PERROR), "Cannot open flag table %s", filename); strcpy(codename, "Cannot open flag table"); return GRIB_FILE_NOT_FOUND; } @@ -68,7 +67,7 @@ static int grib_get_codeflag(grib_accessor* a, long code, char* codename) sscanf(line, "%49s %49s", num, bval); if (num[0] != '#') { - if ((test_bit(code, self->length_ * 8 - atol(num)) > 0) == atol(bval)) { + if ((test_bit(code, length_ * 8 - atol(num)) > 0) == atol(bval)) { size_t linelen = strlen(line); codename[j++] = '('; codename[j++] = num[0]; @@ -117,7 +116,7 @@ void grib_accessor_codeflag_t::dump(grib_dumper* dumper) grib_recompose_name(grib_handle_of_accessor(this), NULL, tablename_, fname, 1); unpack_long(&v, &llen); - grib_get_codeflag(this, v, flagname); + grib_get_codeflag(v, flagname); grib_dump_bits(dumper, this, flagname); } diff --git a/src/accessor/grib_accessor_class_codeflag.h b/src/accessor/grib_accessor_class_codeflag.h index fa394a650..af055fd2f 100644 --- a/src/accessor/grib_accessor_class_codeflag.h +++ b/src/accessor/grib_accessor_class_codeflag.h @@ -23,6 +23,8 @@ public: void dump(grib_dumper*) override; void init(const long, grib_arguments*) override; -public: +private: const char* tablename_; + + int grib_get_codeflag(long code, char* codename); }; diff --git a/src/accessor/grib_accessor_class_codetable.cc b/src/accessor/grib_accessor_class_codetable.cc index 884bbfe3b..b0ac62a08 100644 --- a/src/accessor/grib_accessor_class_codetable.cc +++ b/src/accessor/grib_accessor_class_codetable.cc @@ -163,11 +163,11 @@ static void dump_codetable(grib_codetable* atable) } } #endif -static grib_codetable* load_table(grib_accessor* a) + +grib_codetable* grib_accessor_codetable_t::load_table() { - grib_accessor_codetable_t* self = (grib_accessor_codetable_t*)a; size_t size = 0; - grib_handle* h = ((grib_accessor*)self)->parent_->h; + grib_handle* h = parent_->h; grib_context* c = h->context; grib_codetable* t = NULL; grib_codetable* next = NULL; @@ -187,23 +187,23 @@ static grib_codetable* load_table(grib_accessor* a) }; size_t len = 1024; - if (self->masterDir_ != NULL) - grib_get_string(h, self->masterDir_, masterDir, &len); + if (masterDir_ != NULL) + grib_get_string(h, masterDir_, masterDir, &len); len = 1024; - if (self->localDir_ != NULL) - grib_get_string(h, self->localDir_, localDir, &len); + if (localDir_ != NULL) + grib_get_string(h, localDir_, localDir, &len); if (*masterDir != 0) { char name[2048] = { 0, }; - snprintf(name, sizeof(name), "%s/%s", masterDir, self->tablename_); + snprintf(name, sizeof(name), "%s/%s", masterDir, tablename_); grib_recompose_name(h, NULL, name, recomposed, 0); filename = grib_context_full_defs_path(c, recomposed); } else { - grib_recompose_name(h, NULL, self->tablename_, recomposed, 0); + grib_recompose_name(h, NULL, tablename_, recomposed, 0); filename = grib_context_full_defs_path(c, recomposed); } @@ -211,7 +211,7 @@ static grib_codetable* load_table(grib_accessor* a) char localName[2048] = { 0, }; - snprintf(localName, sizeof(localName), "%s/%s", localDir, self->tablename_); + snprintf(localName, sizeof(localName), "%s/%s", localDir, tablename_); grib_recompose_name(h, NULL, localName, localRecomposed, 0); localFilename = grib_context_full_defs_path(c, localRecomposed); } @@ -243,12 +243,12 @@ static grib_codetable* load_table(grib_accessor* a) next = next->next; } - if (self->flags_ & GRIB_ACCESSOR_FLAG_TRANSIENT) { - Assert(self->vvalue_ != NULL); - size = self->vvalue_->length * 8; + if (flags_ & GRIB_ACCESSOR_FLAG_TRANSIENT) { + Assert(vvalue_ != NULL); + size = vvalue_->length * 8; } else { - size = ((grib_accessor*)self)->byte_count() * 8; + size = byte_count() * 8; } size = (1ULL << size); /* 2^size - 64bits */ @@ -455,7 +455,7 @@ int codes_codetable_get_contents_malloc(const grib_handle* h, const char* key, c return err; } - const grib_codetable* table = ca->table_; + const grib_codetable* table = ca->table(); if (!table) return GRIB_INTERNAL_ERROR; grib_codetable* cached_table = c->codetable; // Access the codetable cache @@ -531,7 +531,7 @@ void grib_accessor_codetable_t::dump(grib_dumper* dumper) long value; if (!table_loaded_) { - table_ = load_table(this); /* may return NULL */ + table_ = load_table(); /* may return NULL */ table_loaded_ = 1; } table = table_; @@ -593,7 +593,7 @@ int grib_accessor_codetable_t::unpack_string(char* buffer, size_t* len) return err; if (!table_loaded_) { - table_ = load_table(this); /* may return NULL */ + table_ = load_table(); /* may return NULL */ table_loaded_ = 1; } table = table_; @@ -664,7 +664,7 @@ int grib_accessor_codetable_t::pack_string(const char* buffer, size_t* len) size_t size = 1; if (!table_loaded_) { - table_ = load_table(this); /* may return NULL */ + table_ = load_table(); /* may return NULL */ table_loaded_ = 1; } table = table_; @@ -812,7 +812,7 @@ int grib_accessor_codetable_t::unpack_long(long* val, size_t* len) rlen = 1; /* ECC-480 Performance: avoid func call overhead of grib_value_count */ if (!table_loaded_) { - table_ = load_table(this); /* may return NULL */ + table_ = load_table(); /* may return NULL */ table_loaded_ = 1; } diff --git a/src/accessor/grib_accessor_class_codetable.h b/src/accessor/grib_accessor_class_codetable.h index 644e0c2c7..425fd9769 100644 --- a/src/accessor/grib_accessor_class_codetable.h +++ b/src/accessor/grib_accessor_class_codetable.h @@ -30,10 +30,14 @@ public: void dump(grib_dumper*) override; void init(const long, grib_arguments*) override; -public: + grib_codetable* table() const { return table_; } + +private: grib_codetable* table_; const char* tablename_; const char* masterDir_; const char* localDir_; int table_loaded_; + + grib_codetable* load_table(); }; diff --git a/src/accessor/grib_accessor_class_codetable_title.cc b/src/accessor/grib_accessor_class_codetable_title.cc index 9894a2d7b..7617a4e90 100644 --- a/src/accessor/grib_accessor_class_codetable_title.cc +++ b/src/accessor/grib_accessor_class_codetable_title.cc @@ -43,7 +43,7 @@ int grib_accessor_codetable_title_t::unpack_string(char* buffer, size_t* len) if ((err = ((grib_accessor*)ca)->unpack_long(&value, &size)) != GRIB_SUCCESS) return err; - table = ca->table_; + table = ca->table(); if (table && (value >= 0) && (value < table->size) && table->entries[value].title) { strcpy(tmp, table->entries[value].title); diff --git a/src/accessor/grib_accessor_class_codetable_units.cc b/src/accessor/grib_accessor_class_codetable_units.cc index 004510ee3..949459917 100644 --- a/src/accessor/grib_accessor_class_codetable_units.cc +++ b/src/accessor/grib_accessor_class_codetable_units.cc @@ -44,7 +44,7 @@ int grib_accessor_codetable_units_t::unpack_string(char* buffer, size_t* len) if ((err = ((grib_accessor*)ca)->unpack_long(&value, &size)) != GRIB_SUCCESS) return err; - table = ca->table_; + table = ca->table(); if (table && (value >= 0) && (value < table->size) && table->entries[value].units) { strcpy(tmp, table->entries[value].units); diff --git a/src/accessor/grib_accessor_class_constant.h b/src/accessor/grib_accessor_class_constant.h index b0e6bda1b..ea4a88c6a 100644 --- a/src/accessor/grib_accessor_class_constant.h +++ b/src/accessor/grib_accessor_class_constant.h @@ -17,4 +17,5 @@ public: grib_accessor_variable_t() { class_name_ = "constant"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_constant_t{}; } void init(const long, grib_arguments*) override; + }; diff --git a/src/accessor/grib_accessor_class_data_apply_bitmap.cc b/src/accessor/grib_accessor_class_data_apply_bitmap.cc index 4913ec146..ec43d810f 100644 --- a/src/accessor/grib_accessor_class_data_apply_bitmap.cc +++ b/src/accessor/grib_accessor_class_data_apply_bitmap.cc @@ -232,10 +232,9 @@ int grib_accessor_data_apply_bitmap_t::pack_double(const double* val, size_t* le return err; } -template -static int unpack(grib_accessor* a, T* val, size_t* len) +template +int grib_accessor_data_apply_bitmap_t::unpack(T* val, size_t* len) { - grib_accessor_data_apply_bitmap_t* self = (grib_accessor_data_apply_bitmap_t*)a; static_assert(std::is_floating_point::value, "Requires floating point numbers"); size_t i = 0; @@ -246,18 +245,18 @@ static int unpack(grib_accessor* a, T* val, size_t* len) T* coded_vals = NULL; double missing_value = 0; - int err = a->value_count(&nn); + int err = value_count(&nn); n_vals = nn; if (err) return err; - if (!grib_find_accessor(grib_handle_of_accessor(a), self->bitmap_)) - return grib_get_array(grib_handle_of_accessor(a), self->coded_values_, val, len); + if (!grib_find_accessor(grib_handle_of_accessor(this), bitmap_)) + return grib_get_array(grib_handle_of_accessor(this), coded_values_, val, len); - if ((err = grib_get_size(grib_handle_of_accessor(a), self->coded_values_, &coded_n_vals)) != GRIB_SUCCESS) + if ((err = grib_get_size(grib_handle_of_accessor(this), coded_values_, &coded_n_vals)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->missing_value_, &missing_value)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(grib_handle_of_accessor(this), missing_value_, &missing_value)) != GRIB_SUCCESS) return err; if (*len < n_vals) { @@ -273,21 +272,21 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return GRIB_SUCCESS; } - if ((err = grib_get_array_internal(grib_handle_of_accessor(a), self->bitmap_, val, &n_vals)) != GRIB_SUCCESS) + if ((err = grib_get_array_internal(grib_handle_of_accessor(this), bitmap_, val, &n_vals)) != GRIB_SUCCESS) return err; - coded_vals = (T*)grib_context_malloc(a->context_, coded_n_vals * sizeof(T)); + coded_vals = (T*)grib_context_malloc(context_, coded_n_vals * sizeof(T)); if (coded_vals == NULL) return GRIB_OUT_OF_MEMORY; - if ((err = grib_get_array(grib_handle_of_accessor(a), self->coded_values_, coded_vals, &coded_n_vals)) != GRIB_SUCCESS) { - grib_context_free(a->context_, coded_vals); + if ((err = grib_get_array(grib_handle_of_accessor(this), coded_values_, coded_vals, &coded_n_vals)) != GRIB_SUCCESS) { + grib_context_free(context_, coded_vals); return err; } - grib_context_log(a->context_, GRIB_LOG_DEBUG, + grib_context_log(context_, GRIB_LOG_DEBUG, "grib_accessor_data_apply_bitmap: %s : creating %s, %d values", - __func__, a->name_, n_vals); + __func__, name_, n_vals); for (i = 0; i < n_vals; i++) { if (val[i] == 0) { @@ -296,11 +295,11 @@ static int unpack(grib_accessor* a, T* val, size_t* len) else { val[i] = coded_vals[j++]; if (j > coded_n_vals) { - grib_context_free(a->context_, coded_vals); - grib_context_log(a->context_, GRIB_LOG_ERROR, + grib_context_free(context_, coded_vals); + grib_context_log(context_, GRIB_LOG_ERROR, "grib_accessor_data_apply_bitmap [%s]:" " %s : number of coded values does not match bitmap %ld %ld", - a->name_, __func__, coded_n_vals, n_vals); + name_, __func__, coded_n_vals, n_vals); return GRIB_ARRAY_TOO_SMALL; } @@ -309,18 +308,18 @@ static int unpack(grib_accessor* a, T* val, size_t* len) *len = n_vals; - grib_context_free(a->context_, coded_vals); + grib_context_free(context_, coded_vals); return err; } int grib_accessor_data_apply_bitmap_t::unpack_double(double* val, size_t* len) { - return unpack(this, val, len); + return unpack(val, len); } int grib_accessor_data_apply_bitmap_t::unpack_float(float* val, size_t* len) { - return unpack(this, val, len); + return unpack(val, len); } long grib_accessor_data_apply_bitmap_t::get_native_type() diff --git a/src/accessor/grib_accessor_class_data_apply_bitmap.h b/src/accessor/grib_accessor_class_data_apply_bitmap.h index f91b24750..bfcc41e47 100644 --- a/src/accessor/grib_accessor_class_data_apply_bitmap.h +++ b/src/accessor/grib_accessor_class_data_apply_bitmap.h @@ -29,11 +29,13 @@ public: int unpack_double_element(size_t i, double* val) override; int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) override; -public: +private: const char* coded_values_; const char* bitmap_; const char* missing_value_; const char* number_of_data_points_; const char* number_of_values_; const char* binary_scale_factor_; + + template int unpack(T* val, size_t* len); }; diff --git a/src/accessor/grib_accessor_class_data_apply_boustrophedonic.cc b/src/accessor/grib_accessor_class_data_apply_boustrophedonic.cc index 5f82ffeb2..b453bc7c9 100644 --- a/src/accessor/grib_accessor_class_data_apply_boustrophedonic.cc +++ b/src/accessor/grib_accessor_class_data_apply_boustrophedonic.cc @@ -39,9 +39,8 @@ int grib_accessor_data_apply_boustrophedonic_t::value_count(long* numberOfPoints } template -static int unpack(grib_accessor* a, T* val, size_t* len) +int grib_accessor_data_apply_boustrophedonic_t::unpack(T* val, size_t* len) { - grib_accessor_data_apply_boustrophedonic_t* self = (grib_accessor_data_apply_boustrophedonic_t*)a; size_t plSize = 0; long* pl = 0; double* values = 0; @@ -52,7 +51,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) int ret; long numberOfPoints, numberOfRows, numberOfColumns; - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfPoints_, &numberOfPoints); + ret = grib_get_long_internal(grib_handle_of_accessor(this), numberOfPoints_, &numberOfPoints); if (ret) return ret; @@ -61,7 +60,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return GRIB_ARRAY_TOO_SMALL; } - ret = grib_get_size(grib_handle_of_accessor(a), self->values_, &valuesSize); + ret = grib_get_size(grib_handle_of_accessor(this), values_, &valuesSize); if (ret) return ret; @@ -70,31 +69,31 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return 0; if (valuesSize != numberOfPoints) { - grib_context_log(a->context_, GRIB_LOG_ERROR, "boustrophedonic ordering error: ( %s=%ld ) != (sizeOf(%s)=%ld)", - numberOfPoints, numberOfPoints, self->values_, (long)valuesSize); + grib_context_log(context_, GRIB_LOG_ERROR, "boustrophedonic ordering error: ( %s=%ld ) != (sizeOf(%s)=%ld)", + numberOfPoints, numberOfPoints, values_, (long)valuesSize); return GRIB_DECODING_ERROR; } - values = (double*)grib_context_malloc_clear(a->context_, sizeof(double) * numberOfPoints); - ret = grib_get_double_array_internal(grib_handle_of_accessor(a), self->values_, values, &valuesSize); + values = (double*)grib_context_malloc_clear(context_, sizeof(double) * numberOfPoints); + ret = grib_get_double_array_internal(grib_handle_of_accessor(this), values_, values, &valuesSize); if (ret) return ret; pvalues = values; pval = val; - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfRows_, &numberOfRows); + ret = grib_get_long_internal(grib_handle_of_accessor(this), numberOfRows_, &numberOfRows); if (ret) return ret; - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfColumns_, &numberOfColumns); + ret = grib_get_long_internal(grib_handle_of_accessor(this), numberOfColumns_, &numberOfColumns); if (ret) return ret; - if (grib_get_size(grib_handle_of_accessor(a), self->pl_, &plSize) == GRIB_SUCCESS) { + if (grib_get_size(grib_handle_of_accessor(this), pl_, &plSize) == GRIB_SUCCESS) { Assert(plSize == numberOfRows); - pl = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * plSize); - ret = grib_get_long_array_internal(grib_handle_of_accessor(a), self->pl_, pl, &plSize); + pl = (long*)grib_context_malloc_clear(context_, sizeof(long) * plSize); + ret = grib_get_long_array_internal(grib_handle_of_accessor(this), pl_, pl, &plSize); if (ret) return ret; @@ -111,7 +110,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) } } - grib_context_free(a->context_, pl); + grib_context_free(context_, pl); } else { for (j = 0; j < numberOfRows; j++) { @@ -128,19 +127,19 @@ static int unpack(grib_accessor* a, T* val, size_t* len) } } - grib_context_free(a->context_, values); + grib_context_free(context_, values); return GRIB_SUCCESS; } int grib_accessor_data_apply_boustrophedonic_t::unpack_double(double* val, size_t* len) { - return unpack(this, val, len); + return unpack(val, len); } int grib_accessor_data_apply_boustrophedonic_t::unpack_float(float* val, size_t* len) { - return unpack(this, val, len); + return unpack(val, len); } int grib_accessor_data_apply_boustrophedonic_t::unpack_double_element(size_t idx, double* val) diff --git a/src/accessor/grib_accessor_class_data_apply_boustrophedonic.h b/src/accessor/grib_accessor_class_data_apply_boustrophedonic.h index da7898ddf..76aae84c6 100644 --- a/src/accessor/grib_accessor_class_data_apply_boustrophedonic.h +++ b/src/accessor/grib_accessor_class_data_apply_boustrophedonic.h @@ -28,10 +28,12 @@ public: int unpack_double_element(size_t i, double* val) override; int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) override; -public: +private: const char* values_; const char* numberOfRows_; const char* numberOfColumns_; const char* numberOfPoints_; const char* pl_; + + template int unpack(T* val, size_t* len); }; diff --git a/src/accessor/grib_accessor_class_data_ccsds_packing.cc b/src/accessor/grib_accessor_class_data_ccsds_packing.cc index 47e16481c..0db790cce 100644 --- a/src/accessor/grib_accessor_class_data_ccsds_packing.cc +++ b/src/accessor/grib_accessor_class_data_ccsds_packing.cc @@ -379,12 +379,11 @@ cleanup: } template -static int unpack(grib_accessor* a, T* val, size_t* len) +int grib_accessor_data_ccsds_packing_t::unpack(T* val, size_t* len) { - grib_accessor_data_ccsds_packing_t* self = (grib_accessor_data_ccsds_packing_t*)a; static_assert(std::is_floating_point::value, "Requires floating point numbers"); - grib_handle* hand = grib_handle_of_accessor(a); - const char* cclass_name = a->class_name_; + grib_handle* hand = grib_handle_of_accessor(this); + const char* cclass_name = class_name_; int err = GRIB_SUCCESS, i = 0; size_t buflen = 0; @@ -408,28 +407,28 @@ static int unpack(grib_accessor* a, T* val, size_t* len) long ccsds_rsi; size_t nbytes; - a->dirty_ = 0; + dirty_ = 0; - if ((err = a->value_count(&nn)) != GRIB_SUCCESS) + if ((err = value_count(&nn)) != GRIB_SUCCESS) return err; n_vals = nn; - if ((err = grib_get_long_internal(hand, self->bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(hand, self->reference_value_, &reference_value)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(hand, reference_value_, &reference_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(hand, self->binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(hand, self->decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return err; // ECC-477: Don't call grib_get_long_internal to suppress error message being output - if ((err = grib_get_long(hand, self->ccsds_flags_, &ccsds_flags)) != GRIB_SUCCESS) + if ((err = grib_get_long(hand, ccsds_flags_, &ccsds_flags)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(hand, self->ccsds_block_size_, &ccsds_block_size)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, ccsds_block_size_, &ccsds_block_size)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(hand, self->ccsds_rsi_, &ccsds_rsi)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, ccsds_rsi_, &ccsds_rsi)) != GRIB_SUCCESS) return err; modify_aec_flags(&ccsds_flags); @@ -449,9 +448,9 @@ static int unpack(grib_accessor* a, T* val, size_t* len) bscale = codes_power(binary_scale_factor, 2); dscale = codes_power(-decimal_scale_factor, 10); - buflen = self->byte_count(); + buflen = byte_count(); buf = (unsigned char*)hand->buffer->data; - buf += a->byte_offset(); + buf += byte_offset(); strm.flags = ccsds_flags; strm.bits_per_sample = bits_per_value; strm.block_size = ccsds_block_size; @@ -465,7 +464,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) nbytes = 4; size = n_vals * nbytes; - decoded = (unsigned char*)grib_context_buffer_malloc_clear(a->context_, size); + decoded = (unsigned char*)grib_context_buffer_malloc_clear(context_, size); if (!decoded) { err = GRIB_OUT_OF_MEMORY; goto cleanup; @@ -476,7 +475,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) if (hand->context->debug) print_aec_stream_info(&strm, "unpack_*"); if ((err = aec_buffer_decode(&strm)) != AEC_OK) { - grib_context_log(a->context_, GRIB_LOG_ERROR, "%s %s: aec_buffer_decode error %d (%s)", + grib_context_log(context_, GRIB_LOG_ERROR, "%s %s: aec_buffer_decode error %d (%s)", cclass_name, __func__, err, aec_get_error_message(err)); err = GRIB_DECODING_ERROR; goto cleanup; @@ -503,8 +502,8 @@ static int unpack(grib_accessor* a, T* val, size_t* len) } break; default: - grib_context_log(a->context_, GRIB_LOG_ERROR, "%s %s: unpacking %s, bitsPerValue=%ld (max %ld)", - cclass_name, __func__, a->name_, bits_per_value, MAX_BITS_PER_VALUE); + grib_context_log(context_, GRIB_LOG_ERROR, "%s %s: unpacking %s, bitsPerValue=%ld (max %ld)", + cclass_name, __func__, name_, bits_per_value, MAX_BITS_PER_VALUE); err = GRIB_INVALID_BPV; goto cleanup; } @@ -512,18 +511,18 @@ static int unpack(grib_accessor* a, T* val, size_t* len) *len = n_vals; cleanup: - grib_context_buffer_free(a->context_, decoded); + grib_context_buffer_free(context_, decoded); return err; } int grib_accessor_data_ccsds_packing_t::unpack_double(double* val, size_t* len) { - return unpack(this, val, len); + return unpack(val, len); } int grib_accessor_data_ccsds_packing_t::unpack_float(float* val, size_t* len) { - return unpack(this, val, len); + return unpack(val, len); } int grib_accessor_data_ccsds_packing_t::unpack_double_element(size_t idx, double* val) diff --git a/src/accessor/grib_accessor_class_data_ccsds_packing.h b/src/accessor/grib_accessor_class_data_ccsds_packing.h index 43ae75b6b..7ae72d514 100644 --- a/src/accessor/grib_accessor_class_data_ccsds_packing.h +++ b/src/accessor/grib_accessor_class_data_ccsds_packing.h @@ -27,7 +27,7 @@ public: int unpack_double_element(size_t i, double* val) override; int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) override; -public: +private: const char* number_of_values_; const char* reference_value_; const char* binary_scale_factor_; @@ -38,4 +38,6 @@ public: const char* ccsds_flags_; const char* ccsds_block_size_; const char* ccsds_rsi_; + + template int unpack(T* val, size_t* len); }; diff --git a/src/accessor/grib_accessor_class_data_complex_packing.cc b/src/accessor/grib_accessor_class_data_complex_packing.cc index a1cd7e81a..fd4c42930 100644 --- a/src/accessor/grib_accessor_class_data_complex_packing.cc +++ b/src/accessor/grib_accessor_class_data_complex_packing.cc @@ -534,12 +534,11 @@ int grib_accessor_data_complex_packing_t::pack_double(const double* val, size_t* } template -static int unpack_real(grib_accessor* a, T* val, size_t* len) +int grib_accessor_data_complex_packing_t::unpack_real(T* val, size_t* len) { - grib_accessor_data_complex_packing_t* self = (grib_accessor_data_complex_packing_t*)a; static_assert(std::is_floating_point::value, "Requires floating point numbers"); - grib_handle* gh = grib_handle_of_accessor(a); - const char* cclass_name = a->class_name_; + grib_handle* gh = grib_handle_of_accessor(this); + const char* cclass_name = class_name_; size_t i = 0; int ret = GRIB_SUCCESS; @@ -585,7 +584,7 @@ static int unpack_real(grib_accessor* a, T* val, size_t* len) decode_float_proc decode_float = NULL; - err = a->value_count(&n_vals); + err = value_count(&n_vals); if (err) return err; @@ -594,44 +593,44 @@ static int unpack_real(grib_accessor* a, T* val, size_t* len) return GRIB_ARRAY_TOO_SMALL; } - if ((ret = grib_get_long_internal(gh, self->offsetdata_, &offsetdata)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, offsetdata_, &offsetdata)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_double_internal(gh, self->reference_value_, &tmp)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(gh, reference_value_, &tmp)) != GRIB_SUCCESS) return ret; reference_value = tmp; - if ((ret = grib_get_long_internal(gh, self->binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->GRIBEX_sh_bug_present_, &GRIBEX_sh_bug_present)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, GRIBEX_sh_bug_present_, &GRIBEX_sh_bug_present)) != GRIB_SUCCESS) return ret; /* ECC-774: don't use grib_get_long_internal */ - if ((ret = grib_get_long(gh, self->ieee_floats_, &ieee_floats)) != GRIB_SUCCESS) + if ((ret = grib_get_long(gh, ieee_floats_, &ieee_floats)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_double_internal(gh, self->laplacianOperator_, &tmp)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(gh, laplacianOperator_, &tmp)) != GRIB_SUCCESS) return ret; laplacianOperator = tmp; - if ((ret = grib_get_long_internal(gh, self->sub_j_, &sub_j)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, sub_j_, &sub_j)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->sub_k_, &sub_k)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, sub_k_, &sub_k)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->sub_m_, &sub_m)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, sub_m_, &sub_m)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->pen_j_, &pen_j)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, pen_j_, &pen_j)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->pen_k_, &pen_k)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, pen_k_, &pen_k)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->pen_m_, &pen_m)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, pen_m_, &pen_m)) != GRIB_SUCCESS) return ret; - a->dirty_ = 0; + dirty_ = 0; switch (ieee_floats) { case 0: @@ -651,7 +650,7 @@ static int unpack_real(grib_accessor* a, T* val, size_t* len) } if (sub_j != sub_k || sub_j != sub_m || pen_j != pen_k || pen_j != pen_m) { - grib_context_log(a->context_, GRIB_LOG_ERROR, "%s: Invalid pentagonal resolution parameters", cclass_name); + grib_context_log(context_, GRIB_LOG_ERROR, "%s: Invalid pentagonal resolution parameters", cclass_name); return GRIB_DECODING_ERROR; } @@ -659,7 +658,7 @@ static int unpack_real(grib_accessor* a, T* val, size_t* len) maxv = pen_j + 1; - buf += a->byte_offset(); + buf += byte_offset(); hres = buf; lres = buf; @@ -667,7 +666,7 @@ static int unpack_real(grib_accessor* a, T* val, size_t* len) n_vals = (pen_j + 1) * (pen_j + 2); d = codes_power(-decimal_scale_factor, 10); - grib_ieee_decode_array(a->context_, buf, n_vals, bytes, val); + grib_ieee_decode_array(context_, buf, n_vals, bytes, val); if (d) { for (i = 0; i < n_vals; i++) val[i] *= d; @@ -675,13 +674,13 @@ static int unpack_real(grib_accessor* a, T* val, size_t* len) return 0; } - packed_offset = a->byte_offset() + bytes * (sub_k + 1) * (sub_k + 2); + packed_offset = byte_offset() + bytes * (sub_k + 1) * (sub_k + 2); lpos = 8 * (packed_offset - offsetdata); s = codes_power(binary_scale_factor, 2); d = codes_power(-decimal_scale_factor, 10); - scals = (T*)grib_context_malloc(a->context_, maxv * sizeof(T)); + scals = (T*)grib_context_malloc(context_, maxv * sizeof(T)); if (!scals) return GRIB_OUT_OF_MEMORY; scals[0] = 0; @@ -690,7 +689,7 @@ static int unpack_real(grib_accessor* a, T* val, size_t* len) if (operat != 0) scals[i] = (1.0 / operat); else { - grib_context_log(a->context_, GRIB_LOG_WARNING, + grib_context_log(context_, GRIB_LOG_WARNING, "%s: Problem with operator div by zero at index %d of %d", cclass_name, i, maxv); scals[i] = 0; } @@ -749,22 +748,22 @@ static int unpack_real(grib_accessor* a, T* val, size_t* len) //Assert(*len >= i); if (*len < i) { - grib_context_log(a->context_, GRIB_LOG_ERROR, "%s::%s: Invalid values *len=%zu and i=%zu.", + grib_context_log(context_, GRIB_LOG_ERROR, "%s::%s: Invalid values *len=%zu and i=%zu.", cclass_name, __func__, *len, i); - grib_context_log(a->context_, GRIB_LOG_ERROR, "Make sure your array is large enough."); + grib_context_log(context_, GRIB_LOG_ERROR, "Make sure your array is large enough."); ret = GRIB_ARRAY_TOO_SMALL; } else { *len = i; } - grib_context_free(a->context_, scals); + grib_context_free(context_, scals); return ret; } int grib_accessor_data_complex_packing_t::unpack_double(double* val, size_t* len) { - return unpack_real(this, val, len); + return unpack_real(val, len); } int grib_accessor_data_complex_packing_t::unpack_float(float* val, size_t* len) @@ -778,7 +777,7 @@ int grib_accessor_data_complex_packing_t::unpack_float(float* val, size_t* len) double* val8 = (double*)grib_context_malloc(context_, size * (sizeof(double))); if (!val8) return GRIB_OUT_OF_MEMORY; - int err = unpack_real(this, val8, len); + int err = unpack_real(val8, len); if (err) { grib_context_free(context_, val8); return err; diff --git a/src/accessor/grib_accessor_class_data_complex_packing.h b/src/accessor/grib_accessor_class_data_complex_packing.h index 6fd4e72ca..bd489883a 100644 --- a/src/accessor/grib_accessor_class_data_complex_packing.h +++ b/src/accessor/grib_accessor_class_data_complex_packing.h @@ -29,15 +29,19 @@ public: int value_count(long*) override; void init(const long, grib_arguments*) override; -public: +protected: + const char* sub_j_; + const char* sub_k_; + const char* sub_m_; + +private: const char* GRIBEX_sh_bug_present_; const char* ieee_floats_; const char* laplacianOperatorIsSet_; const char* laplacianOperator_; - const char* sub_j_; - const char* sub_k_; - const char* sub_m_; const char* pen_j_; const char* pen_k_; const char* pen_m_; + + template int unpack_real(T* val, size_t* len); }; diff --git a/src/accessor/grib_accessor_class_data_g1second_order_general_packing.cc b/src/accessor/grib_accessor_class_data_g1second_order_general_packing.cc index 400381670..ac9622b64 100644 --- a/src/accessor/grib_accessor_class_data_g1second_order_general_packing.cc +++ b/src/accessor/grib_accessor_class_data_g1second_order_general_packing.cc @@ -48,9 +48,8 @@ int grib_accessor_data_g1second_order_general_packing_t::value_count(long* numbe } template -static int unpack_real(grib_accessor* a, T* values, size_t* len) +int grib_accessor_data_g1second_order_general_packing_t::unpack_real(T* values, size_t* len) { - grib_accessor_data_g1second_order_general_packing_t* self = (grib_accessor_data_g1second_order_general_packing_t*)a; static_assert(std::is_floating_point::value, "Requires floating point numbers"); int ret = 0; long numberOfGroups, numberOfSecondOrderPackedValues; @@ -59,7 +58,7 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len) long* X = 0; long pos = 0; long widthOfFirstOrderValues = 0; - unsigned char* buf = (unsigned char*)grib_handle_of_accessor(a)->buffer->data; + unsigned char* buf = (unsigned char*)grib_handle_of_accessor(this)->buffer->data; long i, n; double reference_value; long binary_scale_factor; @@ -69,44 +68,44 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len) long groupLength, j; size_t groupWidthsSize; - buf += a->byte_offset(); - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfGroups_, &numberOfGroups)) != GRIB_SUCCESS) + buf += byte_offset(); + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), numberOfGroups_, &numberOfGroups)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->widthOfFirstOrderValues_, &widthOfFirstOrderValues)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), widthOfFirstOrderValues_, &widthOfFirstOrderValues)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_double_internal(grib_handle_of_accessor(a), self->reference_value_, &reference_value)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(grib_handle_of_accessor(this), reference_value_, &reference_value)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfSecondOrderPackedValues_, + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), numberOfSecondOrderPackedValues_, &numberOfSecondOrderPackedValues)) != GRIB_SUCCESS) return ret; if (*len < (size_t)numberOfSecondOrderPackedValues) return GRIB_ARRAY_TOO_SMALL; - groupWidths = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * numberOfGroups); + groupWidths = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfGroups); groupWidthsSize = numberOfGroups; - if ((ret = grib_get_long_array_internal(grib_handle_of_accessor(a), self->groupWidths_, groupWidths, &groupWidthsSize)) != GRIB_SUCCESS) + if ((ret = grib_get_long_array_internal(grib_handle_of_accessor(this), groupWidths_, groupWidths, &groupWidthsSize)) != GRIB_SUCCESS) return ret; - secondaryBitmap = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * (numberOfSecondOrderPackedValues + 1)); + secondaryBitmap = (long*)grib_context_malloc_clear(context_, sizeof(long) * (numberOfSecondOrderPackedValues + 1)); secondaryBitmap[numberOfSecondOrderPackedValues] = 1; grib_decode_long_array(buf, &pos, 1, numberOfSecondOrderPackedValues, secondaryBitmap); pos = 8 * ((pos + 7) / 8); - firstOrderValues = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * numberOfGroups); + firstOrderValues = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfGroups); grib_decode_long_array(buf, &pos, widthOfFirstOrderValues, numberOfGroups, firstOrderValues); pos = 8 * ((pos + 7) / 8); - X = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * numberOfSecondOrderPackedValues); + X = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfSecondOrderPackedValues); n = 0; i = -1; @@ -143,22 +142,22 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len) } *len = numberOfSecondOrderPackedValues; - grib_context_free(a->context_, secondaryBitmap); - grib_context_free(a->context_, firstOrderValues); - grib_context_free(a->context_, X); - grib_context_free(a->context_, groupWidths); + grib_context_free(context_, secondaryBitmap); + grib_context_free(context_, firstOrderValues); + grib_context_free(context_, X); + grib_context_free(context_, groupWidths); return ret; } int grib_accessor_data_g1second_order_general_packing_t::unpack_float(float* values, size_t* len) { - return unpack_real(this, values, len); + return unpack_real(values, len); } int grib_accessor_data_g1second_order_general_packing_t::unpack_double(double* values, size_t* len) { - return unpack_real(this, values, len); + return unpack_real(values, len); } int grib_accessor_data_g1second_order_general_packing_t::pack_double(const double* cval, size_t* len) diff --git a/src/accessor/grib_accessor_class_data_g1second_order_general_packing.h b/src/accessor/grib_accessor_class_data_g1second_order_general_packing.h index c04deaa2a..159e1f98c 100644 --- a/src/accessor/grib_accessor_class_data_g1second_order_general_packing.h +++ b/src/accessor/grib_accessor_class_data_g1second_order_general_packing.h @@ -25,7 +25,7 @@ public: int value_count(long*) override; void init(const long, grib_arguments*) override; -public: +private: const char* half_byte_; const char* packingType_; const char* ieee_packing_; @@ -42,4 +42,6 @@ public: const char* jPointsAreConsecutive_; const char* bitmap_; const char* groupWidths_; + + template int unpack_real(T* values, size_t* len); }; diff --git a/src/accessor/grib_accessor_class_data_g1second_order_row_by_row_packing.cc b/src/accessor/grib_accessor_class_data_g1second_order_row_by_row_packing.cc index 652ad9e4b..49c8550c2 100644 --- a/src/accessor/grib_accessor_class_data_g1second_order_row_by_row_packing.cc +++ b/src/accessor/grib_accessor_class_data_g1second_order_row_by_row_packing.cc @@ -113,10 +113,9 @@ int grib_accessor_data_g1second_order_row_by_row_packing_t::value_count(long* co } template -static int unpack_real(grib_accessor* a, T* values, size_t* len) +int grib_accessor_data_g1second_order_row_by_row_packing_t::unpack_real(T* values, size_t* len) { - grib_accessor_data_g1second_order_row_by_row_packing_t* self = (grib_accessor_data_g1second_order_row_by_row_packing_t*)a; - grib_handle* gh = grib_handle_of_accessor(a); + grib_handle* gh = grib_handle_of_accessor(this); int ret = 0; long numberOfGroups, numberOfSecondOrderPackedValues; long* groupWidths = 0; @@ -138,25 +137,25 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len) size_t plSize = 0; long* pl = 0; - buf += a->byte_offset(); - if ((ret = grib_get_long_internal(gh, self->numberOfGroups_, &numberOfGroups)) != GRIB_SUCCESS) + buf += byte_offset(); + if ((ret = grib_get_long_internal(gh, numberOfGroups_, &numberOfGroups)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->jPointsAreConsecutive_, &jPointsAreConsecutive)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, jPointsAreConsecutive_, &jPointsAreConsecutive)) != GRIB_SUCCESS) return ret; - if (self->bitmap_) + if (bitmap_) bitmapPresent = 1; - ret = grib_get_size(gh, self->pl_, &plSize); + ret = grib_get_size(gh, pl_, &plSize); if (ret == GRIB_SUCCESS) { - pl = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * plSize); - if ((ret = grib_get_long_array(gh, self->pl_, pl, &plSize)) != GRIB_SUCCESS) + pl = (long*)grib_context_malloc_clear(context_, sizeof(long) * plSize); + if ((ret = grib_get_long_array(gh, pl_, pl, &plSize)) != GRIB_SUCCESS) return ret; } - if ((ret = grib_get_long_internal(gh, self->Ni_, &Ni)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, Ni_, &Ni)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->Nj_, &Nj)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, Nj_, &Nj)) != GRIB_SUCCESS) return ret; if (jPointsAreConsecutive) { numberOfRows = Ni; @@ -167,7 +166,7 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len) numberOfColumns = Ni; } - numbersPerRow = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * numberOfRows); + numbersPerRow = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfRows); if (!numbersPerRow) return GRIB_OUT_OF_MEMORY; if (bitmapPresent) { @@ -179,9 +178,9 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len) for (i = 0; i < numberOfRows; i++) numberOfPoints += pl[i]; } - bitmap = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * numberOfPoints); + bitmap = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfPoints); pbitmap = bitmap; - grib_get_long_array(gh, self->bitmap_, bitmap, &numberOfPoints); + grib_get_long_array(gh, bitmap_, bitmap, &numberOfPoints); if (plSize && pl) { for (i = 0; i < numberOfRows; i++) { for (j = 0; j < pl[i]; j++) { @@ -198,7 +197,7 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len) } } - grib_context_free(a->context_, pbitmap); + grib_context_free(context_, pbitmap); } else { if (plSize && pl) { @@ -211,28 +210,28 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len) } } - if ((ret = grib_get_long_internal(gh, self->widthOfFirstOrderValues_, &widthOfFirstOrderValues)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, widthOfFirstOrderValues_, &widthOfFirstOrderValues)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_double_internal(gh, self->reference_value_, &reference_value)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(gh, reference_value_, &reference_value)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->numberOfSecondOrderPackedValues_, + if ((ret = grib_get_long_internal(gh, numberOfSecondOrderPackedValues_, &numberOfSecondOrderPackedValues)) != GRIB_SUCCESS) return ret; - groupWidths = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * numberOfGroups); + groupWidths = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfGroups); groupWidthsSize = numberOfGroups; - if ((ret = grib_get_long_array_internal(gh, self->groupWidths_, groupWidths, &groupWidthsSize)) != GRIB_SUCCESS) + if ((ret = grib_get_long_array_internal(gh, groupWidths_, groupWidths, &groupWidthsSize)) != GRIB_SUCCESS) return ret; - firstOrderValues = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * numberOfGroups); + firstOrderValues = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfGroups); grib_decode_long_array(buf, &pos, widthOfFirstOrderValues, numberOfGroups, firstOrderValues); pos = 8 * ((pos + 7) / 8); @@ -243,7 +242,7 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len) if (*len < (size_t)n) return GRIB_ARRAY_TOO_SMALL; - X = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * n); + X = (long*)grib_context_malloc_clear(context_, sizeof(long) * n); n = 0; k = 0; for (i = 0; i < numberOfGroups; i++) { @@ -268,25 +267,25 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len) for (i = 0; i < n; i++) { values[i] = (T)(((X[i] * s) + reference_value) * d); } - grib_context_free(a->context_, firstOrderValues); - grib_context_free(a->context_, X); - grib_context_free(a->context_, groupWidths); + grib_context_free(context_, firstOrderValues); + grib_context_free(context_, X); + grib_context_free(context_, groupWidths); if (plSize) - grib_context_free(a->context_, pl); + grib_context_free(context_, pl); if (numbersPerRow) - grib_context_free(a->context_, numbersPerRow); + grib_context_free(context_, numbersPerRow); return ret; } int grib_accessor_data_g1second_order_row_by_row_packing_t::unpack_float(float* values, size_t* len) { - return unpack_real(this, values, len); + return unpack_real(values, len); } int grib_accessor_data_g1second_order_row_by_row_packing_t::unpack_double(double* values, size_t* len) { - return unpack_real(this, values, len); + return unpack_real(values, len); } int grib_accessor_data_g1second_order_row_by_row_packing_t::pack_double(const double* cval, size_t* len) diff --git a/src/accessor/grib_accessor_class_data_g1second_order_row_by_row_packing.h b/src/accessor/grib_accessor_class_data_g1second_order_row_by_row_packing.h index af224ab56..263830ad8 100644 --- a/src/accessor/grib_accessor_class_data_g1second_order_row_by_row_packing.h +++ b/src/accessor/grib_accessor_class_data_g1second_order_row_by_row_packing.h @@ -25,7 +25,7 @@ public: int value_count(long*) override; void init(const long, grib_arguments*) override; -public: +private: const char* half_byte_; const char* packingType_; const char* ieee_packing_; @@ -42,4 +42,6 @@ public: const char* jPointsAreConsecutive_; const char* bitmap_; const char* groupWidths_; + + template int unpack_real(T* values, size_t* len); }; diff --git a/src/accessor/grib_accessor_class_data_g1simple_packing.h b/src/accessor/grib_accessor_class_data_g1simple_packing.h index 4fdcc1241..789648747 100644 --- a/src/accessor/grib_accessor_class_data_g1simple_packing.h +++ b/src/accessor/grib_accessor_class_data_g1simple_packing.h @@ -22,7 +22,7 @@ public: int value_count(long*) override; void init(const long, grib_arguments*) override; -public: +protected: const char* half_byte_; const char* packingType_; const char* ieee_packing_; diff --git a/src/accessor/grib_accessor_class_data_g22order_packing.cc b/src/accessor/grib_accessor_class_data_g22order_packing.cc index 895b4459a..9097f87f7 100644 --- a/src/accessor/grib_accessor_class_data_g22order_packing.cc +++ b/src/accessor/grib_accessor_class_data_g22order_packing.cc @@ -1461,12 +1461,11 @@ int grib_accessor_data_g22order_packing_t::pack_double(const double* val, size_t } template -static int unpack(grib_accessor* a, T* val, size_t* len) +int grib_accessor_data_g22order_packing_t::unpack(T* val, size_t* len) { - grib_accessor_data_g22order_packing_t* self = reinterpret_cast(a); static_assert(std::is_floating_point::value, "Requires floating points numbers"); - const char* cclass_name = a->class_name_; - grib_handle* gh = grib_handle_of_accessor(a); + const char* cclass_name = class_name_; + grib_handle* gh = grib_handle_of_accessor(this); size_t i = 0; size_t j = 0; @@ -1511,57 +1510,57 @@ static int unpack(grib_accessor* a, T* val, size_t* len) long numberOfOctetsExtraDescriptors = 0; double missingValue = 0; - err = a->value_count(&n_vals); + err = value_count(&n_vals); if (err) return err; if (*len < static_cast(n_vals)) return GRIB_ARRAY_TOO_SMALL; - if ((err = grib_get_long_internal(gh, self->bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(gh, self->reference_value_, &reference_value)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(gh, reference_value_, &reference_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->typeOfOriginalFieldValues_, &typeOfOriginalFieldValues)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, typeOfOriginalFieldValues_, &typeOfOriginalFieldValues)) != GRIB_SUCCESS) return err; // Don't call grib_get_long_internal to suppress error message being output - if ((err = grib_get_long(gh, self->groupSplittingMethodUsed_, &groupSplittingMethodUsed)) != GRIB_SUCCESS) + if ((err = grib_get_long(gh, groupSplittingMethodUsed_, &groupSplittingMethodUsed)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->missingValueManagementUsed_, &missingValueManagementUsed)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, missingValueManagementUsed_, &missingValueManagementUsed)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->primaryMissingValueSubstitute_, &primaryMissingValueSubstitute)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, primaryMissingValueSubstitute_, &primaryMissingValueSubstitute)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->secondaryMissingValueSubstitute_, &secondaryMissingValueSubstitute)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, secondaryMissingValueSubstitute_, &secondaryMissingValueSubstitute)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->numberOfGroupsOfDataValues_, &numberOfGroupsOfDataValues)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, numberOfGroupsOfDataValues_, &numberOfGroupsOfDataValues)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->referenceForGroupWidths_, &referenceForGroupWidths)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, referenceForGroupWidths_, &referenceForGroupWidths)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->numberOfBitsUsedForTheGroupWidths_, &numberOfBitsUsedForTheGroupWidths)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, numberOfBitsUsedForTheGroupWidths_, &numberOfBitsUsedForTheGroupWidths)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->referenceForGroupLengths_, &referenceForGroupLengths)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, referenceForGroupLengths_, &referenceForGroupLengths)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->lengthIncrementForTheGroupLengths_, &lengthIncrementForTheGroupLengths)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, lengthIncrementForTheGroupLengths_, &lengthIncrementForTheGroupLengths)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->trueLengthOfLastGroup_, &trueLengthOfLastGroup)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, trueLengthOfLastGroup_, &trueLengthOfLastGroup)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->numberOfBitsUsedForTheScaledGroupLengths_, &numberOfBitsUsedForTheScaledGroupLengths)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, numberOfBitsUsedForTheScaledGroupLengths_, &numberOfBitsUsedForTheScaledGroupLengths)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->orderOfSpatialDifferencing_, &orderOfSpatialDifferencing)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, orderOfSpatialDifferencing_, &orderOfSpatialDifferencing)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->numberOfOctetsExtraDescriptors_, &numberOfOctetsExtraDescriptors)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, numberOfOctetsExtraDescriptors_, &numberOfOctetsExtraDescriptors)) != GRIB_SUCCESS) return err; if ((err = grib_get_double_internal(gh, "missingValue", &missingValue)) != GRIB_SUCCESS) return err; - a->dirty_ = 0; + dirty_ = 0; if (bits_per_value == 0) { for (i = 0; i < n_vals; i++) { @@ -1571,11 +1570,11 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return GRIB_SUCCESS; } - sec_val = (long*)grib_context_malloc(a->context_, (n_vals) * sizeof(long)); + sec_val = (long*)grib_context_malloc(context_, (n_vals) * sizeof(long)); if (!sec_val) return GRIB_OUT_OF_MEMORY; memset(sec_val, 0, (n_vals) * sizeof(long)); // See SUP-718 - buf_ref = buf + a->offset_; + buf_ref = buf + offset_; ref_p = (numberOfGroupsOfDataValues * bits_per_value); @@ -1688,7 +1687,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) // For Complex packing, order == 0 // For Complex packing and spatial differencing, order == 1 or 2 (code table 5.6) if (orderOfSpatialDifferencing != 1 && orderOfSpatialDifferencing != 2) { - grib_context_log(a->context_, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "%s unpacking: Unsupported order of spatial differencing %ld", cclass_name, orderOfSpatialDifferencing); return GRIB_INTERNAL_ERROR; } @@ -1699,7 +1698,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) bias = grib_decode_signed_longb(buf_ref, &ref_p, numberOfOctetsExtraDescriptors * 8); - post_process(a->context_, sec_val, n_vals, orderOfSpatialDifferencing, bias, extras); + post_process(context_, sec_val, n_vals, orderOfSpatialDifferencing, bias, extras); // de_spatial_difference (context_ , sec_val, n_vals, orderOfSpatialDifferencing, bias); } @@ -1715,18 +1714,18 @@ static int unpack(grib_accessor* a, T* val, size_t* len) } } - grib_context_free(a->context_, sec_val); + grib_context_free(context_, sec_val); return err; } int grib_accessor_data_g22order_packing_t::unpack_double(double* val, size_t* len) { - return unpack(this, val, len); + return unpack(val, len); } int grib_accessor_data_g22order_packing_t::unpack_float(float* val, size_t* len) { - return unpack(this, val, len); + return unpack(val, len); } int grib_accessor_data_g22order_packing_t::unpack_double_element(size_t idx, double* val) diff --git a/src/accessor/grib_accessor_class_data_g22order_packing.h b/src/accessor/grib_accessor_class_data_g22order_packing.h index cbb396f62..f8c015afe 100644 --- a/src/accessor/grib_accessor_class_data_g22order_packing.h +++ b/src/accessor/grib_accessor_class_data_g22order_packing.h @@ -27,7 +27,7 @@ public: int unpack_double_element(size_t i, double* val) override; int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) override; -public: +private: const char* numberOfValues_; const char* bits_per_value_; const char* reference_value_; @@ -48,4 +48,6 @@ public: const char* numberOfBitsUsedForTheScaledGroupLengths_; const char* orderOfSpatialDifferencing_; const char* numberOfOctetsExtraDescriptors_; + + template int unpack(T* val, size_t* len); }; diff --git a/src/accessor/grib_accessor_class_data_g2bifourier_packing.cc b/src/accessor/grib_accessor_class_data_g2bifourier_packing.cc index 066744538..d887635e0 100644 --- a/src/accessor/grib_accessor_class_data_g2bifourier_packing.cc +++ b/src/accessor/grib_accessor_class_data_g2bifourier_packing.cc @@ -15,9 +15,6 @@ grib_accessor_data_g2bifourier_packing_t _grib_accessor_data_g2bifourier_packing{}; grib_accessor* grib_accessor_data_g2bifourier_packing = &_grib_accessor_data_g2bifourier_packing; -typedef unsigned long (*encode_float_proc)(double); -typedef double (*decode_float_proc)(unsigned long); - void grib_accessor_data_g2bifourier_packing_t::init(const long v, grib_arguments* args) { grib_accessor_data_simple_packing_t::init(v, args); @@ -145,29 +142,6 @@ static void diamond(long ni, long nj, long itrunc[], long jtrunc[]) insub = insub || (i == 0) || (j == 0); \ } while (0) -typedef struct bif_trunc_t -{ - long bits_per_value; - long decimal_scale_factor; - long binary_scale_factor; - long ieee_floats; - long laplacianOperatorIsSet; - double laplacianOperator; - double reference_value; - long sub_i, sub_j, bif_i, bif_j; - long biFourierTruncationType; - long biFourierSubTruncationType; - long keepaxes; - long maketemplate; - decode_float_proc decode_float; - encode_float_proc encode_float; - int bytes; - long* itruncation_bif; - long* jtruncation_bif; - long* itruncation_sub; - long* jtruncation_sub; - size_t n_vals_bif, n_vals_sub; -} bif_trunc_t; /* * Total number of coefficients @@ -354,45 +328,44 @@ static void free_bif_trunc(bif_trunc_t* bt, grib_accessor* a) grib_context_free(gh->context, bt); } -static bif_trunc_t* new_bif_trunc(grib_accessor* a) +bif_trunc_t* grib_accessor_data_g2bifourier_packing_t::new_bif_trunc() { int ret; - grib_accessor_data_g2bifourier_packing_t* self = (grib_accessor_data_g2bifourier_packing_t*)a; - grib_handle* gh = grib_handle_of_accessor(a); + grib_handle* gh = grib_handle_of_accessor(this); bif_trunc_t* bt = (bif_trunc_t*)grib_context_malloc(gh->context, sizeof(bif_trunc_t)); memset(bt, 0, sizeof(bif_trunc_t)); - if ((ret = grib_get_double_internal(gh, self->reference_value_, &bt->reference_value)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(gh, reference_value_, &bt->reference_value)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->bits_per_value_, &bt->bits_per_value)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, bits_per_value_, &bt->bits_per_value)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->binary_scale_factor_, &bt->binary_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, binary_scale_factor_, &bt->binary_scale_factor)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->decimal_scale_factor_, &bt->decimal_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, decimal_scale_factor_, &bt->decimal_scale_factor)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->ieee_floats_, &bt->ieee_floats)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, ieee_floats_, &bt->ieee_floats)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->laplacianOperatorIsSet_, &bt->laplacianOperatorIsSet)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, laplacianOperatorIsSet_, &bt->laplacianOperatorIsSet)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_double_internal(gh, self->laplacianOperator_, &bt->laplacianOperator)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(gh, laplacianOperator_, &bt->laplacianOperator)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->sub_i_, &bt->sub_i)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, sub_i_, &bt->sub_i)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->sub_j_, &bt->sub_j)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, sub_j_, &bt->sub_j)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->bif_i_, &bt->bif_i)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, bif_i_, &bt->bif_i)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->bif_j_, &bt->bif_j)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, bif_j_, &bt->bif_j)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->biFourierTruncationType_, &bt->biFourierTruncationType)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, biFourierTruncationType_, &bt->biFourierTruncationType)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->biFourierSubTruncationType_, &bt->biFourierSubTruncationType)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, biFourierSubTruncationType_, &bt->biFourierSubTruncationType)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->biFourierDoNotPackAxes_, &bt->keepaxes)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, biFourierDoNotPackAxes_, &bt->keepaxes)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->biFourierMakeTemplate_, &bt->maketemplate)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, biFourierMakeTemplate_, &bt->maketemplate)) != GRIB_SUCCESS) goto cleanup; switch (bt->ieee_floats) { @@ -461,7 +434,7 @@ static bif_trunc_t* new_bif_trunc(grib_accessor* a) cleanup: - free_bif_trunc(bt, a); + free_bif_trunc(bt, this); if (ret) fprintf(stderr, "ERROR: new_bif_trunc: %s\n", grib_get_error_message(ret)); return NULL; @@ -495,7 +468,7 @@ int grib_accessor_data_g2bifourier_packing_t::unpack_double(double* val, size_t* if ((ret = value_count(&count)) != GRIB_SUCCESS) goto cleanup; - bt = new_bif_trunc(this); + bt = new_bif_trunc(); if (bt == NULL) { ret = GRIB_INTERNAL_ERROR; @@ -594,7 +567,7 @@ int grib_accessor_data_g2bifourier_packing_t::pack_double(const double* val, siz goto cleanup; } - bt = new_bif_trunc(this); + bt = new_bif_trunc(); if (bt == NULL) { long makeTemplate = 0; diff --git a/src/accessor/grib_accessor_class_data_g2bifourier_packing.h b/src/accessor/grib_accessor_class_data_g2bifourier_packing.h index 22449fb93..f5bce94fb 100644 --- a/src/accessor/grib_accessor_class_data_g2bifourier_packing.h +++ b/src/accessor/grib_accessor_class_data_g2bifourier_packing.h @@ -12,6 +12,35 @@ #include "grib_accessor_class_data_simple_packing.h" +typedef unsigned long (*encode_float_proc)(double); +typedef double (*decode_float_proc)(unsigned long); + + +typedef struct bif_trunc_t +{ + long bits_per_value; + long decimal_scale_factor; + long binary_scale_factor; + long ieee_floats; + long laplacianOperatorIsSet; + double laplacianOperator; + double reference_value; + long sub_i, sub_j, bif_i, bif_j; + long biFourierTruncationType; + long biFourierSubTruncationType; + long keepaxes; + long maketemplate; + decode_float_proc decode_float; + encode_float_proc encode_float; + int bytes; + long* itruncation_bif; + long* jtruncation_bif; + long* itruncation_sub; + long* jtruncation_sub; + size_t n_vals_bif, n_vals_sub; +} bif_trunc_t; + + class grib_accessor_data_g2bifourier_packing_t : public grib_accessor_data_simple_packing_t { public: @@ -23,7 +52,7 @@ public: int value_count(long*) override; void init(const long, grib_arguments*) override; -public: +private: const char* ieee_floats_; const char* laplacianOperatorIsSet_; const char* laplacianOperator_; @@ -37,4 +66,6 @@ public: const char* biFourierMakeTemplate_; const char* totalNumberOfValuesInUnpackedSubset_; const char* numberOfValues_; + + bif_trunc_t* new_bif_trunc(); }; diff --git a/src/accessor/grib_accessor_class_data_run_length_packing.h b/src/accessor/grib_accessor_class_data_run_length_packing.h index b489c7d9b..8606a6ae0 100644 --- a/src/accessor/grib_accessor_class_data_run_length_packing.h +++ b/src/accessor/grib_accessor_class_data_run_length_packing.h @@ -23,7 +23,7 @@ public: int value_count(long*) override; void init(const long, grib_arguments*) override; -public: +private: const char* number_of_values_; const char* bits_per_value_; const char* max_level_value_; diff --git a/src/accessor/grib_accessor_class_data_secondary_bitmap.h b/src/accessor/grib_accessor_class_data_secondary_bitmap.h index 6ddacd3c0..92771fbe7 100644 --- a/src/accessor/grib_accessor_class_data_secondary_bitmap.h +++ b/src/accessor/grib_accessor_class_data_secondary_bitmap.h @@ -23,7 +23,7 @@ public: void dump(grib_dumper*) override; void init(const long, grib_arguments*) override; -public: +protected: const char* primary_bitmap_; const char* secondary_bitmap_; const char* missing_value_; diff --git a/src/accessor/grib_accessor_class_data_sh_unpacked.cc b/src/accessor/grib_accessor_class_data_sh_unpacked.cc index dfbd55465..6ff72c1b3 100644 --- a/src/accessor/grib_accessor_class_data_sh_unpacked.cc +++ b/src/accessor/grib_accessor_class_data_sh_unpacked.cc @@ -199,6 +199,7 @@ int grib_accessor_data_sh_unpacked_t::unpack_double(double* val, size_t* len) if (sub_k >= 0) { for (hcount = 0; hcount < sub_k + 1; hcount++) { val[i++] = decode_float(grib_decode_unsigned_long(hres, &hpos, 8 * bytes)); + val[i++] = decode_float(grib_decode_unsigned_long(hres, &hpos, 8 * bytes)); if (GRIBEX_sh_bug_present && hcount == sub_k) { /* bug in ecmwf data, last row (K+1)is scaled but should not */ diff --git a/src/accessor/grib_accessor_class_data_shsimple_packing.h b/src/accessor/grib_accessor_class_data_shsimple_packing.h index 841ce9056..df29d6330 100644 --- a/src/accessor/grib_accessor_class_data_shsimple_packing.h +++ b/src/accessor/grib_accessor_class_data_shsimple_packing.h @@ -23,9 +23,7 @@ public: void dump(grib_dumper*) override; void init(const long, grib_arguments*) override; -public: +protected: const char* coded_values_; const char* real_part_; - // TODO(maee): dirty_ shadowed by the derived class - // int dirty_; }; diff --git a/src/accessor/grib_accessor_class_data_simple_packing.cc b/src/accessor/grib_accessor_class_data_simple_packing.cc index 1de1595b9..22e484507 100644 --- a/src/accessor/grib_accessor_class_data_simple_packing.cc +++ b/src/accessor/grib_accessor_class_data_simple_packing.cc @@ -159,14 +159,13 @@ int grib_accessor_data_simple_packing_t::unpack_double_element_set(const size_t* } template -static int unpack(grib_accessor* a, T* val, size_t* len) +int grib_accessor_data_simple_packing_t::unpack(T* val, size_t* len) { - grib_accessor_data_simple_packing_t* self = (grib_accessor_data_simple_packing_t*)a; static_assert(std::is_floating_point::value, "Requires floating point numbers"); - const char* cclass_name = a->class_name_; - grib_handle* gh = grib_handle_of_accessor(a); - unsigned char* buf = (unsigned char*)grib_handle_of_accessor(a)->buffer->data; + const char* cclass_name = class_name_; + grib_handle* gh = grib_handle_of_accessor(this); + unsigned char* buf = (unsigned char*)grib_handle_of_accessor(this)->buffer->data; size_t i = 0; int err = 0; @@ -184,7 +183,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) double units_factor = 1.0; double units_bias = 0.0; - err = a->value_count(&count); + err = value_count(&count); if (err) return err; n_vals = count; @@ -194,7 +193,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return GRIB_ARRAY_TOO_SMALL; } - if ((err = grib_get_long_internal(gh, self->bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return err; /* @@ -205,14 +204,14 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return GRIB_INVALID_BPV; } - if (self->units_factor_ && - (grib_get_double_internal(gh, self->units_factor_, &units_factor) == GRIB_SUCCESS)) { - grib_set_double_internal(gh, self->units_factor_, 1.0); + if (units_factor_ && + (grib_get_double_internal(gh, units_factor_, &units_factor) == GRIB_SUCCESS)) { + grib_set_double_internal(gh, units_factor_, 1.0); } - if (self->units_bias_ && - (grib_get_double_internal(gh, self->units_bias_, &units_bias) == GRIB_SUCCESS)) { - grib_set_double_internal(gh, self->units_bias_, 0.0); + if (units_bias_ && + (grib_get_double_internal(gh, units_bias_, &units_bias) == GRIB_SUCCESS)) { + grib_set_double_internal(gh, units_bias_, 0.0); } if (n_vals == 0) { @@ -220,15 +219,15 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return GRIB_SUCCESS; } - a->dirty_ = 0; + dirty_ = 0; - if ((err = grib_get_double_internal(gh, self->reference_value_, &reference_value)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(gh, reference_value_, &reference_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return err; /* Special case */ @@ -243,23 +242,23 @@ static int unpack(grib_accessor* a, T* val, size_t* len) s = codes_power(binary_scale_factor, 2); d = codes_power(-decimal_scale_factor, 10); - grib_context_log(a->context_, GRIB_LOG_DEBUG, - "%s %s: Creating %s, %zu values", cclass_name, __func__, a->name_, n_vals); + grib_context_log(context_, GRIB_LOG_DEBUG, + "%s %s: Creating %s, %zu values", cclass_name, __func__, name_, n_vals); - offsetBeforeData = a->byte_offset(); + offsetBeforeData = byte_offset(); buf += offsetBeforeData; /*Assert(((bits_per_value*n_vals)/8) < (1<<29));*/ /* See GRIB-787 */ /* ECC-941 */ - if (!a->context_->ieee_packing) { + if (!context_->ieee_packing) { /* Must turn off this check when the environment variable ECCODES_GRIB_IEEE_PACKING is on */ long offsetAfterData = 0; err = grib_get_long(gh, "offsetAfterData", &offsetAfterData); if (!err && offsetAfterData > offsetBeforeData) { const long valuesSize = (bits_per_value * n_vals) / 8; /*in bytes*/ if (offsetBeforeData + valuesSize > offsetAfterData) { - grib_context_log(a->context_, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "%s: Data section size mismatch: " "offset before data=%ld, offset after data=%ld (num values=%zu, bits per value=%ld)", cclass_name, offsetBeforeData, offsetAfterData, n_vals, bits_per_value); @@ -275,7 +274,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) // } } - grib_context_log(a->context_, GRIB_LOG_DEBUG, + grib_context_log(context_, GRIB_LOG_DEBUG, "%s %s: calling outline function: bpv: %ld, rv: %g, bsf: %ld, dsf: %ld", cclass_name, __func__, bits_per_value, reference_value, binary_scale_factor, decimal_scale_factor); grib_decode_array(buf, &pos, bits_per_value, reference_value, s, d, n_vals, val); @@ -304,19 +303,19 @@ static int unpack(grib_accessor* a, T* val, size_t* len) int grib_accessor_data_simple_packing_t::unpack_double(double* val, size_t* len) { - return unpack(this, val, len); + return unpack(val, len); } int grib_accessor_data_simple_packing_t::unpack_float(float* val, size_t* len) { - return unpack(this, val, len); + return unpack(val, len); } -static int _unpack_double(grib_accessor* a, double* val, size_t* len, unsigned char* buf, long pos, size_t n_vals) +int grib_accessor_data_simple_packing_t::_unpack_double(double* val, size_t* len, unsigned char* buf, long pos, size_t n_vals) { - grib_accessor_data_simple_packing_t* self = (grib_accessor_data_simple_packing_t*)a; - grib_handle* gh = grib_handle_of_accessor(a); - const char* cclass_name = a->class_name_; + grib_accessor_data_simple_packing_t* self = (grib_accessor_data_simple_packing_t*)this; + grib_handle* gh = grib_handle_of_accessor(this); + const char* cclass_name = class_name_; size_t i = 0; int err = 0; @@ -362,7 +361,7 @@ static int _unpack_double(grib_accessor* a, double* val, size_t* len, unsigned c return GRIB_SUCCESS; } - a->dirty_ = 0; + dirty_ = 0; if ((err = grib_get_double_internal(gh, self->reference_value_, &reference_value)) != GRIB_SUCCESS) return err; @@ -385,23 +384,23 @@ static int _unpack_double(grib_accessor* a, double* val, size_t* len, unsigned c s = codes_power(binary_scale_factor, 2); d = codes_power(-decimal_scale_factor, 10); - grib_context_log(a->context_, GRIB_LOG_DEBUG, - "%s %s: Creating %s, %zu values", cclass_name, __func__, a->name_, n_vals); + grib_context_log(context_, GRIB_LOG_DEBUG, + "%s %s: Creating %s, %zu values", cclass_name, __func__, name_, n_vals); - offsetBeforeData = a->byte_offset(); + offsetBeforeData = byte_offset(); buf += offsetBeforeData; /*Assert(((bits_per_value*n_vals)/8) < (1<<29));*/ /* See GRIB-787 */ /* ECC-941 */ - if (!a->context_->ieee_packing) { + if (!context_->ieee_packing) { /* Must turn off this check when the environment variable ECCODES_GRIB_IEEE_PACKING is on */ long offsetAfterData = 0; err = grib_get_long(gh, "offsetAfterData", &offsetAfterData); if (!err && offsetAfterData > offsetBeforeData) { const long valuesSize = (bits_per_value * n_vals) / 8; /*in bytes*/ if (offsetBeforeData + valuesSize > offsetAfterData) { - grib_context_log(a->context_, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "Data section size mismatch: offset before data=%ld, offset after data=%ld (num values=%ld, bits per value=%ld)", offsetBeforeData, offsetAfterData, n_vals, bits_per_value); return GRIB_DECODING_ERROR; @@ -417,7 +416,7 @@ static int _unpack_double(grib_accessor* a, double* val, size_t* len, unsigned c // } } - grib_context_log(a->context_, GRIB_LOG_DEBUG, + grib_context_log(context_, GRIB_LOG_DEBUG, "unpack_double: calling outline function : bpv %d, rv : %g, sf : %d, dsf : %d ", bits_per_value, reference_value, binary_scale_factor, decimal_scale_factor); grib_decode_array(buf, &pos, bits_per_value, reference_value, s, d, n_vals, val); @@ -454,7 +453,7 @@ int grib_accessor_data_simple_packing_t::unpack_double_subarray(double* val, siz buf += (start * bits_per_value) / 8; pos = start * bits_per_value % 8; - return _unpack_double(this, val, plen, buf, pos, nvals); + return _unpack_double(val, plen, buf, pos, nvals); } int grib_accessor_data_simple_packing_t::pack_double(const double* val, size_t* len) diff --git a/src/accessor/grib_accessor_class_data_simple_packing.h b/src/accessor/grib_accessor_class_data_simple_packing.h index 6de820ebc..0b196f086 100644 --- a/src/accessor/grib_accessor_class_data_simple_packing.h +++ b/src/accessor/grib_accessor_class_data_simple_packing.h @@ -28,7 +28,7 @@ public: int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) override; int unpack_double_subarray(double* val, size_t start, size_t len) override; -public: +protected: int edition_; const char* units_factor_; const char* units_bias_; @@ -39,4 +39,8 @@ public: const char* binary_scale_factor_; const char* decimal_scale_factor_; const char* optimize_scaling_factor_; + +private: + template int unpack(T* val, size_t* len); + int _unpack_double(double* val, size_t* len, unsigned char* buf, long pos, size_t n_vals); }; diff --git a/src/accessor/grib_accessor_class_dictionary.cc b/src/accessor/grib_accessor_class_dictionary.cc index 6bca21294..933a89ec4 100644 --- a/src/accessor/grib_accessor_class_dictionary.cc +++ b/src/accessor/grib_accessor_class_dictionary.cc @@ -29,10 +29,8 @@ void grib_accessor_dictionary_t::init(const long len, grib_arguments* params) flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -static grib_trie* load_dictionary(grib_accessor* a, int* err) +grib_trie* grib_accessor_dictionary_t::load_dictionary(int* err) { - grib_accessor_dictionary_t* self = (grib_accessor_dictionary_t*)a; - char* filename = NULL; char line[1024] = { 0, @@ -55,17 +53,17 @@ static grib_trie* load_dictionary(grib_accessor* a, int* err) grib_trie* dictionary = NULL; FILE* f = NULL; int i = 0; - grib_handle* h = grib_handle_of_accessor(a); - grib_context* c = a->context_; + grib_handle* h = grib_handle_of_accessor(this); + grib_context* c = context_; *err = GRIB_SUCCESS; len = 1024; - if (self->masterDir_ != NULL) - grib_get_string(h, self->masterDir_, masterDir, &len); + if (masterDir_ != NULL) + grib_get_string(h, masterDir_, masterDir, &len); len = 1024; - if (self->localDir_ != NULL) - grib_get_string(h, self->localDir_, localDir, &len); + if (localDir_ != NULL) + grib_get_string(h, localDir_, localDir, &len); if (*masterDir != 0) { char name[2048] = { @@ -74,12 +72,12 @@ static grib_trie* load_dictionary(grib_accessor* a, int* err) char recomposed[2048] = { 0, }; - snprintf(name, sizeof(name), "%s/%s", masterDir, self->dictionary_); + snprintf(name, sizeof(name), "%s/%s", masterDir, dictionary_); grib_recompose_name(h, NULL, name, recomposed, 0); filename = grib_context_full_defs_path(c, recomposed); } else { - filename = grib_context_full_defs_path(c, self->dictionary_); + filename = grib_context_full_defs_path(c, dictionary_); } if (*localDir != 0) { @@ -89,7 +87,7 @@ static grib_trie* load_dictionary(grib_accessor* a, int* err) char localRecomposed[1024] = { 0, }; - snprintf(localName, sizeof(localName), "%s/%s", localDir, self->dictionary_); + snprintf(localName, sizeof(localName), "%s/%s", localDir, dictionary_); grib_recompose_name(h, NULL, localName, localRecomposed, 0); localFilename = grib_context_full_defs_path(c, localRecomposed); snprintf(dictName, sizeof(dictName), "%s:%s", localFilename, filename); @@ -99,7 +97,7 @@ static grib_trie* load_dictionary(grib_accessor* a, int* err) } if (!filename) { - grib_context_log(c, GRIB_LOG_ERROR, "Unable to find def file %s", self->dictionary_); + grib_context_log(c, GRIB_LOG_ERROR, "Unable to find def file %s", dictionary_); *err = GRIB_FILE_NOT_FOUND; return NULL; } @@ -108,11 +106,11 @@ static grib_trie* load_dictionary(grib_accessor* a, int* err) } dictionary = (grib_trie*)grib_trie_get(c->lists, dictName); if (dictionary) { - grib_context_log(c, GRIB_LOG_DEBUG, "using dictionary %s from cache", self->dictionary_); + grib_context_log(c, GRIB_LOG_DEBUG, "using dictionary %s from cache", dictionary_); return dictionary; } else { - grib_context_log(c, GRIB_LOG_DEBUG, "using dictionary %s from file %s", self->dictionary_, filename); + grib_context_log(c, GRIB_LOG_DEBUG, "using dictionary %s from file %s", dictionary_, filename); } f = codes_fopen(filename, "r"); @@ -192,7 +190,7 @@ int grib_accessor_dictionary_t::unpack_string(char* buffer, size_t* len) size_t rsize = 0; int i = 0; - grib_trie* dictionary = load_dictionary(this, &err); + grib_trie* dictionary = load_dictionary(&err); if (err) return err; diff --git a/src/accessor/grib_accessor_class_dictionary.h b/src/accessor/grib_accessor_class_dictionary.h index dd1fba934..7c6b8ed76 100644 --- a/src/accessor/grib_accessor_class_dictionary.h +++ b/src/accessor/grib_accessor_class_dictionary.h @@ -26,10 +26,12 @@ public: void dump(grib_dumper*) override; void init(const long, grib_arguments*) override; -public: +private: const char* dictionary_; const char* key_; long column_; const char* masterDir_; const char* localDir_; + + grib_trie* load_dictionary(int* err); }; diff --git a/src/accessor/grib_accessor_class_evaluate.h b/src/accessor/grib_accessor_class_evaluate.h index 3156a683d..53f5420ae 100644 --- a/src/accessor/grib_accessor_class_evaluate.h +++ b/src/accessor/grib_accessor_class_evaluate.h @@ -21,6 +21,6 @@ public: int unpack_long(long* val, size_t* len) override; void init(const long, grib_arguments*) override; -public: +protected: grib_arguments* arg_; }; diff --git a/src/accessor/grib_accessor_class_expanded_descriptors.cc b/src/accessor/grib_accessor_class_expanded_descriptors.cc index 381466428..6303dd9b1 100644 --- a/src/accessor/grib_accessor_class_expanded_descriptors.cc +++ b/src/accessor/grib_accessor_class_expanded_descriptors.cc @@ -19,16 +19,6 @@ grib_accessor* grib_accessor_expanded_descriptors = &_grib_accessor_expanded_des #define DESC_SIZE_INIT 400 /* Initial size for grib_bufr_descriptors_array_new */ #define DESC_SIZE_INCR 400 /* Increment size for grib_bufr_descriptors_array_new */ -typedef struct change_coding_params -{ - int associatedFieldWidth; - int localDescriptorWidth; - int extraWidth; - int extraScale; - int newStringWidth; - double referenceFactor; -} change_coding_params; - /* Handy macro to catch errors. * Arguments: array is a pointer to 'bufr_descriptors_array', result is pointer to 'bufr_descriptor' */ #define DESCRIPTORS_POP_FRONT_OR_RETURN(array, result) \ @@ -49,7 +39,7 @@ void grib_accessor_expanded_descriptors_t::init(const long len, grib_arguments* expandedName_ = grib_arguments_get_name(hand, args, n++); rank_ = grib_arguments_get_long(hand, args, n++); if (rank_ != 0) { - expandedAccessor_ = grib_find_accessor(hand, expandedName_); + expandedAccessor_ = dynamic_cast(grib_find_accessor(hand, expandedName_)); } else { expandedAccessor_ = 0; @@ -98,10 +88,8 @@ static char* descriptor_type_name(int dtype) } #endif -static void __expand(grib_accessor* a, bufr_descriptors_array* unexpanded, bufr_descriptors_array* expanded, change_coding_params* ccp, int* err) +void grib_accessor_expanded_descriptors_t::__expand(bufr_descriptors_array* unexpanded, bufr_descriptors_array* expanded, change_coding_params* ccp, int* err) { - grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; - int k, j, i; size_t size = 0; long* v_array = NULL; @@ -115,11 +103,11 @@ static void __expand(grib_accessor* a, bufr_descriptors_array* unexpanded, bufr_ bufr_descriptor* urc = NULL; size_t idx = 0; bufr_descriptor* u0 = NULL; - grib_context* c = a->context_; + grib_context* c = context_; bufr_descriptor* us = NULL; bufr_descriptors_array* inner_expanded = NULL; bufr_descriptors_array* inner_unexpanded = NULL; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); #if MYDEBUG int idepth; #endif @@ -146,23 +134,23 @@ static void __expand(grib_accessor* a, bufr_descriptors_array* unexpanded, bufr_ printf("+++ pop %06ld [%s]\n", u->code, descriptor_type_name(u->type)); #endif /*this is to get the sequence elements of the sequence unexpanded[i] */ - *err = grib_set_long(hand, self->sequence_, u->code); - *err = grib_get_size(hand, self->sequence_, &size); + *err = grib_set_long(hand, sequence_, u->code); + *err = grib_get_size(hand, sequence_, &size); grib_bufr_descriptor_delete(u); if (*err) goto cleanup; v_array = (long*)grib_context_malloc_clear(c, sizeof(long) * size); - *err = grib_get_long_array(hand, self->sequence_, v_array, &size); + *err = grib_get_long_array(hand, sequence_, v_array, &size); if (*err) goto cleanup; inner_unexpanded = grib_bufr_descriptors_array_new(c, DESC_SIZE_INIT, DESC_SIZE_INCR); for (i = 0; i < size; i++) { - vv = grib_bufr_descriptor_new(self->tablesAccessor_, v_array[i], !SILENT, err); + vv = grib_bufr_descriptor_new(tablesAccessor_, v_array[i], !SILENT, err); inner_unexpanded = grib_bufr_descriptors_array_push(inner_unexpanded, vv); } grib_context_free(c, v_array); - inner_expanded = do_expand(a, inner_unexpanded, ccp, err); + inner_expanded = do_expand(inner_unexpanded, ccp, err); if (*err) return; grib_bufr_descriptors_array_delete(inner_unexpanded); @@ -212,7 +200,7 @@ static void __expand(grib_accessor* a, bufr_descriptors_array* unexpanded, bufr_ printf("+++ pop %06ld [%s]\n", u0->code, descriptor_type_name(u0->type)); #endif } - inner_expanded = do_expand(a, inner_unexpanded, ccp, err); + inner_expanded = do_expand(inner_unexpanded, ccp, err); if (*err) return; grib_bufr_descriptors_array_delete(inner_unexpanded); @@ -270,7 +258,7 @@ static void __expand(grib_accessor* a, bufr_descriptors_array* unexpanded, bufr_ for (i = 0; i < us->X; i++) grib_bufr_descriptor_delete(ur[i]); - inner_expanded = do_expand(a, inner_unexpanded, ccp, err); + inner_expanded = do_expand(inner_unexpanded, ccp, err); if (*err) return; grib_bufr_descriptors_array_delete(inner_unexpanded); @@ -290,7 +278,7 @@ static void __expand(grib_accessor* a, bufr_descriptors_array* unexpanded, bufr_ DESCRIPTORS_POP_FRONT_OR_RETURN(unexpanded, u); size = 1; if (ccp->associatedFieldWidth && u->X != 31) { - bufr_descriptor* au = grib_bufr_descriptor_new(self->tablesAccessor_, 999999, !SILENT, err); + bufr_descriptor* au = grib_bufr_descriptor_new(tablesAccessor_, 999999, !SILENT, err); au->width = ccp->associatedFieldWidth; grib_bufr_descriptor_set_scale(au, 0); strcpy(au->shortName, "associatedField"); @@ -416,10 +404,10 @@ cleanup: if (us) grib_bufr_descriptor_delete(us); } -static bufr_descriptors_array* do_expand(grib_accessor* a, bufr_descriptors_array* unexpanded, change_coding_params* ccp, int* err) +bufr_descriptors_array* grib_accessor_expanded_descriptors_t::do_expand(bufr_descriptors_array* unexpanded, change_coding_params* ccp, int* err) { - bufr_descriptors_array* expanded = NULL; - grib_context* c = a->context_; + bufr_descriptors_array* expanded = NULL; + grib_context* c = context_; #if MYDEBUG int idepth; global_depth++; @@ -445,7 +433,7 @@ static bufr_descriptors_array* do_expand(grib_accessor* a, bufr_descriptors_arra } #endif while (unexpanded->n) { - __expand(a, unexpanded, expanded, ccp, err); + __expand(unexpanded, expanded, ccp, err); if (*err) { grib_bufr_descriptors_array_delete(expanded); return NULL; @@ -478,11 +466,10 @@ static bufr_descriptors_array* do_expand(grib_accessor* a, bufr_descriptors_arra return expanded; } -static int expand(grib_accessor* a) +int grib_accessor_expanded_descriptors_t::expand() { - grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; - int err = 0; - size_t unexpandedSize = 0; + int err = 0; + size_t unexpandedSize = 0; /* grib_iarray* unexp=0; */ int i; long* u = 0; @@ -494,25 +481,25 @@ static int expand(grib_accessor* a) bufr_descriptors_array* unexpanded = NULL; bufr_descriptors_array* unexpanded_copy = NULL; bufr_descriptors_array* expanded = NULL; - grib_context* c = a->context_; - const grib_handle* h = grib_handle_of_accessor(a); + grib_context* c = context_; + const grib_handle* h = grib_handle_of_accessor(this); int operator206yyy_width = 0; /* width specified by operator 206YYY */ - if (!self->do_expand_) { + if (!do_expand_) { return err; } - self->do_expand_ = 0; - if (self->rank_ != 0) { - err = expand(self->expandedAccessor_); - self->expanded_ = ((grib_accessor_expanded_descriptors_t*)self->expandedAccessor_)->expanded_; + do_expand_ = 0; + if (rank_ != 0) { + err = expandedAccessor_->expand(); + expanded_ = ((grib_accessor_expanded_descriptors_t*)expandedAccessor_)->expanded_; return err; } - err = grib_get_size(h, self->unexpandedDescriptors_, &unexpandedSize); + err = grib_get_size(h, unexpandedDescriptors_, &unexpandedSize); if (err) return err; if (unexpandedSize == 0) { - grib_context_log(c, GRIB_LOG_ERROR, "%s: Unexpanded size is zero!", a->name_); + grib_context_log(c, GRIB_LOG_ERROR, "%s: Unexpanded size is zero!", name_); return GRIB_DECODING_ERROR; } @@ -521,7 +508,7 @@ static int expand(grib_accessor* a) err = GRIB_OUT_OF_MEMORY; return err; } - err = grib_get_long_array(h, self->unexpandedDescriptors_, u, &unexpandedSize); + err = grib_get_long_array(h, unexpandedDescriptors_, u, &unexpandedSize); if (err) return err; @@ -541,14 +528,14 @@ static int expand(grib_accessor* a) snprintf(key, sizeof(key), "%ld_%ld_%ld_%ld_%ld", centre, masterTablesVersionNumber, localTablesVersionNumber, masterTablesNumber, u[0]); expanded = grib_context_expanded_descriptors_list_get(c, key, u, unexpandedSize); if (expanded) { - self->expanded_ = expanded; + expanded_ = expanded; grib_context_free(c, u); return GRIB_SUCCESS; } - if (!self->tablesAccessor_) { - self->tablesAccessor_ = grib_find_accessor(h, self->tablesAccessorName_); - Assert(self->tablesAccessor_); + if (!tablesAccessor_) { + tablesAccessor_ = grib_find_accessor(h, tablesAccessorName_); + Assert(tablesAccessor_); } unexpanded = grib_bufr_descriptors_array_new(c, unexpandedSize, DESC_SIZE_INCR); @@ -558,9 +545,9 @@ static int expand(grib_accessor* a) bufr_descriptor *aDescriptor1, *aDescriptor2; /* ECC-1274: clear error and only issue msg once */ err = 0; - aDescriptor1 = grib_bufr_descriptor_new(self->tablesAccessor_, u[i], SILENT, &err); + aDescriptor1 = grib_bufr_descriptor_new(tablesAccessor_, u[i], SILENT, &err); err = 0; - aDescriptor2 = grib_bufr_descriptor_new(self->tablesAccessor_, u[i], !SILENT, &err); + aDescriptor2 = grib_bufr_descriptor_new(tablesAccessor_, u[i], !SILENT, &err); /* ECC-433: Operator 206YYY */ if (aDescriptor1->F == 2 && aDescriptor1->X == 6) { @@ -591,30 +578,28 @@ static int expand(grib_accessor* a) ccp.referenceFactor = 1; ccp.associatedFieldWidth = 0; ccp.newStringWidth = 0; - self->expanded_ = do_expand(a, unexpanded, &ccp, &err); + expanded_ = do_expand(unexpanded, &ccp, &err); if (err) { grib_bufr_descriptors_array_delete(unexpanded); grib_bufr_descriptors_array_delete(unexpanded_copy); return err; } - grib_context_expanded_descriptors_list_push(c, key, self->expanded_, unexpanded_copy); + grib_context_expanded_descriptors_list_push(c, key, expanded_, unexpanded_copy); grib_bufr_descriptors_array_delete(unexpanded); return err; } -int grib_accessor_expanded_descriptors_set_do_expand(grib_accessor* a, long do_expand) +int grib_accessor_expanded_descriptors_t::grib_accessor_expanded_descriptors_set_do_expand(long do_expand) { - grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; - self->do_expand_ = do_expand; + do_expand_ = do_expand; return 0; } -bufr_descriptors_array* grib_accessor_expanded_descriptors_get_expanded(grib_accessor* a, int* err) +bufr_descriptors_array* grib_accessor_expanded_descriptors_t::grib_accessor_expanded_descriptors_get_expanded(int* err) { - const grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; - *err = expand(a); - return self->expanded_; + *err = expand(); + return expanded_; } int grib_accessor_expanded_descriptors_t::unpack_double(double* val, size_t* len) @@ -633,7 +618,7 @@ int grib_accessor_expanded_descriptors_t::unpack_double(double* val, size_t* len grib_context_free(context_, lval); } else { - ret = expand(this); + ret = expand(); if (ret) return ret; @@ -657,7 +642,7 @@ int grib_accessor_expanded_descriptors_t::unpack_long(long* val, size_t* len) size_t rlen = 0; size_t i = 0; - ret = expand(this); + ret = expand(); if (ret) return ret; if (!expanded_) @@ -736,7 +721,7 @@ int grib_accessor_expanded_descriptors_t::value_count(long* rlen) int err = 0; *rlen = 0; - err = expand(this); + err = expand(); if (err) { grib_context_log(context_, GRIB_LOG_ERROR, "%s unable to compute size", name_); grib_bufr_descriptors_array_delete(expanded_); diff --git a/src/accessor/grib_accessor_class_expanded_descriptors.h b/src/accessor/grib_accessor_class_expanded_descriptors.h index 682f62105..571469b3d 100644 --- a/src/accessor/grib_accessor_class_expanded_descriptors.h +++ b/src/accessor/grib_accessor_class_expanded_descriptors.h @@ -12,6 +12,16 @@ #include "grib_accessor_class_long.h" +typedef struct change_coding_params +{ + int associatedFieldWidth; + int localDescriptorWidth; + int extraWidth; + int extraScale; + int newStringWidth; + double referenceFactor; +} change_coding_params; + class grib_accessor_expanded_descriptors_t : public grib_accessor_long_t { public: @@ -27,17 +37,21 @@ public: void destroy(grib_context*) override; void init(const long, grib_arguments*) override; -public: + int grib_accessor_expanded_descriptors_set_do_expand(long do_expand); + bufr_descriptors_array* grib_accessor_expanded_descriptors_get_expanded(int* err); + +private: const char* unexpandedDescriptors_; const char* sequence_; const char* expandedName_; const char* tablesAccessorName_; bufr_descriptors_array* expanded_; int rank_; - grib_accessor* expandedAccessor_; + grib_accessor_expanded_descriptors_t* expandedAccessor_; int do_expand_; grib_accessor* tablesAccessor_; -}; -int grib_accessor_expanded_descriptors_set_do_expand(grib_accessor* a, long do_expand); -bufr_descriptors_array* grib_accessor_expanded_descriptors_get_expanded(grib_accessor* a, int* err); + int expand(); + void __expand(bufr_descriptors_array* unexpanded, bufr_descriptors_array* expanded, change_coding_params* ccp, int* err); + bufr_descriptors_array* do_expand(bufr_descriptors_array* unexpanded, change_coding_params* ccp, int* err); +}; diff --git a/src/accessor/grib_accessor_class_g1_message_length.cc b/src/accessor/grib_accessor_class_g1_message_length.cc index 088e8c34c..7ce162c86 100644 --- a/src/accessor/grib_accessor_class_g1_message_length.cc +++ b/src/accessor/grib_accessor_class_g1_message_length.cc @@ -79,7 +79,7 @@ int grib_accessor_g1_message_length_t::pack_long(const long* val, size_t* len) /* Do not directly call pack_long on base class */ /* because in this special case we want to skip the checks. */ /* So we call the helper function which has an extra argument */ - return pack_long_unsigned_helper(this, val, len, /*check=*/0); + return pack_long_unsigned_helper(val, len, /*check=*/0); } if (!s4) @@ -97,7 +97,7 @@ int grib_accessor_g1_message_length_t::pack_long(const long* val, size_t* len) *len = 1; /* Do not do the length checks in this special case */ - if ((ret = pack_long_unsigned_helper(this, &tlen, len, /*check=*/0)) != GRIB_SUCCESS) + if ((ret = pack_long_unsigned_helper(&tlen, len, /*check=*/0)) != GRIB_SUCCESS) return ret; // if((ret = super->pack_long(a,&tlen,len)) != GRIB_SUCCESS) return ret; diff --git a/src/accessor/grib_accessor_class_g1_section4_length.cc b/src/accessor/grib_accessor_class_g1_section4_length.cc index 24d63eb70..b4ff3bff6 100644 --- a/src/accessor/grib_accessor_class_g1_section4_length.cc +++ b/src/accessor/grib_accessor_class_g1_section4_length.cc @@ -31,7 +31,7 @@ int grib_accessor_g1_section4_length_t::pack_long(const long* val, size_t* len) // Note: Do not directly call pack_long on base class // because in this special case we want to skip the checks. // So we call the helper function which has an extra argument - return pack_long_unsigned_helper(this, val, len, /*check=*/0); + return pack_long_unsigned_helper(val, len, /*check=*/0); } int grib_accessor_g1_section4_length_t::unpack_long(long* val, size_t* len) diff --git a/src/accessor/grib_accessor_class_g1date.h b/src/accessor/grib_accessor_class_g1date.h index 87aab7b6d..f4195215f 100644 --- a/src/accessor/grib_accessor_class_g1date.h +++ b/src/accessor/grib_accessor_class_g1date.h @@ -25,7 +25,7 @@ public: int value_count(long*) override; void init(const long, grib_arguments*) override; -public: +protected: const char* century_; const char* year_; const char* month_; diff --git a/src/accessor/grib_accessor_class_g1fcperiod.cc b/src/accessor/grib_accessor_class_g1fcperiod.cc index 29de64124..46acfbbf5 100644 --- a/src/accessor/grib_accessor_class_g1fcperiod.cc +++ b/src/accessor/grib_accessor_class_g1fcperiod.cc @@ -18,7 +18,7 @@ int grib_accessor_g1fcperiod_t::unpack_string(char* val, size_t* len) long start = 0, theEnd = 0; char tmp[1024]; const size_t tmpLen = sizeof(tmp); - int err = grib_g1_step_get_steps(this, &start, &theEnd); + int err = grib_g1_step_get_steps(&start, &theEnd); size_t l = 0; if (err) diff --git a/src/accessor/grib_accessor_class_g1forecastmonth.cc b/src/accessor/grib_accessor_class_g1forecastmonth.cc index 3315831bd..6f9e00a64 100644 --- a/src/accessor/grib_accessor_class_g1forecastmonth.cc +++ b/src/accessor/grib_accessor_class_g1forecastmonth.cc @@ -103,9 +103,8 @@ static int unpack_long_edition2(grib_accessor* a, long* val, size_t* len) return GRIB_SUCCESS; } -static int unpack_long_edition1(grib_accessor* a, long* val, size_t* len) +int grib_accessor_g1forecastmonth_t::unpack_long_edition1(long* val, size_t* len) { - grib_accessor_g1forecastmonth_t* self = (grib_accessor_g1forecastmonth_t*)a; int err = 0; long verification_yearmonth = 0; @@ -116,29 +115,29 @@ static int unpack_long_edition1(grib_accessor* a, long* val, size_t* len) long check = 0; long fcmonth = 0; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), - self->verification_yearmonth_, &verification_yearmonth)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), + verification_yearmonth_, &verification_yearmonth)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->base_date_, &base_date)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), base_date_, &base_date)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->day_, &day)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), day_, &day)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->hour_, &hour)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), hour_, &hour)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->fcmonth_, &gribForecastMonth)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), fcmonth_, &gribForecastMonth)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->check_, &check)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), check_, &check)) != GRIB_SUCCESS) return err; - if ((err = calculate_fcmonth(a, verification_yearmonth, base_date, day, hour, val)) != GRIB_SUCCESS) + if ((err = calculate_fcmonth(this, verification_yearmonth, base_date, day, hour, val)) != GRIB_SUCCESS) return err; /* Verification - compare gribForecastMonth with fcmonth */ fcmonth = *val; if (gribForecastMonth != 0 && gribForecastMonth != fcmonth) { if (check) { - grib_context_log(a->context_, GRIB_LOG_ERROR, "%s=%ld (%s-%s)=%ld", self->fcmonth_, - gribForecastMonth, base_date, self->verification_yearmonth_, fcmonth); + grib_context_log(context_, GRIB_LOG_ERROR, "%s=%ld (%s-%s)=%ld", fcmonth_, + gribForecastMonth, base_date, verification_yearmonth_, fcmonth); Assert(gribForecastMonth == fcmonth); } else { @@ -160,7 +159,7 @@ int grib_accessor_g1forecastmonth_t::unpack_long(long* val, size_t* len) return err; if (edition == 1) - return unpack_long_edition1(this, val, len); + return unpack_long_edition1(val, len); if (edition == 2) return unpack_long_edition2(this, val, len); diff --git a/src/accessor/grib_accessor_class_g1forecastmonth.h b/src/accessor/grib_accessor_class_g1forecastmonth.h index c19be2f31..9737eb16a 100644 --- a/src/accessor/grib_accessor_class_g1forecastmonth.h +++ b/src/accessor/grib_accessor_class_g1forecastmonth.h @@ -24,11 +24,13 @@ public: void dump(grib_dumper*) override; void init(const long, grib_arguments*) override; -public: +private: const char* verification_yearmonth_; const char* base_date_; const char* day_; const char* hour_; const char* fcmonth_; const char* check_; + + int unpack_long_edition1(long* val, size_t* len); }; diff --git a/src/accessor/grib_accessor_class_g1step_range.cc b/src/accessor/grib_accessor_class_g1step_range.cc index d3f0aa0ce..954205381 100644 --- a/src/accessor/grib_accessor_class_g1step_range.cc +++ b/src/accessor/grib_accessor_class_g1step_range.cc @@ -83,9 +83,8 @@ static const int u2s[] = { 1800 /* (15) 30 minutes */ }; -int grib_g1_step_get_steps(grib_accessor* a, long* start, long* theEnd) +int grib_accessor_g1step_range_t::grib_g1_step_get_steps(long* start, long* theEnd) { - grib_accessor_g1step_range_t* self = (grib_accessor_g1step_range_t*)a; int err = 0; long p1 = 0, p2 = 0, unit = 0, timeRangeIndicator = 0, timeRangeIndicatorFromStepRange = 0; long step_unit = 1; @@ -96,30 +95,30 @@ int grib_g1_step_get_steps(grib_accessor* a, long* start, long* theEnd) long newstart, newend; int factor = 1; long u2sf, u2sf_step_unit; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); - if (self->step_unit_ != NULL) - grib_get_long_internal(hand, self->step_unit_, &step_unit); + if (step_unit_ != NULL) + grib_get_long_internal(hand, step_unit_, &step_unit); if (err != GRIB_SUCCESS) return err; - err = grib_get_long_internal(hand, self->unit_, &unit); + err = grib_get_long_internal(hand, unit_, &unit); if (err) return err; if (unit == 254) { unit = 15; /* See ECC-316: WMO says 254 is for 'seconds' but we use 15! */ } - err = grib_get_long_internal(hand, self->p1_, &p1); + err = grib_get_long_internal(hand, p1_, &p1); if (err) return err; - err = grib_get_long_internal(hand, self->p2_, &p2); + err = grib_get_long_internal(hand, p2_, &p2); if (err) return err; - err = grib_get_long_internal(hand, self->timeRangeIndicator_, &timeRangeIndicator); + err = grib_get_long_internal(hand, timeRangeIndicator_, &timeRangeIndicator); if (err) return err; @@ -130,8 +129,8 @@ int grib_g1_step_get_steps(grib_accessor* a, long* start, long* theEnd) if (timeRangeIndicatorFromStepRange == 10) timeRangeIndicator = timeRangeIndicatorFromStepRange; - if (self->stepType_) { - err = grib_get_string_internal(hand, self->stepType_, stepType, &stepTypeLen); + if (stepType_) { + err = grib_get_string_internal(hand, stepType_, stepType, &stepTypeLen); if (err) return err; } @@ -196,7 +195,7 @@ int grib_accessor_g1step_range_t::unpack_string(char* val, size_t* len) size_t stepTypeLen = 20; grib_handle* hand = grib_handle_of_accessor(this); - if ((err = grib_g1_step_get_steps(this, &start, &theEnd)) != GRIB_SUCCESS) { + if ((err = grib_g1_step_get_steps(&start, &theEnd)) != GRIB_SUCCESS) { size_t step_unit_string_len = 10; char step_unit_string[10]; diff --git a/src/accessor/grib_accessor_class_g1step_range.h b/src/accessor/grib_accessor_class_g1step_range.h index d0de789a9..29858ce1a 100644 --- a/src/accessor/grib_accessor_class_g1step_range.h +++ b/src/accessor/grib_accessor_class_g1step_range.h @@ -30,7 +30,10 @@ public: void dump(grib_dumper*) override; void init(const long, grib_arguments*) override; -public: +protected: + int grib_g1_step_get_steps(long* start, long* theEnd); + +private: const char* p1_; const char* p2_; const char* timeRangeIndicator_; diff --git a/src/accessor/grib_accessor_class_g2_mars_labeling.cc b/src/accessor/grib_accessor_class_g2_mars_labeling.cc index 8e8ffa131..509ebf8b8 100644 --- a/src/accessor/grib_accessor_class_g2_mars_labeling.cc +++ b/src/accessor/grib_accessor_class_g2_mars_labeling.cc @@ -77,11 +77,10 @@ int grib_accessor_g2_mars_labeling_t::unpack_string(char* val, size_t* len) return grib_get_string(grib_handle_of_accessor(this), key, val, len); } -static int extra_set(grib_accessor* a, long val) +int grib_accessor_g2_mars_labeling_t::extra_set(long val) { - grib_accessor_g2_mars_labeling_t* self = (grib_accessor_g2_mars_labeling_t*)a; int ret = 0; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); char stepType[30] = { 0, }; @@ -108,7 +107,7 @@ static int extra_set(grib_accessor* a, long val) const int is_wave = grib_is_defined(hand, "waveDirectionNumber"); const int is_wave_prange = grib_is_defined(hand, "typeOfWavePeriodInterval"); - switch (self->index_) { + switch (index_) { case 0: /* class */ return ret; @@ -162,7 +161,7 @@ static int extra_set(grib_accessor* a, long val) break; case 17: /* Ensemble mean (em) */ derivedForecast = 0; - grib_get_string(hand, self->stepType_, stepType, &stepTypelen); + grib_get_string(hand, stepType_, stepType, &stepTypelen); if (!strcmp(stepType, "instant")) { productDefinitionTemplateNumberNew = 2; } @@ -174,7 +173,7 @@ static int extra_set(grib_accessor* a, long val) break; case 18: /* Ensemble standard deviation (es) */ derivedForecast = 4; - grib_get_string(hand, self->stepType_, stepType, &stepTypelen); + grib_get_string(hand, stepType_, stepType, &stepTypelen); if (!strcmp(stepType, "instant")) { productDefinitionTemplateNumberNew = 2; } @@ -258,7 +257,7 @@ static int extra_set(grib_accessor* a, long val) typeOfGeneratingProcess = 255; break; default: - grib_context_log(a->context_, GRIB_LOG_WARNING, "g2_mars_labeling: unknown mars.type %d", (int)val); + grib_context_log(context_, GRIB_LOG_WARNING, "g2_mars_labeling: unknown mars.type %d", (int)val); /*return GRIB_ENCODING_ERROR;*/ } break; @@ -269,7 +268,7 @@ static int extra_set(grib_accessor* a, long val) case 1249: /* elda */ case 1250: /* ewla */ is_eps = 1; /* These streams are all for ensembles */ - grib_get_string(hand, self->stepType_, stepType, &stepTypelen); + grib_get_string(hand, stepType_, stepType, &stepTypelen); is_instant = (strcmp(stepType, "instant") == 0); productDefinitionTemplateNumberNew = grib2_select_PDTN( is_eps, is_instant, @@ -282,8 +281,8 @@ static int extra_set(grib_accessor* a, long val) } break; default: - grib_context_log(a->context_, GRIB_LOG_ERROR, - "invalid first argument of g2_mars_labeling in %s", a->name_); + grib_context_log(context_, GRIB_LOG_ERROR, + "invalid first argument of g2_mars_labeling in %s", name_); return GRIB_INTERNAL_ERROR; } @@ -293,19 +292,19 @@ static int extra_set(grib_accessor* a, long val) } if (productDefinitionTemplateNumberNew >= 0) { - grib_get_long(hand, self->productDefinitionTemplateNumber_, &productDefinitionTemplateNumber); + grib_get_long(hand, productDefinitionTemplateNumber_, &productDefinitionTemplateNumber); if (productDefinitionTemplateNumber != productDefinitionTemplateNumberNew) - grib_set_long(hand, self->productDefinitionTemplateNumber_, productDefinitionTemplateNumberNew); + grib_set_long(hand, productDefinitionTemplateNumber_, productDefinitionTemplateNumberNew); } if (derivedForecast >= 0) { - grib_set_long(hand, self->derivedForecast_, derivedForecast); + grib_set_long(hand, derivedForecast_, derivedForecast); } if (typeOfProcessedData > 0) - grib_set_long(hand, self->typeOfProcessedData_, typeOfProcessedData); + grib_set_long(hand, typeOfProcessedData_, typeOfProcessedData); if (typeOfGeneratingProcess > 0) - grib_set_long(hand, self->typeOfGeneratingProcess_, typeOfGeneratingProcess); + grib_set_long(hand, typeOfGeneratingProcess_, typeOfGeneratingProcess); return ret; } @@ -340,7 +339,7 @@ int grib_accessor_g2_mars_labeling_t::pack_string(const char* val, size_t* len) if (ret) return ret; /* failed */ - return extra_set(this, lval); + return extra_set(lval); } int grib_accessor_g2_mars_labeling_t::pack_long(const long* val, size_t* len) @@ -368,7 +367,7 @@ int grib_accessor_g2_mars_labeling_t::pack_long(const long* val, size_t* len) if (ret) return ret; /* failed */ - return extra_set(this, *val); + return extra_set(*val); } int grib_accessor_g2_mars_labeling_t::value_count(long* count) diff --git a/src/accessor/grib_accessor_class_g2_mars_labeling.h b/src/accessor/grib_accessor_class_g2_mars_labeling.h index fa9e816e5..7655fd60d 100644 --- a/src/accessor/grib_accessor_class_g2_mars_labeling.h +++ b/src/accessor/grib_accessor_class_g2_mars_labeling.h @@ -27,7 +27,7 @@ public: int value_count(long*) override; void init(const long, grib_arguments*) override; -public: +private: int index_; const char* the_class_; const char* stream_; @@ -38,4 +38,6 @@ public: const char* stepType_; const char* derivedForecast_; const char* typeOfGeneratingProcess_; + + int extra_set(long val); }; diff --git a/src/accessor/grib_accessor_class_g2end_step.cc b/src/accessor/grib_accessor_class_g2end_step.cc index 36cd03f5b..a601250d8 100644 --- a/src/accessor/grib_accessor_class_g2end_step.cc +++ b/src/accessor/grib_accessor_class_g2end_step.cc @@ -96,10 +96,8 @@ static int convert_time_range_long_( return GRIB_SUCCESS; } -static int unpack_one_time_range_long_(grib_accessor* a, long* val, size_t* len) +int grib_accessor_g2end_step_t::unpack_one_time_range_long_(long* val, size_t* len) { - grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a; - int err = 0; long start_step_value; long step_units; @@ -107,17 +105,17 @@ static int unpack_one_time_range_long_(grib_accessor* a, long* val, size_t* len) long time_range_value, typeOfTimeIncrement; int add_time_range = 1; /* whether we add lengthOfTimeRange */ - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); - if ((err = grib_get_long_internal(h, self->start_step_value_, &start_step_value))) + if ((err = grib_get_long_internal(h, start_step_value_, &start_step_value))) return err; - if ((err = grib_get_long_internal(h, self->step_units_, &step_units))) + if ((err = grib_get_long_internal(h, step_units_, &step_units))) return err; - if ((err = grib_get_long_internal(h, self->time_range_unit_, &time_range_unit))) + if ((err = grib_get_long_internal(h, time_range_unit_, &time_range_unit))) return err; - if ((err = grib_get_long_internal(h, self->time_range_value_, &time_range_value))) + if ((err = grib_get_long_internal(h, time_range_value_, &time_range_value))) return err; - if ((err = grib_get_long_internal(h, self->typeOfTimeIncrement_, &typeOfTimeIncrement))) + if ((err = grib_get_long_internal(h, typeOfTimeIncrement_, &typeOfTimeIncrement))) return err; err = convert_time_range_long_(h, step_units, time_range_unit, &time_range_value); @@ -146,9 +144,8 @@ static int unpack_one_time_range_long_(grib_accessor* a, long* val, size_t* len) return GRIB_SUCCESS; } -static int unpack_one_time_range_double_(grib_accessor* a, double* val, size_t* len) +int grib_accessor_g2end_step_t::unpack_one_time_range_double_(double* val, size_t* len) { - grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a; int err = 0; double start_step_value; long start_step_unit; @@ -158,19 +155,19 @@ static int unpack_one_time_range_double_(grib_accessor* a, double* val, size_t* long typeOfTimeIncrement; int add_time_range = 1; /* whether we add lengthOfTimeRange */ - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); - if ((err = grib_get_double_internal(h, self->start_step_value_, &start_step_value))) + if ((err = grib_get_double_internal(h, start_step_value_, &start_step_value))) return err; if ((err = grib_get_long_internal(h, "startStepUnit", &start_step_unit))) return err; - if ((err = grib_get_long_internal(h, self->step_units_, &step_units))) + if ((err = grib_get_long_internal(h, step_units_, &step_units))) return err; - if ((err = grib_get_long_internal(h, self->time_range_unit_, &time_range_unit))) + if ((err = grib_get_long_internal(h, time_range_unit_, &time_range_unit))) return err; - if ((err = grib_get_double_internal(h, self->time_range_value_, &time_range_value))) + if ((err = grib_get_double_internal(h, time_range_value_, &time_range_value))) return err; - if ((err = grib_get_long_internal(h, self->typeOfTimeIncrement_, &typeOfTimeIncrement))) + if ((err = grib_get_long_internal(h, typeOfTimeIncrement_, &typeOfTimeIncrement))) return err; eccodes::Step start_step{ start_step_value, start_step_unit }; @@ -199,11 +196,10 @@ static int unpack_one_time_range_double_(grib_accessor* a, double* val, size_t* } #define MAX_NUM_TIME_RANGES 16 /* maximum number of time range specifications */ -static int unpack_multiple_time_ranges_long_(grib_accessor* a, long* val, size_t* len) +int grib_accessor_g2end_step_t::unpack_multiple_time_ranges_long_(long* val, size_t* len) { - grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a; int i = 0, err = 0; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); long numberOfTimeRanges = 0, step_units = 0, start_step_value = 0; size_t count = 0; @@ -217,11 +213,11 @@ static int unpack_multiple_time_ranges_long_(grib_accessor* a, long* val, size_t 0, }; - if ((err = grib_get_long_internal(h, self->start_step_value_, &start_step_value))) + if ((err = grib_get_long_internal(h, start_step_value_, &start_step_value))) return err; - if ((err = grib_get_long_internal(h, self->step_units_, &step_units))) + if ((err = grib_get_long_internal(h, step_units_, &step_units))) return err; - if ((err = grib_get_long_internal(h, self->numberOfTimeRanges_, &numberOfTimeRanges))) + if ((err = grib_get_long_internal(h, numberOfTimeRanges_, &numberOfTimeRanges))) return err; if (numberOfTimeRanges > MAX_NUM_TIME_RANGES) { grib_context_log(h->context, GRIB_LOG_ERROR, "Too many time range specifications!"); @@ -230,11 +226,11 @@ static int unpack_multiple_time_ranges_long_(grib_accessor* a, long* val, size_t count = numberOfTimeRanges; /* Get the arrays for the N time ranges */ - if ((err = grib_get_long_array(h, self->typeOfTimeIncrement_, arr_typeOfTimeIncrement, &count))) + if ((err = grib_get_long_array(h, typeOfTimeIncrement_, arr_typeOfTimeIncrement, &count))) return err; - if ((err = grib_get_long_array(h, self->time_range_unit_, arr_coded_unit, &count))) + if ((err = grib_get_long_array(h, time_range_unit_, arr_coded_unit, &count))) return err; - if ((err = grib_get_long_array(h, self->time_range_value_, arr_coded_time_range, &count))) + if ((err = grib_get_long_array(h, time_range_value_, arr_coded_time_range, &count))) return err; /* Look in the array of typeOfTimeIncrements for first entry whose typeOfTimeIncrement == 2 */ @@ -258,11 +254,10 @@ static int unpack_multiple_time_ranges_long_(grib_accessor* a, long* val, size_t return GRIB_DECODING_ERROR; } -static int unpack_multiple_time_ranges_double_(grib_accessor* a, double* val, size_t* len) +int grib_accessor_g2end_step_t::unpack_multiple_time_ranges_double_(double* val, size_t* len) { - grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a; int i = 0, err = 0; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); long numberOfTimeRanges = 0; long step_units = 0; long start_step_value = 0; @@ -279,17 +274,17 @@ static int unpack_multiple_time_ranges_double_(grib_accessor* a, double* val, si 0, }; - if ((err = grib_get_long_internal(h, self->start_step_value_, &start_step_value))) + if ((err = grib_get_long_internal(h, start_step_value_, &start_step_value))) return err; if ((err = grib_get_long_internal(h, "startStepUnit", &start_step_unit))) return err; eccodes::Step start_step{ start_step_value, start_step_unit }; - if ((err = grib_get_long_internal(h, self->step_units_, &step_units))) + if ((err = grib_get_long_internal(h, step_units_, &step_units))) return err; - if ((err = grib_get_long_internal(h, self->numberOfTimeRanges_, &numberOfTimeRanges))) + if ((err = grib_get_long_internal(h, numberOfTimeRanges_, &numberOfTimeRanges))) return err; if (numberOfTimeRanges > MAX_NUM_TIME_RANGES) { grib_context_log(h->context, GRIB_LOG_ERROR, "Too many time range specifications!"); @@ -298,11 +293,11 @@ static int unpack_multiple_time_ranges_double_(grib_accessor* a, double* val, si count = numberOfTimeRanges; /* Get the arrays for the N time ranges */ - if ((err = grib_get_long_array(h, self->typeOfTimeIncrement_, arr_typeOfTimeIncrement, &count))) + if ((err = grib_get_long_array(h, typeOfTimeIncrement_, arr_typeOfTimeIncrement, &count))) return err; - if ((err = grib_get_long_array(h, self->time_range_unit_, arr_coded_unit, &count))) + if ((err = grib_get_long_array(h, time_range_unit_, arr_coded_unit, &count))) return err; - if ((err = grib_get_long_array(h, self->time_range_value_, arr_coded_time_range, &count))) + if ((err = grib_get_long_array(h, time_range_value_, arr_coded_time_range, &count))) return err; /* Look in the array of typeOfTimeIncrements for first entry whose typeOfTimeIncrement == 2 */ @@ -355,10 +350,10 @@ int grib_accessor_g2end_step_t::unpack_long(long* val, size_t* len) try { if (numberOfTimeRanges == 1) { - ret = unpack_one_time_range_long_(this, val, len); + ret = unpack_one_time_range_long_(val, len); } else { - ret = unpack_multiple_time_ranges_long_(this, val, len); + ret = unpack_multiple_time_ranges_long_(val, len); } } catch (std::exception& e) { @@ -397,10 +392,10 @@ int grib_accessor_g2end_step_t::unpack_double(double* val, size_t* len) try { if (numberOfTimeRanges == 1) { - ret = unpack_one_time_range_double_(this, val, len); + ret = unpack_one_time_range_double_(val, len); } else { - ret = unpack_multiple_time_ranges_double_(this, val, len); + ret = unpack_multiple_time_ranges_double_(val, len); } } catch (std::exception& e) { @@ -411,10 +406,9 @@ int grib_accessor_g2end_step_t::unpack_double(double* val, size_t* len) return ret; } -static int pack_long_(grib_accessor* a, const long end_step_value, const long end_step_unit) +int grib_accessor_g2end_step_t::pack_long_(const long end_step_value, const long end_step_unit) { - grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); int err = 0; long year; @@ -436,34 +430,34 @@ static int pack_long_(grib_accessor* a, const long end_step_value, const long en long typeOfTimeIncrement; double dend, dstep; - const int show_units_for_hours = a->context_->grib_hourly_steps_with_units; + const int show_units_for_hours = context_->grib_hourly_steps_with_units; eccodes::Step end_step{ end_step_value, end_step_unit }; /*point in time */ - if (self->year_ == NULL) { + if (year_ == NULL) { if ((err = grib_set_long_internal(h, "startStepUnit", end_step.unit().value())) != GRIB_SUCCESS) return err; - err = grib_set_long_internal(h, self->start_step_value_, end_step.value()); + err = grib_set_long_internal(h, start_step_value_, end_step.value()); return err; } - if ((err = grib_get_long_internal(h, self->time_range_unit_, &time_range_unit))) + if ((err = grib_get_long_internal(h, time_range_unit_, &time_range_unit))) return err; - if ((err = grib_get_long_internal(h, self->year_, &year))) + if ((err = grib_get_long_internal(h, year_, &year))) return err; - if ((err = grib_get_long_internal(h, self->month_, &month))) + if ((err = grib_get_long_internal(h, month_, &month))) return err; - if ((err = grib_get_long_internal(h, self->day_, &day))) + if ((err = grib_get_long_internal(h, day_, &day))) return err; - if ((err = grib_get_long_internal(h, self->hour_, &hour))) + if ((err = grib_get_long_internal(h, hour_, &hour))) return err; - if ((err = grib_get_long_internal(h, self->minute_, &minute))) + if ((err = grib_get_long_internal(h, minute_, &minute))) return err; - if ((err = grib_get_long_internal(h, self->second_, &second))) + if ((err = grib_get_long_internal(h, second_, &second))) return err; - if ((err = grib_get_long_internal(h, self->start_step_value_, &start_step_value))) + if ((err = grib_get_long_internal(h, start_step_value_, &start_step_value))) return err; if ((err = grib_get_long_internal(h, "startStepUnit", &start_step_unit))) return err; @@ -478,7 +472,7 @@ static int pack_long_(grib_accessor* a, const long end_step_value, const long en return GRIB_WRONG_STEP_UNIT; } - if ((err = grib_get_long_internal(h, self->typeOfTimeIncrement_, &typeOfTimeIncrement))) + if ((err = grib_get_long_internal(h, typeOfTimeIncrement_, &typeOfTimeIncrement))) return err; eccodes::Step start_step{ start_step_value, start_step_unit }; @@ -496,7 +490,7 @@ static int pack_long_(grib_accessor* a, const long end_step_value, const long en grib_context_log(h->context, GRIB_LOG_ERROR, "%s:%s: Date/Time is not valid! " "year=%ld month=%ld day=%ld hour=%ld minute=%ld second=%ld", - a->class_name_, __func__, year, month, day, hour, minute, second); + class_name_, __func__, year, month, day, hour, minute, second); return GRIB_DECODING_ERROR; } @@ -513,17 +507,17 @@ static int pack_long_(grib_accessor* a, const long end_step_value, const long en if (err != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(h, self->year_of_end_of_interval_, year_of_end_of_interval))) + if ((err = grib_set_long_internal(h, year_of_end_of_interval_, year_of_end_of_interval))) return err; - if ((err = grib_set_long_internal(h, self->month_of_end_of_interval_, month_of_end_of_interval))) + if ((err = grib_set_long_internal(h, month_of_end_of_interval_, month_of_end_of_interval))) return err; - if ((err = grib_set_long_internal(h, self->day_of_end_of_interval_, day_of_end_of_interval))) + if ((err = grib_set_long_internal(h, day_of_end_of_interval_, day_of_end_of_interval))) return err; - if ((err = grib_set_long_internal(h, self->hour_of_end_of_interval_, hour_of_end_of_interval))) + if ((err = grib_set_long_internal(h, hour_of_end_of_interval_, hour_of_end_of_interval))) return err; - if ((err = grib_set_long_internal(h, self->minute_of_end_of_interval_, minute_of_end_of_interval))) + if ((err = grib_set_long_internal(h, minute_of_end_of_interval_, minute_of_end_of_interval))) return err; - if ((err = grib_set_long_internal(h, self->second_of_end_of_interval_, second_of_end_of_interval))) + if ((err = grib_set_long_internal(h, second_of_end_of_interval_, second_of_end_of_interval))) return err; const char* forecast_time_value_key = "forecastTime"; @@ -538,13 +532,13 @@ static int pack_long_(grib_accessor* a, const long end_step_value, const long en time_range_opt = eccodes::Step{ time_range.value(eccodes::Unit{ force_step_units }), eccodes::Unit{ force_step_units } }; } - if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->time_range_value_, time_range_opt.value())) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(grib_handle_of_accessor(this), time_range_value_, time_range_opt.value())) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->time_range_unit_, time_range_opt.unit().value())) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(grib_handle_of_accessor(this), time_range_unit_, time_range_opt.unit().value())) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(grib_handle_of_accessor(a), forecast_time_value_key, forecast_time_opt.value())) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(grib_handle_of_accessor(this), forecast_time_value_key, forecast_time_opt.value())) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(grib_handle_of_accessor(a), forecast_time_unit_key, forecast_time_opt.unit().value())) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(grib_handle_of_accessor(this), forecast_time_unit_key, forecast_time_opt.unit().value())) != GRIB_SUCCESS) return err; return GRIB_SUCCESS; @@ -614,7 +608,7 @@ int grib_accessor_g2end_step_t::pack_long(const long* val, size_t* len) else { end_step_unit = force_step_units; } - ret = pack_long_(this, *val, end_step_unit); + ret = pack_long_(*val, end_step_unit); } catch (std::exception& e) { grib_context_log(h->context, GRIB_LOG_ERROR, "grib_accessor_g2end_step_t::pack_long: %s", e.what()); @@ -638,7 +632,7 @@ int grib_accessor_g2end_step_t::pack_string(const char* val, size_t* len) if ((ret = grib_set_long_internal(h, "endStepUnit", end_step.unit().value())) != GRIB_SUCCESS) return ret; - if ((ret = pack_long_(this, end_step.value(), end_step.unit().value())) != GRIB_SUCCESS) + if ((ret = pack_long_(end_step.value(), end_step.unit().value())) != GRIB_SUCCESS) return ret; } catch (std::exception& e) { diff --git a/src/accessor/grib_accessor_class_g2end_step.h b/src/accessor/grib_accessor_class_g2end_step.h index 9bd3461d4..d66a01d5e 100644 --- a/src/accessor/grib_accessor_class_g2end_step.h +++ b/src/accessor/grib_accessor_class_g2end_step.h @@ -28,7 +28,7 @@ public: void dump(grib_dumper*) override; void init(const long, grib_arguments*) override; -public: +private: const char* start_step_value_; const char* step_units_; const char* year_; @@ -47,4 +47,10 @@ public: const char* time_range_value_; const char* typeOfTimeIncrement_; const char* numberOfTimeRanges_; + + int unpack_one_time_range_long_(long* val, size_t* len); + int unpack_one_time_range_double_(double* val, size_t* len); + int unpack_multiple_time_ranges_long_(long* val, size_t* len); + int unpack_multiple_time_ranges_double_(double* val, size_t* len); + int pack_long_(const long end_step_value, const long end_step_unit); }; diff --git a/src/accessor/grib_accessor_class_gen.h b/src/accessor/grib_accessor_class_gen.h index 407841dd2..e4aed165f 100644 --- a/src/accessor/grib_accessor_class_gen.h +++ b/src/accessor/grib_accessor_class_gen.h @@ -69,10 +69,6 @@ public: grib_accessor* make_clone(grib_section*, int*) override; grib_accessor* next_accessor() override; // TODO: Implement - - template - int unpack_helper(grib_accessor* a, T* v, size_t* len); - private: enum { @@ -86,6 +82,9 @@ private: UNPACK_STRING, }; std::bitset<8> is_overridden_ = 0b11111111; + + template + int unpack_helper(grib_accessor* a, T* v, size_t* len); }; diff --git a/src/accessor/grib_accessor_class_getenv.h b/src/accessor/grib_accessor_class_getenv.h index f8168fa50..089ed328a 100644 --- a/src/accessor/grib_accessor_class_getenv.h +++ b/src/accessor/grib_accessor_class_getenv.h @@ -25,7 +25,6 @@ public: void init(const long, grib_arguments*) override; private: - // TODO(maee): shadows name_? const char* envvar_; char* value_; const char* default_value_; diff --git a/src/accessor/grib_accessor_class_hash_array.cc b/src/accessor/grib_accessor_class_hash_array.cc index 789102ad9..b82d0cf79 100644 --- a/src/accessor/grib_accessor_class_hash_array.cc +++ b/src/accessor/grib_accessor_class_hash_array.cc @@ -64,16 +64,15 @@ int grib_accessor_hash_array_t::unpack_double(double* val, size_t* len) return GRIB_NOT_IMPLEMENTED; } -static grib_hash_array_value* find_hash_value(grib_accessor* a, int* err) +grib_hash_array_value* grib_accessor_hash_array_t::find_hash_value(int* err) { - grib_accessor_hash_array_t* self = (grib_accessor_hash_array_t*)a; grib_hash_array_value* ha_ret = 0; grib_hash_array_value* ha = NULL; - ha = get_hash_array(grib_handle_of_accessor(a), self->creator_); + ha = get_hash_array(grib_handle_of_accessor(this), creator_); if (!ha) { - grib_context_log(a->context_, GRIB_LOG_ERROR, - "unable to get hash value for %s", self->creator_->name); + grib_context_log(context_, GRIB_LOG_ERROR, + "unable to get hash value for %s", creator_->name); *err = GRIB_HASH_ARRAY_NO_MATCH; return NULL; } @@ -81,27 +80,27 @@ static grib_hash_array_value* find_hash_value(grib_accessor* a, int* err) *err = GRIB_SUCCESS; Assert(ha != NULL); - if (!self->key_) { - grib_context_log(a->context_, GRIB_LOG_ERROR, - "unable to get hash value for %s, set before getting", self->creator_->name); + if (!key_) { + grib_context_log(context_, GRIB_LOG_ERROR, + "unable to get hash value for %s, set before getting", creator_->name); *err = GRIB_HASH_ARRAY_NO_MATCH; return NULL; } - ha_ret = (grib_hash_array_value*)grib_trie_get(ha->index, self->key_); + ha_ret = (grib_hash_array_value*)grib_trie_get(ha->index, key_); if (!ha_ret) ha_ret = (grib_hash_array_value*)grib_trie_get(ha->index, "default"); if (!ha_ret) { *err = GRIB_HASH_ARRAY_NO_MATCH; - grib_context_log(a->context_, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "hash_array: no match for %s=%s", - self->creator_->name, self->key_); - const char* full_path = get_hash_array_full_path(self->creator_); + creator_->name, key_); + const char* full_path = get_hash_array_full_path(creator_); if (full_path) { - grib_context_log(a->context_, GRIB_LOG_ERROR, "hash_array: file path = %s", full_path); + grib_context_log(context_, GRIB_LOG_ERROR, "hash_array: file path = %s", full_path); } - grib_context_log(a->context_, GRIB_LOG_ERROR, "Hint: Check the key 'masterTablesVersionNumber'"); + grib_context_log(context_, GRIB_LOG_ERROR, "Hint: Check the key 'masterTablesVersionNumber'"); return NULL; } return ha_ret; @@ -114,7 +113,7 @@ int grib_accessor_hash_array_t::unpack_long(long* val, size_t* len) size_t i = 0; if (!ha_) { - ha = find_hash_value(this, &err); + ha = find_hash_value(&err); if (err) return err; ha_ = ha; @@ -169,7 +168,7 @@ int grib_accessor_hash_array_t::value_count(long* count) grib_hash_array_value* ha = 0; if (!ha_) { - ha = find_hash_value(this, &err); + ha = find_hash_value(&err); if (err) return err; ha_ = ha; diff --git a/src/accessor/grib_accessor_class_hash_array.h b/src/accessor/grib_accessor_class_hash_array.h index 7819dbc8b..9dabd2db8 100644 --- a/src/accessor/grib_accessor_class_hash_array.h +++ b/src/accessor/grib_accessor_class_hash_array.h @@ -33,7 +33,9 @@ public: void init(const long, grib_arguments*) override; int compare(grib_accessor*) override; -public: +private: char* key_; grib_hash_array_value* ha_; + + grib_hash_array_value* find_hash_value(int* err); }; diff --git a/src/accessor/grib_accessor_class_iterator.h b/src/accessor/grib_accessor_class_iterator.h index dba32e6e5..13aadfcd9 100644 --- a/src/accessor/grib_accessor_class_iterator.h +++ b/src/accessor/grib_accessor_class_iterator.h @@ -21,8 +21,10 @@ public: void init(const long l, grib_arguments* args) override; void dump(grib_dumper* dumper) override; -public: +private: grib_arguments* args_; + + friend grib_iterator* grib_iterator_new(const grib_handle* ch, unsigned long flags, int* error); }; // grib_iterator* grib_iterator_new(const grib_handle* ch, unsigned long flags, int* error) diff --git a/src/accessor/grib_accessor_class_md5.cc b/src/accessor/grib_accessor_class_md5.cc index ffc92d497..345b28184 100644 --- a/src/accessor/grib_accessor_class_md5.cc +++ b/src/accessor/grib_accessor_class_md5.cc @@ -41,7 +41,7 @@ void grib_accessor_md5_t::init(const long len, grib_arguments* arg) } } } - // TODO(maee): Is this necessary? + grib_accessor::length_ = 0; flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; flags_ |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; diff --git a/src/accessor/grib_accessor_class_nearest.h b/src/accessor/grib_accessor_class_nearest.h index 3d6280743..0781f9132 100644 --- a/src/accessor/grib_accessor_class_nearest.h +++ b/src/accessor/grib_accessor_class_nearest.h @@ -21,8 +21,10 @@ public: void init(const long l, grib_arguments* args) override; void dump(grib_dumper* dumper) override; -public: +private: grib_arguments* args_; + + friend grib_nearest* grib_nearest_new(const grib_handle* ch, int* error); }; // grib_nearest* grib_nearest_new(const grib_handle* ch, int* error); diff --git a/src/accessor/grib_accessor_class_number_of_points_gaussian.cc b/src/accessor/grib_accessor_class_number_of_points_gaussian.cc index a62d8bf30..2876eda3d 100644 --- a/src/accessor/grib_accessor_class_number_of_points_gaussian.cc +++ b/src/accessor/grib_accessor_class_number_of_points_gaussian.cc @@ -122,15 +122,14 @@ int grib_accessor_number_of_points_gaussian_t::unpack_long(long* val, size_t* le return err; if (support_legacy == 1) - return unpack_long_with_legacy_support(this, val, len); + return unpack_long_with_legacy_support(val, len); else - return unpack_long_new(this, val, len); + return unpack_long_new(val, len); } /* New algorithm */ -static int unpack_long_new(grib_accessor* a, long* val, size_t* len) +int grib_accessor_number_of_points_gaussian_t::unpack_long_new(long* val, size_t* len) { - grib_accessor_number_of_points_gaussian_t* self = (grib_accessor_number_of_points_gaussian_t*)a; int err = GRIB_SUCCESS; int is_global = 0; long ni = 0, nj = 0, plpresent = 0, order = 0; @@ -142,17 +141,17 @@ static int unpack_long_new(grib_accessor* a, long* val, size_t* len) long ilon_first = 0, ilon_last = 0; double angular_precision = 1.0 / 1000000.0; long angleSubdivisions = 0; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); - grib_context* c = a->context_; + grib_context* c = context_; - if ((err = grib_get_long_internal(h, self->ni_, &ni)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, ni_, &ni)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(h, self->nj_, &nj)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, nj_, &nj)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(h, self->plpresent_, &plpresent)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, plpresent_, &plpresent)) != GRIB_SUCCESS) return err; if (nj == 0) @@ -169,23 +168,23 @@ static int unpack_long_new(grib_accessor* a, long* val, size_t* len) // double lon_first_row = 0, lon_last_row = 0; /*reduced*/ - if ((err = grib_get_long_internal(h, self->order_, &order)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, order_, &order)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(h, self->lat_first_, &lat_first)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(h, lat_first_, &lat_first)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(h, self->lon_first_, &lon_first)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(h, lon_first_, &lon_first)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(h, self->lat_last_, &lat_last)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(h, lat_last_, &lat_last)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(h, self->lon_last_, &lon_last)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(h, lon_last_, &lon_last)) != GRIB_SUCCESS) return err; - if ((err = grib_get_size(h, self->pl_, &plsize)) != GRIB_SUCCESS) + if ((err = grib_get_size(h, pl_, &plsize)) != GRIB_SUCCESS) return err; pl = (long*)grib_context_malloc_clear(c, sizeof(long) * plsize); plsave = pl; - grib_get_long_array_internal(h, self->pl_, pl, &plsize); + grib_get_long_array_internal(h, pl_, pl, &plsize); if (lon_last < 0) lon_last += 360; @@ -237,9 +236,8 @@ static int unpack_long_new(grib_accessor* a, long* val, size_t* len) } /* With Legacy support */ -static int unpack_long_with_legacy_support(grib_accessor* a, long* val, size_t* len) +int grib_accessor_number_of_points_gaussian_t::unpack_long_with_legacy_support(long* val, size_t* len) { - grib_accessor_number_of_points_gaussian_t* self = (grib_accessor_number_of_points_gaussian_t*)a; int err = GRIB_SUCCESS; int is_global = 0; long ni = 0, nj = 0, plpresent = 0, order = 0; @@ -251,18 +249,18 @@ static int unpack_long_with_legacy_support(grib_accessor* a, long* val, size_t* long ilon_first = 0, ilon_last = 0; double angular_precision = 1.0 / 1000000.0; long angleSubdivisions = 0; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); size_t numDataValues = 0; - grib_context* c = a->context_; + grib_context* c = context_; - if ((err = grib_get_long_internal(h, self->ni_, &ni)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, ni_, &ni)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(h, self->nj_, &nj)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, nj_, &nj)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(h, self->plpresent_, &plpresent)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, plpresent_, &plpresent)) != GRIB_SUCCESS) return err; if (nj == 0) @@ -279,23 +277,23 @@ static int unpack_long_with_legacy_support(grib_accessor* a, long* val, size_t* // double lon_first_row = 0, lon_last_row = 0; /*reduced*/ - if ((err = grib_get_long_internal(h, self->order_, &order)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, order_, &order)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(h, self->lat_first_, &lat_first)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(h, lat_first_, &lat_first)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(h, self->lon_first_, &lon_first)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(h, lon_first_, &lon_first)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(h, self->lat_last_, &lat_last)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(h, lat_last_, &lat_last)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(h, self->lon_last_, &lon_last)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(h, lon_last_, &lon_last)) != GRIB_SUCCESS) return err; - if ((err = grib_get_size(h, self->pl_, &plsize)) != GRIB_SUCCESS) + if ((err = grib_get_size(h, pl_, &plsize)) != GRIB_SUCCESS) return err; pl = (long*)grib_context_malloc_clear(c, sizeof(long) * plsize); plsave = pl; - grib_get_long_array_internal(h, self->pl_, pl, &plsize); + grib_get_long_array_internal(h, pl_, pl, &plsize); if (lon_last < 0) lon_last += 360; diff --git a/src/accessor/grib_accessor_class_number_of_points_gaussian.h b/src/accessor/grib_accessor_class_number_of_points_gaussian.h index 6b47f7a0e..530f1ad27 100644 --- a/src/accessor/grib_accessor_class_number_of_points_gaussian.h +++ b/src/accessor/grib_accessor_class_number_of_points_gaussian.h @@ -22,7 +22,7 @@ public: int unpack_long(long* val, size_t* len) override; void init(const long, grib_arguments*) override; -public: +private: const char* ni_; const char* nj_; const char* plpresent_; @@ -33,4 +33,7 @@ public: const char* lat_last_; const char* lon_last_; const char* support_legacy_; + + int unpack_long_new(long* val, size_t* len); + int unpack_long_with_legacy_support(long* val, size_t* len); }; diff --git a/src/accessor/grib_accessor_class_section.cc b/src/accessor/grib_accessor_class_section.cc index 7835eefce..27544d0a2 100644 --- a/src/accessor/grib_accessor_class_section.cc +++ b/src/accessor/grib_accessor_class_section.cc @@ -96,7 +96,6 @@ grib_accessor* grib_accessor_section_t::next(grib_accessor* a, int explore) } if (!next) { if (a->parent_->owner) - // TODO(maee): check the owner of the parent next = a->parent_->owner->next(a->parent_->owner, 0); } return next; diff --git a/src/accessor/grib_accessor_class_signed_bits.cc b/src/accessor/grib_accessor_class_signed_bits.cc index 2c2587338..af75c55cf 100644 --- a/src/accessor/grib_accessor_class_signed_bits.cc +++ b/src/accessor/grib_accessor_class_signed_bits.cc @@ -18,24 +18,23 @@ long grib_accessor_signed_bits_t::byte_count() return length_; } -static long compute_byte_count(grib_accessor* a) +long grib_accessor_signed_bits_t::compute_byte_count() { - grib_accessor_signed_bits_t* self = (grib_accessor_signed_bits_t*)a; long numberOfBits; long numberOfElements; int ret = 0; - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits_, &numberOfBits); + ret = grib_get_long(grib_handle_of_accessor(this), numberOfBits_, &numberOfBits); if (ret) { - grib_context_log(a->context_, GRIB_LOG_ERROR, - "%s unable to get %s to compute size", a->name_, self->numberOfBits_); + grib_context_log(context_, GRIB_LOG_ERROR, + "%s unable to get %s to compute size", name_, numberOfBits_); return 0; } - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfElements_, &numberOfElements); + ret = grib_get_long(grib_handle_of_accessor(this), numberOfElements_, &numberOfElements); if (ret) { - grib_context_log(a->context_, GRIB_LOG_ERROR, - "%s unable to get %s to compute size", a->name_, self->numberOfElements_); + grib_context_log(context_, GRIB_LOG_ERROR, + "%s unable to get %s to compute size", name_, numberOfElements_); return 0; } @@ -48,7 +47,7 @@ void grib_accessor_signed_bits_t::init(const long len, grib_arguments* args) int n = 0; numberOfBits_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); numberOfElements_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); - length_ = compute_byte_count(this); + length_ = compute_byte_count(); } int grib_accessor_signed_bits_t::unpack_long(long* val, size_t* len) diff --git a/src/accessor/grib_accessor_class_signed_bits.h b/src/accessor/grib_accessor_class_signed_bits.h index 9d37550f4..e257343e7 100644 --- a/src/accessor/grib_accessor_class_signed_bits.h +++ b/src/accessor/grib_accessor_class_signed_bits.h @@ -28,7 +28,9 @@ public: void init(const long, grib_arguments*) override; void update_size(size_t) override; -public: +private: const char* numberOfBits_; const char* numberOfElements_; + + long compute_byte_count(); }; diff --git a/src/accessor/grib_accessor_class_smart_table.cc b/src/accessor/grib_accessor_class_smart_table.cc index f628fba79..d0e629b19 100644 --- a/src/accessor/grib_accessor_class_smart_table.cc +++ b/src/accessor/grib_accessor_class_smart_table.cc @@ -65,11 +65,10 @@ void grib_accessor_smart_table_t::init(const long len, grib_arguments* params) table_ = NULL; } -grib_smart_table* load_table(grib_accessor* a) +grib_smart_table* grib_accessor_smart_table_t::load_table() { - grib_accessor_smart_table_t* self = (grib_accessor_smart_table_t*)a; size_t size = 0; - grib_handle* h = ((grib_accessor*)self)->parent_->h; + grib_handle* h = this->parent_->h; grib_context* c = h->context; grib_smart_table* t = NULL; grib_smart_table* next = NULL; @@ -96,30 +95,30 @@ grib_smart_table* load_table(grib_accessor* a) }; size_t len = 1024; - if (self->masterDir_ != NULL) { - grib_get_string(h, self->masterDir_, masterDir, &len); + if (masterDir_ != NULL) { + grib_get_string(h, masterDir_, masterDir, &len); } len = 1024; - if (self->localDir_ != NULL) { - grib_get_string(h, self->localDir_, localDir, &len); + if (localDir_ != NULL) { + grib_get_string(h, localDir_, localDir, &len); } len = 1024; - if (self->extraDir_ != NULL && self->extraTable_ != NULL) { - grib_get_string(h, self->extraDir_, extraDir, &len); + if (extraDir_ != NULL && extraTable_ != NULL) { + grib_get_string(h, extraDir_, extraDir, &len); } if (*masterDir != 0) { char name[2048] = { 0, }; - snprintf(name, sizeof(name), "%s/%s", masterDir, self->tablename_); + snprintf(name, sizeof(name), "%s/%s", masterDir, tablename_); grib_recompose_name(h, NULL, name, recomposed, 0); filename = grib_context_full_defs_path(c, recomposed); } else { - grib_recompose_name(h, NULL, self->tablename_, recomposed, 0); + grib_recompose_name(h, NULL, tablename_, recomposed, 0); filename = grib_context_full_defs_path(c, recomposed); } @@ -127,7 +126,7 @@ grib_smart_table* load_table(grib_accessor* a) char localName[2048] = { 0, }; - snprintf(localName, sizeof(localName), "%s/%s", localDir, self->tablename_); + snprintf(localName, sizeof(localName), "%s/%s", localDir, tablename_); grib_recompose_name(h, NULL, localName, localRecomposed, 0); localFilename = grib_context_full_defs_path(c, localRecomposed); } @@ -136,7 +135,7 @@ grib_smart_table* load_table(grib_accessor* a) char extraTable[2048] = { 0, }; - snprintf(extraTable, sizeof(extraTable), "%s/%s", extraDir, self->extraTable_); + snprintf(extraTable, sizeof(extraTable), "%s/%s", extraDir, extraTable_); grib_recompose_name(h, NULL, extraTable, extraRecomposed, 0); extraFilename = grib_context_full_defs_path(c, extraRecomposed); } @@ -155,7 +154,7 @@ grib_smart_table* load_table(grib_accessor* a) // Note: widthOfCode_ is chosen so that 2^width is bigger than the maximum descriptor code, // which for BUFR4 is the Table C operator 243255 // - size = (1ULL << self->widthOfCode_); // = 2^widthOfCode_ (as a 64 bit number) + size = (1ULL << widthOfCode_); // = 2^widthOfCode_ (as a 64 bit number) t = (grib_smart_table*)grib_context_malloc_clear_persistent(c, sizeof(grib_smart_table)); t->entries = (grib_smart_table_entry*)grib_context_malloc_clear_persistent(c, size * sizeof(grib_smart_table_entry)); @@ -317,7 +316,7 @@ int grib_accessor_smart_table_t::unpack_string(char* buffer, size_t* len) return err; if (!table_) - table_ = load_table(this); + table_ = load_table(); table = table_; if (table && (value >= 0) && (value < table->numberOfEntries) && table->entries[value].abbreviation) { @@ -341,9 +340,8 @@ int grib_accessor_smart_table_t::unpack_string(char* buffer, size_t* len) return GRIB_SUCCESS; } -static int get_table_codes(grib_accessor* a) +int grib_accessor_smart_table_t::get_table_codes() { - grib_accessor_smart_table_t* self = (grib_accessor_smart_table_t*)a; size_t size = 0; long* v = 0; int err = 0; @@ -352,43 +350,43 @@ static int get_table_codes(grib_accessor* a) int table_size; - if (!a->dirty_) + if (!dirty_) return 0; - table_size = (1 << self->widthOfCode_); // 2 ^ widthOfCode_ + table_size = (1 << widthOfCode_); // 2 ^ widthOfCode_ - if (!self->table_) - self->table_ = load_table(a); + if (!table_) + table_ = load_table(); - err = grib_get_size(grib_handle_of_accessor(a), self->values_, &size); + err = grib_get_size(grib_handle_of_accessor(this), values_, &size); if (err) { - grib_context_log(a->context_, GRIB_LOG_ERROR, - "unable to get size of %s", a->name_); + grib_context_log(context_, GRIB_LOG_ERROR, + "unable to get size of %s", name_); return err; } - v = (long*)grib_context_malloc_clear(a->context_, size * sizeof(long)); + v = (long*)grib_context_malloc_clear(context_, size * sizeof(long)); - grib_get_long_array(grib_handle_of_accessor(a), self->values_, v, &size); + grib_get_long_array(grib_handle_of_accessor(this), values_, v, &size); count = 0; for (i = 0; i < size; i++) { if (v[i] < table_size) count++; } - if (self->tableCodes_) - grib_context_free(a->context_, self->tableCodes_); - self->tableCodes_ = (long*)grib_context_malloc_clear(a->context_, count * sizeof(long)); + if (tableCodes_) + grib_context_free(context_, tableCodes_); + tableCodes_ = (long*)grib_context_malloc_clear(context_, count * sizeof(long)); j = 0; for (i = 0; i < size; i++) { if (v[i] < table_size) - self->tableCodes_[j++] = v[i]; + tableCodes_[j++] = v[i]; } - grib_context_free(a->context_, v); + grib_context_free(context_, v); - self->tableCodesSize_ = count; - a->dirty_ = 0; + tableCodesSize_ = count; + dirty_ = 0; return 0; } @@ -400,7 +398,7 @@ int grib_accessor_smart_table_t::value_count(long* count) if (!values_) return 0; - err = get_table_codes(this); + err = get_table_codes(); if (err) return err; @@ -438,7 +436,7 @@ int grib_accessor_smart_table_t::unpack_long(long* val, size_t* len) if (!values_) return 0; - err = get_table_codes(this); + err = get_table_codes(); if (err) return 0; diff --git a/src/accessor/grib_accessor_class_smart_table.h b/src/accessor/grib_accessor_class_smart_table.h index 28664b1e5..ebc77c87c 100644 --- a/src/accessor/grib_accessor_class_smart_table.h +++ b/src/accessor/grib_accessor_class_smart_table.h @@ -27,7 +27,10 @@ public: void dump(grib_dumper*) override; void init(const long, grib_arguments*) override; -public: + grib_smart_table* table() const { return table_; } + +private: + grib_smart_table* table_; const char* values_; const char* tablename_; const char* masterDir_; @@ -37,7 +40,7 @@ public: int widthOfCode_; long* tableCodes_; size_t tableCodesSize_; - grib_smart_table* table_; - // TODO(maee): dirty_ shadowed by the derived class - // int dirty_; + + grib_smart_table* load_table(); + int get_table_codes(); }; diff --git a/src/accessor/grib_accessor_class_smart_table_column.cc b/src/accessor/grib_accessor_class_smart_table_column.cc index 9602f9ea0..7cdc1193d 100644 --- a/src/accessor/grib_accessor_class_smart_table_column.cc +++ b/src/accessor/grib_accessor_class_smart_table_column.cc @@ -77,7 +77,7 @@ int grib_accessor_smart_table_column_t::unpack_string_array(char** buffer, size_ if ((err = ((grib_accessor*)tableAccessor)->unpack_long(code, &size)) != GRIB_SUCCESS) return err; - table = tableAccessor->table_; + table = tableAccessor->table(); for (i = 0; i < size; i++) { if (table && (code[i] >= 0) && @@ -132,7 +132,7 @@ int grib_accessor_smart_table_column_t::unpack_long(long* val, size_t* len) return err; } - table = tableAccessor->table_; + table = tableAccessor->table(); for (i = 0; i < size; i++) { if (table && (code[i] >= 0) && diff --git a/src/accessor/grib_accessor_class_spd.cc b/src/accessor/grib_accessor_class_spd.cc index ae746cc7f..8d0df9bad 100644 --- a/src/accessor/grib_accessor_class_spd.cc +++ b/src/accessor/grib_accessor_class_spd.cc @@ -18,23 +18,22 @@ long grib_accessor_spd_t::byte_count() return length_; } -static long compute_byte_count(grib_accessor* a) +long grib_accessor_spd_t::compute_byte_count() { - grib_accessor_spd_t* self = (grib_accessor_spd_t*)a; long numberOfBits = 0; long numberOfElements = 0; - int ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits_, &numberOfBits); + int ret = grib_get_long(grib_handle_of_accessor(this), numberOfBits_, &numberOfBits); if (ret) { - grib_context_log(a->context_, GRIB_LOG_ERROR, - "%s unable to get %s to compute size", a->name_, self->numberOfBits_); + grib_context_log(context_, GRIB_LOG_ERROR, + "%s unable to get %s to compute size", name_, numberOfBits_); return 0; } - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfElements_, &numberOfElements); + ret = grib_get_long(grib_handle_of_accessor(this), numberOfElements_, &numberOfElements); if (ret) { - grib_context_log(a->context_, GRIB_LOG_ERROR, - "%s unable to get %s to compute size", a->name_, self->numberOfElements_); + grib_context_log(context_, GRIB_LOG_ERROR, + "%s unable to get %s to compute size", name_, numberOfElements_); return 0; } numberOfElements++; @@ -48,7 +47,7 @@ void grib_accessor_spd_t::init(const long len, grib_arguments* args) int n = 0; numberOfBits_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); numberOfElements_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); - length_ = compute_byte_count(this); + length_ = compute_byte_count(); } int grib_accessor_spd_t::unpack_long(long* val, size_t* len) @@ -109,7 +108,7 @@ int grib_accessor_spd_t::pack_long(const long* val, size_t* len) if (ret) return ret; - buflen = compute_byte_count(this); + buflen = compute_byte_count(); buf = (unsigned char*)grib_context_malloc_clear(context_, buflen); for (i = 0; i < rlen - 1; i++) { diff --git a/src/accessor/grib_accessor_class_spd.h b/src/accessor/grib_accessor_class_spd.h index 06114dc09..9c9ecd070 100644 --- a/src/accessor/grib_accessor_class_spd.h +++ b/src/accessor/grib_accessor_class_spd.h @@ -28,7 +28,9 @@ public: void init(const long, grib_arguments*) override; void update_size(size_t) override; -public: +private: const char* numberOfBits_; const char* numberOfElements_; + + long compute_byte_count(); }; diff --git a/src/accessor/grib_accessor_class_step_in_units.cc b/src/accessor/grib_accessor_class_step_in_units.cc index 651e4dfa1..d63a13c76 100644 --- a/src/accessor/grib_accessor_class_step_in_units.cc +++ b/src/accessor/grib_accessor_class_step_in_units.cc @@ -92,19 +92,18 @@ int grib_accessor_step_in_units_t::unpack_double(double* val, size_t* len) return GRIB_SUCCESS; } -static int pack_long_new_(grib_accessor* a, const long start_step_value, const long start_step_unit, const long force_step_units) +int grib_accessor_step_in_units_t::pack_long_new_(const long start_step_value, const long start_step_unit, const long force_step_units) { - const grib_accessor_step_in_units_t* self = (grib_accessor_step_in_units_t*)a; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); int err = 0; long forecast_time_unit; long start_step_value_old; long start_step_unit_old; size_t len = 0; - if ((err = grib_get_long_internal(h, self->forecast_time_unit_, &forecast_time_unit)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, forecast_time_unit_, &forecast_time_unit)) != GRIB_SUCCESS) return err; - if ((err = a->unpack_long(&start_step_value_old, &len)) != GRIB_SUCCESS) + if ((err = unpack_long(&start_step_value_old, &len)) != GRIB_SUCCESS) return err; if ((err = grib_get_long_internal(h, "startStepUnit", &start_step_unit_old)) != GRIB_SUCCESS) return err; @@ -113,7 +112,7 @@ static int pack_long_new_(grib_accessor* a, const long start_step_value, const l eccodes::Step forecast_time(start_step_value, start_step_unit); eccodes::Step time_range_new{}; - auto time_range_opt = get_step(h, self->time_range_value_, self->time_range_unit_); + auto time_range_opt = get_step(h, time_range_value_, time_range_unit_); if (time_range_opt) { auto time_range = time_range_opt.value(); @@ -121,11 +120,11 @@ static int pack_long_new_(grib_accessor* a, const long start_step_value, const l if (time_range.value() < 0) time_range = eccodes::Step{ 0l, time_range.unit() }; auto [sa, sb] = find_common_units(forecast_time.optimize_unit(), time_range.optimize_unit()); - if ((err = set_step(h, self->forecast_time_value_, self->forecast_time_unit_, sa)) != GRIB_SUCCESS) + if ((err = set_step(h, forecast_time_value_, forecast_time_unit_, sa)) != GRIB_SUCCESS) return err; if ((err = grib_set_long_internal(h, "startStepUnit", forecast_time.unit().value())) != GRIB_SUCCESS) return err; - if ((err = set_step(h, self->time_range_value_, self->time_range_unit_, sb)) != GRIB_SUCCESS) + if ((err = set_step(h, time_range_value_, time_range_unit_, sb)) != GRIB_SUCCESS) return err; return GRIB_SUCCESS; } @@ -136,7 +135,7 @@ static int pack_long_new_(grib_accessor* a, const long start_step_value, const l if ((err = grib_set_long_internal(h, "startStepUnit", forecast_time.unit().value())) != GRIB_SUCCESS) return err; - if ((err = set_step(h, self->forecast_time_value_, self->forecast_time_unit_, forecast_time)) != GRIB_SUCCESS) + if ((err = set_step(h, forecast_time_value_, forecast_time_unit_, forecast_time)) != GRIB_SUCCESS) return err; return GRIB_SUCCESS; @@ -169,7 +168,7 @@ int grib_accessor_step_in_units_t::pack_long(const long* val, size_t* len) return GRIB_DECODING_ERROR; } - ret = pack_long_new_(this, *val, start_step_unit, force_step_units); + ret = pack_long_new_(*val, start_step_unit, force_step_units); return ret; } @@ -185,7 +184,7 @@ int grib_accessor_step_in_units_t::pack_string(const char* val, size_t* len) try { eccodes::Step step = step_from_string(val, eccodes::Unit{ force_step_units }); - if ((ret = pack_long_new_(this, step.value(), step.unit().value(), force_step_units)) != GRIB_SUCCESS) + if ((ret = pack_long_new_(step.value(), step.unit().value(), force_step_units)) != GRIB_SUCCESS) return ret; } catch (std::exception& e) { diff --git a/src/accessor/grib_accessor_class_step_in_units.h b/src/accessor/grib_accessor_class_step_in_units.h index 74c71a0af..49c3403e0 100644 --- a/src/accessor/grib_accessor_class_step_in_units.h +++ b/src/accessor/grib_accessor_class_step_in_units.h @@ -28,10 +28,12 @@ public: void dump(grib_dumper*) override; void init(const long, grib_arguments*) override; -public: +private: const char* forecast_time_value_; const char* forecast_time_unit_; const char* step_units_; const char* time_range_unit_; const char* time_range_value_; + + int pack_long_new_(const long start_step_value, const long start_step_unit, const long force_step_units); }; diff --git a/src/accessor/grib_accessor_class_suppressed.cc b/src/accessor/grib_accessor_class_suppressed.cc index 29a78cc1b..f0de3960f 100644 --- a/src/accessor/grib_accessor_class_suppressed.cc +++ b/src/accessor/grib_accessor_class_suppressed.cc @@ -22,38 +22,37 @@ void grib_accessor_suppressed_t::init(const long l, grib_arguments* c) length_ = 0; } -static void log_message(grib_accessor* a) +void grib_accessor_suppressed_t::log_message() { - grib_accessor_suppressed_t* self = (grib_accessor_suppressed_t*)a; int i = 0; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); - grib_context_log(a->context_, GRIB_LOG_ERROR, - "key '%s' is unavailable in this version.", a->name_); - grib_context_log(a->context_, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, + "key '%s' is unavailable in this version.", name_); + grib_context_log(context_, GRIB_LOG_ERROR, "Please use the following key(s):"); - while (grib_arguments_get_name(hand, self->args_, i)) { - grib_context_log(a->context_, GRIB_LOG_ERROR, "\t- %s", - grib_arguments_get_name(hand, self->args_, i)); + while (grib_arguments_get_name(hand, args_, i)) { + grib_context_log(context_, GRIB_LOG_ERROR, "\t- %s", + grib_arguments_get_name(hand, args_, i)); i++; } } int grib_accessor_suppressed_t::unpack_string(char* val, size_t* len) { - log_message(this); + log_message(); return GRIB_NOT_FOUND; } int grib_accessor_suppressed_t::unpack_long(long* val, size_t* len) { - log_message(this); + log_message(); return GRIB_NOT_FOUND; } int grib_accessor_suppressed_t::unpack_double(double* val, size_t* len) { - log_message(this); + log_message(); return GRIB_NOT_FOUND; } diff --git a/src/accessor/grib_accessor_class_suppressed.h b/src/accessor/grib_accessor_class_suppressed.h index 9c4f0a243..2fce6dc51 100644 --- a/src/accessor/grib_accessor_class_suppressed.h +++ b/src/accessor/grib_accessor_class_suppressed.h @@ -26,6 +26,8 @@ public: int value_count(long*) override; void init(const long, grib_arguments*) override; -public: +private: grib_arguments* args_; + + void log_message(); }; diff --git a/src/accessor/grib_accessor_class_to_double.h b/src/accessor/grib_accessor_class_to_double.h index 0c5a99d58..546aa53c7 100644 --- a/src/accessor/grib_accessor_class_to_double.h +++ b/src/accessor/grib_accessor_class_to_double.h @@ -29,9 +29,11 @@ public: void dump(grib_dumper*) override; void init(const long, grib_arguments*) override; -public: +protected: const char* key_; long start_; size_t length_; + +private: long scale_; }; diff --git a/src/accessor/grib_accessor_class_unexpanded_descriptors.cc b/src/accessor/grib_accessor_class_unexpanded_descriptors.cc index 15adc675e..7c4ddd602 100644 --- a/src/accessor/grib_accessor_class_unexpanded_descriptors.cc +++ b/src/accessor/grib_accessor_class_unexpanded_descriptors.cc @@ -70,7 +70,7 @@ int grib_accessor_unexpanded_descriptors_t::pack_long(const long* val, size_t* l long pos = 0; unsigned long f, x, y; unsigned char* buf = NULL; - grib_accessor* expanded = NULL; + grib_accessor_expanded_descriptors_t* expanded = NULL; size_t buflen = *len * 2; size_t i = 0, length = *len; long createNewData = 1; @@ -96,9 +96,9 @@ int grib_accessor_unexpanded_descriptors_t::pack_long(const long* val, size_t* l if (createNewData == 0) return ret; - expanded = grib_find_accessor(hand, "expandedCodes"); + expanded = dynamic_cast(grib_find_accessor(hand, "expandedCodes")); Assert(expanded != NULL); - ret = grib_accessor_expanded_descriptors_set_do_expand(expanded, 1); + ret = expanded->grib_accessor_expanded_descriptors_set_do_expand(1); if (ret != GRIB_SUCCESS) return ret; diff --git a/src/accessor/grib_accessor_class_unpack_bufr_values.cc b/src/accessor/grib_accessor_class_unpack_bufr_values.cc index 0b90ede64..be36e9a2d 100644 --- a/src/accessor/grib_accessor_class_unpack_bufr_values.cc +++ b/src/accessor/grib_accessor_class_unpack_bufr_values.cc @@ -9,7 +9,6 @@ */ #include "grib_accessor_class_unpack_bufr_values.h" -#include "grib_accessor_class_bufr_data_array.h" grib_accessor_unpack_bufr_values_t _grib_accessor_unpack_bufr_values{}; grib_accessor* grib_accessor_unpack_bufr_values = &_grib_accessor_unpack_bufr_values; @@ -19,7 +18,7 @@ void grib_accessor_unpack_bufr_values_t::init(const long len, grib_arguments* pa grib_accessor_gen_t::init(len, params); char* key; key = (char*)grib_arguments_get_name(grib_handle_of_accessor(this), params, 0); - data_accessor_ = grib_find_accessor(grib_handle_of_accessor(this), key); + data_accessor_ = dynamic_cast(grib_find_accessor(grib_handle_of_accessor(this), key)); length_ = 0; } @@ -89,7 +88,7 @@ int grib_accessor_unpack_bufr_values_t::pack_long(const long* val, size_t* len) if (*val == 3) unpackMode = CODES_BUFR_NEW_DATA; - accessor_bufr_data_array_set_unpackMode(data_accessor_, unpackMode); + data_accessor_->accessor_bufr_data_array_set_unpackMode(unpackMode); return data_accessor_->unpack_double(0, 0); } diff --git a/src/accessor/grib_accessor_class_unpack_bufr_values.h b/src/accessor/grib_accessor_class_unpack_bufr_values.h index 2d0425af1..6fc059c8d 100644 --- a/src/accessor/grib_accessor_class_unpack_bufr_values.h +++ b/src/accessor/grib_accessor_class_unpack_bufr_values.h @@ -12,6 +12,7 @@ #pragma once #include "grib_accessor_class_gen.h" +#include "grib_accessor_class_bufr_data_array.h" class grib_accessor_unpack_bufr_values_t : public grib_accessor_gen_t { @@ -32,5 +33,5 @@ public: void init(const long, grib_arguments*) override; private: - grib_accessor* data_accessor_; + grib_accessor_bufr_data_array_t* data_accessor_; }; diff --git a/src/accessor/grib_accessor_class_unsigned.cc b/src/accessor/grib_accessor_class_unsigned.cc index 538504188..95f802150 100644 --- a/src/accessor/grib_accessor_class_unsigned.cc +++ b/src/accessor/grib_accessor_class_unsigned.cc @@ -61,10 +61,8 @@ int value_is_missing(long val) return (val == GRIB_MISSING_LONG || val == all_ones); } -int pack_long_unsigned_helper(grib_accessor* a, const long* val, size_t* len, int check) +int grib_accessor_unsigned_t::pack_long_unsigned_helper(const long* val, size_t* len, int check) { - grib_accessor_unsigned_t* self = (grib_accessor_unsigned_t*)a; - int ret = 0; long off = 0; long rlen = 0; @@ -74,28 +72,28 @@ int pack_long_unsigned_helper(grib_accessor* a, const long* val, size_t* len, in unsigned long i = 0; unsigned long missing = 0; - int err = a->value_count(&rlen); + int err = value_count(&rlen); if (err) return err; - if (a->flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) { - Assert(self->nbytes_ <= 4); - missing = ones[self->nbytes_]; + if (flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) { + Assert(nbytes_ <= 4); + missing = ones[nbytes_]; } - if (self->flags_ & GRIB_ACCESSOR_FLAG_TRANSIENT) { - self->vvalue_->lval = val[0]; + if (flags_ & GRIB_ACCESSOR_FLAG_TRANSIENT) { + vvalue_->lval = val[0]; if (missing && val[0] == GRIB_MISSING_LONG) - self->vvalue_->missing = 1; + vvalue_->missing = 1; else - self->vvalue_->missing = 0; + vvalue_->missing = 0; return GRIB_SUCCESS; } if (*len < 1) { - grib_context_log(a->context_, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values ", a->name_, 1); + grib_context_log(context_, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values ", name_, 1); len[0] = 0; return GRIB_ARRAY_TOO_SMALL; } @@ -110,51 +108,51 @@ int pack_long_unsigned_helper(grib_accessor* a, const long* val, size_t* len, in /* Check if value fits into number of bits */ if (check) { if (val[0] < 0) { - grib_context_log(a->context_, GRIB_LOG_ERROR, - "Key \"%s\": Trying to encode a negative value of %ld for key of type unsigned", a->name_, val[0]); + grib_context_log(context_, GRIB_LOG_ERROR, + "Key \"%s\": Trying to encode a negative value of %ld for key of type unsigned", name_, val[0]); return GRIB_ENCODING_ERROR; } /* See GRIB-23 and GRIB-262 */ if (!value_is_missing(v)) { - const long nbits = self->nbytes_ * 8; + const long nbits = nbytes_ * 8; if (nbits < 33) { unsigned long maxval = (1UL << nbits) - 1; if (maxval > 0 && v > maxval) { /* See ECC-1002 */ - grib_context_log(a->context_, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "Key \"%s\": Trying to encode value of %ld but the maximum allowable value is %lu (number of bits=%ld)", - a->name_, v, maxval, nbits); + name_, v, maxval, nbits); return GRIB_ENCODING_ERROR; } } } } - off = a->offset_ * 8; - ret = grib_encode_unsigned_long(grib_handle_of_accessor(a)->buffer->data, v, &off, self->nbytes_ * 8); + off = offset_ * 8; + ret = grib_encode_unsigned_long(grib_handle_of_accessor(this)->buffer->data, v, &off, nbytes_ * 8); if (ret == GRIB_SUCCESS) len[0] = 1; if (*len > 1) - grib_context_log(a->context_, GRIB_LOG_WARNING, "grib_accessor_unsigned : Trying to pack %d values in a scalar %s, packing first value", *len, a->name_); + grib_context_log(context_, GRIB_LOG_WARNING, "grib_accessor_unsigned : Trying to pack %d values in a scalar %s, packing first value", *len, name_); len[0] = 1; return ret; } /* TODO: We assume that there are no missing values if there are more that 1 value */ - buflen = *len * self->nbytes_; + buflen = *len * nbytes_; - buf = (unsigned char*)grib_context_malloc(a->context_, buflen); + buf = (unsigned char*)grib_context_malloc(context_, buflen); for (i = 0; i < *len; i++) - grib_encode_unsigned_long(buf, val[i], &off, self->nbytes_ * 8); + grib_encode_unsigned_long(buf, val[i], &off, nbytes_ * 8); - ret = grib_set_long_internal(grib_handle_of_accessor(a), grib_arguments_get_name(a->parent_->h, self->arg_, 0), *len); + ret = grib_set_long_internal(grib_handle_of_accessor(this), grib_arguments_get_name(parent_->h, arg_, 0), *len); if (ret == GRIB_SUCCESS) - grib_buffer_replace(a, buf, buflen, 1, 1); + grib_buffer_replace(this, buf, buflen, 1, 1); else *len = 0; - grib_context_free(a->context_, buf); + grib_context_free(context_, buf); return ret; } @@ -204,7 +202,7 @@ int grib_accessor_unsigned_t::unpack_long(long* val, size_t* len) int grib_accessor_unsigned_t::pack_long(const long* val, size_t* len) { /* See GRIB-262 as example of why we do the checks */ - return pack_long_unsigned_helper(this, val, len, /*check=*/1); + return pack_long_unsigned_helper(val, len, /*check=*/1); } long grib_accessor_unsigned_t::byte_count() diff --git a/src/accessor/grib_accessor_class_unsigned.h b/src/accessor/grib_accessor_class_unsigned.h index 9afcbdf56..ef25596b9 100644 --- a/src/accessor/grib_accessor_class_unsigned.h +++ b/src/accessor/grib_accessor_class_unsigned.h @@ -30,8 +30,12 @@ public: int is_missing() override; void destroy(grib_context* context) override; - // TODO(maee): make members private -public: +protected: long nbytes_; + + int pack_long_unsigned_helper(const long* val, size_t* len, int check); + +private: grib_arguments* arg_; + }; diff --git a/src/accessor/grib_accessor_class_unsigned_bits.cc b/src/accessor/grib_accessor_class_unsigned_bits.cc index edaa9bbe1..eeb34614d 100644 --- a/src/accessor/grib_accessor_class_unsigned_bits.cc +++ b/src/accessor/grib_accessor_class_unsigned_bits.cc @@ -13,24 +13,23 @@ grib_accessor_unsigned_bits_t _grib_accessor_unsigned_bits{}; grib_accessor* grib_accessor_unsigned_bits = &_grib_accessor_unsigned_bits; -static long compute_byte_count(grib_accessor* a) +long grib_accessor_unsigned_bits_t::compute_byte_count() { - grib_accessor_unsigned_bits_t* self = (grib_accessor_unsigned_bits_t*)a; long numberOfBits; long numberOfElements; int ret = 0; - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits_, &numberOfBits); + ret = grib_get_long(grib_handle_of_accessor(this), numberOfBits_, &numberOfBits); if (ret) { - grib_context_log(a->context_, GRIB_LOG_ERROR, - "%s unable to get %s to compute size", a->name_, self->numberOfBits_); + grib_context_log(context_, GRIB_LOG_ERROR, + "%s unable to get %s to compute size", name_, numberOfBits_); return 0; } - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfElements_, &numberOfElements); + ret = grib_get_long(grib_handle_of_accessor(this), numberOfElements_, &numberOfElements); if (ret) { - grib_context_log(a->context_, GRIB_LOG_ERROR, - "%s unable to get %s to compute size", a->name_, self->numberOfElements_); + grib_context_log(context_, GRIB_LOG_ERROR, + "%s unable to get %s to compute size", name_, numberOfElements_); return 0; } @@ -43,7 +42,7 @@ void grib_accessor_unsigned_bits_t::init(const long len, grib_arguments* args) int n = 0; numberOfBits_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); numberOfElements_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); - length_ = compute_byte_count(this); + length_ = compute_byte_count(); } int grib_accessor_unsigned_bits_t::unpack_long(long* val, size_t* len) @@ -112,7 +111,7 @@ int grib_accessor_unsigned_bits_t::pack_long(const long* val, size_t* len) return GRIB_SUCCESS; } - buflen = compute_byte_count(this); + buflen = compute_byte_count(); buf = (unsigned char*)grib_context_malloc_clear(context_, buflen + sizeof(long)); for (i = 0; i < *len; i++) diff --git a/src/accessor/grib_accessor_class_unsigned_bits.h b/src/accessor/grib_accessor_class_unsigned_bits.h index 66512187f..a93256da1 100644 --- a/src/accessor/grib_accessor_class_unsigned_bits.h +++ b/src/accessor/grib_accessor_class_unsigned_bits.h @@ -28,7 +28,9 @@ public: void init(const long, grib_arguments*) override; void update_size(size_t) override; -public: +private: const char* numberOfBits_; const char* numberOfElements_; + + long compute_byte_count(); }; diff --git a/src/accessor/grib_accessor_class_values.cc b/src/accessor/grib_accessor_class_values.cc index 489c7a4dd..3b378f82f 100644 --- a/src/accessor/grib_accessor_class_values.cc +++ b/src/accessor/grib_accessor_class_values.cc @@ -13,16 +13,15 @@ grib_accessor_values_t _grib_accessor_values{}; grib_accessor* grib_accessor_values = &_grib_accessor_values; -long init_length(grib_accessor* a) +long grib_accessor_values_t::init_length() { - grib_accessor_values_t* self = (grib_accessor_values_t*)a; int ret = 0; long seclen = 0; long offsetsection = 0; long offsetdata = 0; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->seclen_, &seclen))) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), seclen_, &seclen))) return ret; if (seclen == 0) { @@ -30,16 +29,16 @@ long init_length(grib_accessor* a) return 0; } - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetsection_, &offsetsection))) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), offsetsection_, &offsetsection))) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetdata_, &offsetdata))) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), offsetdata_, &offsetdata))) return ret; /* When reparsing */ if (offsetdata < offsetsection) { /* printf("init_length offsetdata < offsetsection=0\n"); */ - Assert(grib_handle_of_accessor(a)->loader); + Assert(grib_handle_of_accessor(this)->loader); return 0; } @@ -56,7 +55,7 @@ void grib_accessor_values_t::init(const long v, grib_arguments* params) offsetsection_ = grib_arguments_get_name(grib_handle_of_accessor(this), params, carg_++); dirty_ = 1; - length_ = init_length(this); + length_ = init_length(); /* Assert(length_ >=0); */ } diff --git a/src/accessor/grib_accessor_class_values.h b/src/accessor/grib_accessor_class_values.h index b7743205e..256d5a4f2 100644 --- a/src/accessor/grib_accessor_class_values.h +++ b/src/accessor/grib_accessor_class_values.h @@ -28,10 +28,13 @@ public: void update_size(size_t) override; int compare(grib_accessor*) override; -public: +protected: int carg_; const char* seclen_; const char* offsetdata_; const char* offsetsection_; int dirty_; + +private: + long init_length(); }; diff --git a/src/accessor/grib_accessor_class_variable.cc b/src/accessor/grib_accessor_class_variable.cc index 35b6ea0d0..1fbc899d6 100644 --- a/src/accessor/grib_accessor_class_variable.cc +++ b/src/accessor/grib_accessor_class_variable.cc @@ -71,10 +71,9 @@ void grib_accessor_variable_t::init(const long length, grib_arguments* args) } } -void accessor_variable_set_type(grib_accessor* a, int type) +void grib_accessor_variable_t::accessor_variable_set_type(int type) { - grib_accessor_variable_t* self = (grib_accessor_variable_t*)a; - self->type_ = type; + type_ = type; } void grib_accessor_variable_t::dump(grib_dumper* dumper) diff --git a/src/accessor/grib_accessor_class_variable.h b/src/accessor/grib_accessor_class_variable.h index 3051ab58f..29f42cf3a 100644 --- a/src/accessor/grib_accessor_class_variable.h +++ b/src/accessor/grib_accessor_class_variable.h @@ -37,7 +37,8 @@ public: int compare(grib_accessor*) override; grib_accessor* make_clone(grib_section*, int*) override; -public: + void accessor_variable_set_type(int type); +private: double dval_; float fval_; char* cval_; diff --git a/src/eccodes_prototypes.h b/src/eccodes_prototypes.h index bde1fc807..5039a36e7 100644 --- a/src/eccodes_prototypes.h +++ b/src/eccodes_prototypes.h @@ -196,15 +196,15 @@ void grib_viarray_delete_content(grib_context* c, grib_viarray* v); /* grib_accessor_class_bufr_data_array.cc*/ /* grib_accessor_class_bufr_data_element.cc */ -void accessor_bufr_data_element_set_index(grib_accessor* a, long index); -void accessor_bufr_data_element_set_type(grib_accessor* a, int type); -void accessor_bufr_data_element_set_numberOfSubsets(grib_accessor* a, long numberOfSubsets); -void accessor_bufr_data_element_set_subsetNumber(grib_accessor* a, long subsetNumber); -void accessor_bufr_data_element_set_compressedData(grib_accessor* a, int compressedData); -void accessor_bufr_data_element_set_descriptors(grib_accessor* a, bufr_descriptors_array* descriptors); -void accessor_bufr_data_element_set_numericValues(grib_accessor* a, grib_vdarray* numericValues); -void accessor_bufr_data_element_set_stringValues(grib_accessor* a, grib_vsarray* stringValues); -void accessor_bufr_data_element_set_elementsDescriptorsIndex(grib_accessor* a, grib_viarray* elementsDescriptorsIndex); +//void accessor_bufr_data_element_set_index(grib_accessor* a, long index); +//void accessor_bufr_data_element_set_type(grib_accessor* a, int type); +//void accessor_bufr_data_element_set_numberOfSubsets(grib_accessor* a, long numberOfSubsets); +//void accessor_bufr_data_element_set_subsetNumber(grib_accessor* a, long subsetNumber); +//void accessor_bufr_data_element_set_compressedData(grib_accessor* a, int compressedData); +//void accessor_bufr_data_element_set_descriptors(grib_accessor* a, bufr_descriptors_array* descriptors); +//void accessor_bufr_data_element_set_numericValues(grib_accessor* a, grib_vdarray* numericValues); +//void accessor_bufr_data_element_set_stringValues(grib_accessor* a, grib_vsarray* stringValues); +//void accessor_bufr_data_element_set_elementsDescriptorsIndex(grib_accessor* a, grib_viarray* elementsDescriptorsIndex); /* grib_accessor_class_bufr_elements_table.cc */ int bufr_descriptor_is_marker(bufr_descriptor* d); @@ -242,7 +242,7 @@ grib_nearest* grib_nearest_new(const grib_handle* h, int* error); int grib_get_g1_message_size(grib_handle* h, grib_accessor* tl, grib_accessor* s4, long* total_length, long* sec4_len); /* grib_accessor_class_variable.cc */ -void accessor_variable_set_type(grib_accessor* a, int type); +//void accessor_variable_set_type(grib_accessor* a, int type); /* grib_accessor_class_expanded_descriptors.cc */ int grib_accessor_class_expanded_descriptors_set_do_expand(grib_accessor* a, long do_expand); diff --git a/src/grib_accessor_class.cc b/src/grib_accessor_class.cc index 67ce6b92f..762489961 100644 --- a/src/grib_accessor_class.cc +++ b/src/grib_accessor_class.cc @@ -129,22 +129,11 @@ static GRIB_INLINE grib_accessor_class* get_class(grib_context* c, char* type) grib_accessor* grib_accessor_factory(grib_section* p, grib_action* creator, const long len, grib_arguments* params) { - //grib_accessor_class* c = NULL; grib_accessor* a = NULL; size_t size = 0; -// TODO(maee): Replace this with an accessor_factory -#ifdef ACCESSOR_FACTORY_USE_TRIE - //c = get_class(p->h->context, creator->op); -#else - /* Use the hash table built with gperf (See make_accessor_class_hash.sh) */ - //c = *((grib_accessor_classes_hash(creator->op, strlen(creator->op)))->cclass); -#endif - - auto a_tmp = *((grib_accessor_hash(creator->op, strlen(creator->op)))->cclass); - - a = a_tmp->create_empty_accessor(); - //a = c->create_empty_accessor(); + grib_accessor* builder = *((grib_accessor_hash(creator->op, strlen(creator->op)))->cclass); + a = builder->create_empty_accessor(); a->name_ = creator->name; a->name_space_ = creator->name_space; @@ -179,8 +168,6 @@ grib_accessor* grib_accessor_factory(grib_section* p, grib_action* creator, a->offset_ = 0; } - //a->cclass_ = c; - a->init_accessor(len, params); size = a->get_next_position_offset(); diff --git a/src/grib_query.cc b/src/grib_query.cc index 398d24887..fa7f1417c 100644 --- a/src/grib_query.cc +++ b/src/grib_query.cc @@ -212,8 +212,9 @@ static char* get_condition(const char* name, codes_condition* condition) static grib_accessor* _search_by_rank(grib_accessor* a, const char* name, int rank) { - grib_trie_with_rank* t = accessor_bufr_data_array_get_dataAccessorsTrie(a); - grib_accessor* ret = (grib_accessor*)grib_trie_with_rank_get(t, name, rank); + grib_accessor_bufr_data_array_t* data_accessor = dynamic_cast(a); + grib_trie_with_rank* t = data_accessor->accessor_bufr_data_array_get_dataAccessorsTrie(); + grib_accessor* ret = (grib_accessor*)grib_trie_with_rank_get(t, name, rank); return ret; } @@ -431,9 +432,10 @@ static grib_accessors_list* search_by_condition(grib_handle* h, const char* name { grib_accessors_list* al; grib_accessors_list* result = NULL; - grib_accessor* data = search_and_cache(h, "dataAccessors", 0); - if (data && condition->left) { - al = accessor_bufr_data_array_get_dataAccessors(data); + grib_accessor* a = search_and_cache(h, "dataAccessors", 0); + grib_accessor_bufr_data_array_t* data_accessor = dynamic_cast(a); + if (data_accessor && condition->left) { + al = data_accessor->accessor_bufr_data_array_get_dataAccessors(); if (!al) return NULL; result = (grib_accessors_list*)grib_context_malloc_clear(al->accessor->context_, sizeof(grib_accessors_list)); diff --git a/tools/bufr_dump.cc b/tools/bufr_dump.cc index 6c31ce76e..bc11a8e8f 100644 --- a/tools/bufr_dump.cc +++ b/tools/bufr_dump.cc @@ -397,9 +397,9 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h) { long length = 0; int i, err = 0; - grib_handle* hclone = NULL; - grib_accessor* a = NULL; - grib_accessors_list* al = NULL; + grib_handle* hclone = NULL; + grib_accessor_bufr_data_array_t* data = NULL; + grib_accessors_list* al = NULL; if (grib_get_long(h, "totalLength", &length) != GRIB_SUCCESS) length = -9999; @@ -475,8 +475,8 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h) /*return err; See ECC-723*/ } } - a = grib_find_accessor(h, "numericValues"); - al = accessor_bufr_data_array_get_dataAccessors(a); + data = dynamic_cast(grib_find_accessor(h, "numericValues")); + al = data->accessor_bufr_data_array_get_dataAccessors(); options->dump_flags = GRIB_DUMP_FLAG_ALL_ATTRIBUTES; codes_dump_bufr_flat(al, h, stdout, options->dump_mode, options->dump_flags, 0); break;