diff --git a/src/accessor/grib_accessor_class_lookup.cc b/src/accessor/grib_accessor_class_lookup.cc index 17ccd4d61..e58162ccb 100644 --- a/src/accessor/grib_accessor_class_lookup.cc +++ b/src/accessor/grib_accessor_class_lookup.cc @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * @@ -11,39 +10,42 @@ #include "grib_accessor_class_lookup.h" -grib_accessor_class_lookup_t _grib_accessor_class_lookup{"lookup"}; +grib_accessor_class_lookup_t _grib_accessor_class_lookup{ "lookup" }; grib_accessor_class* grib_accessor_class_lookup = &_grib_accessor_class_lookup; -void grib_accessor_class_lookup_t::init(grib_accessor* a, const long len, grib_arguments* arg){ +void grib_accessor_class_lookup_t::init(grib_accessor* a, const long len, grib_arguments* arg) +{ grib_accessor_class_long_t::init(a, len, arg); grib_accessor_lookup_t* self = (grib_accessor_lookup_t*)a; - a->length = 0; - self->llength = len; - self->loffset = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 0); + + a->length = 0; + self->llength = len; + self->loffset = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 0); a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; self->real_name = grib_arguments_get_expression(grib_handle_of_accessor(a), arg, 1); } -void grib_accessor_class_lookup_t::post_init(grib_accessor* a){ +void grib_accessor_class_lookup_t::post_init(grib_accessor* a) +{ grib_accessor_lookup_t* self = (grib_accessor_lookup_t*)a; if (self->real_name) { grib_dependency_observe_expression(a, self->real_name); } } -void grib_accessor_class_lookup_t::dump(grib_accessor* a, grib_dumper* dumper){ +void grib_accessor_class_lookup_t::dump(grib_accessor* a, grib_dumper* dumper) +{ grib_accessor_lookup_t* self = (grib_accessor_lookup_t*)a; - unsigned char bytes[1024] = {0,}; + unsigned char bytes[1024] = {0,}; char msg[1024] = {0,}; char buf[2048]; - int i; unsigned long v = 0; size_t llen = self->llength; a->unpack_bytes(bytes, &llen); bytes[llen] = 0; - for (i = 0; i < llen; i++) { + for (size_t i = 0; i < llen; i++) { msg[i] = isprint(bytes[i]) ? bytes[i] : '?'; v <<= 8; v |= bytes[i]; @@ -56,16 +58,16 @@ void grib_accessor_class_lookup_t::dump(grib_accessor* a, grib_dumper* dumper){ grib_dump_long(dumper, a, buf); } -int grib_accessor_class_lookup_t::unpack_string(grib_accessor* a, char* v, size_t* len){ +int grib_accessor_class_lookup_t::unpack_string(grib_accessor* a, char* v, size_t* len) +{ grib_accessor_lookup_t* self = (grib_accessor_lookup_t*)a; - unsigned char bytes[1024] = {0,}; - int i; + unsigned char bytes[1024] = {0,}; size_t llen = self->llength; a->unpack_bytes(bytes, &llen); bytes[llen] = 0; - for (i = 0; i < llen; i++) { + for (size_t i = 0; i < llen; i++) { v[i] = isprint(bytes[i]) ? bytes[i] : '?'; } @@ -87,9 +89,10 @@ int grib_accessor_class_lookup_t::unpack_string(grib_accessor* a, char* v, size_ return GRIB_SUCCESS; } -int grib_accessor_class_lookup_t::unpack_long(grib_accessor* a, long* val, size_t* len){ +int grib_accessor_class_lookup_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ grib_accessor_lookup_t* self = (grib_accessor_lookup_t*)a; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(a); long pos = (a->offset + self->loffset) * 8; @@ -113,21 +116,25 @@ int grib_accessor_class_lookup_t::unpack_long(grib_accessor* a, long* val, size_ return GRIB_SUCCESS; } -int grib_accessor_class_lookup_t::pack_long(grib_accessor* a, const long* val, size_t* len){ +int grib_accessor_class_lookup_t::pack_long(grib_accessor* a, const long* val, size_t* len) +{ return GRIB_NOT_IMPLEMENTED; } -long grib_accessor_class_lookup_t::byte_count(grib_accessor* a){ +long grib_accessor_class_lookup_t::byte_count(grib_accessor* a) +{ grib_accessor_lookup_t* self = (grib_accessor_lookup_t*)a; return self->llength; } -long grib_accessor_class_lookup_t::byte_offset(grib_accessor* a){ +long grib_accessor_class_lookup_t::byte_offset(grib_accessor* a) +{ grib_accessor_lookup_t* self = (grib_accessor_lookup_t*)a; return self->loffset; } -int grib_accessor_class_lookup_t::notify_change(grib_accessor* self, grib_accessor* changed){ +int grib_accessor_class_lookup_t::notify_change(grib_accessor* self, grib_accessor* changed) +{ /* Forward changes */ return grib_dependency_notify_change(self); } diff --git a/src/accessor/grib_accessor_class_number_of_values_data_raw_packing.cc b/src/accessor/grib_accessor_class_number_of_values_data_raw_packing.cc index b8f1d667b..c443e7c24 100644 --- a/src/accessor/grib_accessor_class_number_of_values_data_raw_packing.cc +++ b/src/accessor/grib_accessor_class_number_of_values_data_raw_packing.cc @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * @@ -11,28 +10,31 @@ #include "grib_accessor_class_number_of_values_data_raw_packing.h" -grib_accessor_class_number_of_values_data_raw_packing_t _grib_accessor_class_number_of_values_data_raw_packing{"number_of_values_data_raw_packing"}; +grib_accessor_class_number_of_values_data_raw_packing_t _grib_accessor_class_number_of_values_data_raw_packing{ "number_of_values_data_raw_packing" }; grib_accessor_class* grib_accessor_class_number_of_values_data_raw_packing = &_grib_accessor_class_number_of_values_data_raw_packing; -void grib_accessor_class_number_of_values_data_raw_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){ +void grib_accessor_class_number_of_values_data_raw_packing_t::init(grib_accessor* a, const long v, grib_arguments* args) +{ grib_accessor_class_gen_t::init(a, v, args); - int n = 0; grib_accessor_number_of_values_data_raw_packing_t* self = (grib_accessor_number_of_values_data_raw_packing_t*)a; + int n = 0; self->values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); self->precision = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; a->length = 0; } -int grib_accessor_class_number_of_values_data_raw_packing_t::unpack_long(grib_accessor* a, long* val, size_t* len){ - int err = 0; +int grib_accessor_class_number_of_values_data_raw_packing_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ grib_accessor_number_of_values_data_raw_packing_t* self = (grib_accessor_number_of_values_data_raw_packing_t*)a; - grib_accessor* adata = NULL; - long precision = 0; - int bytes = 0; - long byte_count = 0; + + int err = 0; + grib_accessor* adata = NULL; + long precision = 0; + int bytes = 0; + long byte_count = 0; adata = grib_find_accessor(grib_handle_of_accessor(a), self->values); Assert(adata != NULL); @@ -58,6 +60,7 @@ int grib_accessor_class_number_of_values_data_raw_packing_t::unpack_long(grib_ac return err; } -int grib_accessor_class_number_of_values_data_raw_packing_t::get_native_type(grib_accessor* a){ +int grib_accessor_class_number_of_values_data_raw_packing_t::get_native_type(grib_accessor* a) +{ return GRIB_TYPE_LONG; } diff --git a/src/accessor/grib_accessor_class_octet_number.cc b/src/accessor/grib_accessor_class_octet_number.cc index 4b270f257..354a39820 100644 --- a/src/accessor/grib_accessor_class_octet_number.cc +++ b/src/accessor/grib_accessor_class_octet_number.cc @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * @@ -11,27 +10,27 @@ #include "grib_accessor_class_octet_number.h" -grib_accessor_class_octet_number_t _grib_accessor_class_octet_number{"octet_number"}; +grib_accessor_class_octet_number_t _grib_accessor_class_octet_number{ "octet_number" }; grib_accessor_class* grib_accessor_class_octet_number = &_grib_accessor_class_octet_number; -void grib_accessor_class_octet_number_t::init(grib_accessor* a, const long l, grib_arguments* c){ +void grib_accessor_class_octet_number_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ grib_accessor_class_long_t::init(a, l, c); grib_accessor_octet_number_t* self = (grib_accessor_octet_number_t*)a; - int n = 0; + int n = 0; self->left = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); self->right = grib_arguments_get_long(grib_handle_of_accessor(a), c, n++); a->length = 0; } -int grib_accessor_class_octet_number_t::unpack_long(grib_accessor* a, long* val, size_t* len){ +int grib_accessor_class_octet_number_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ grib_accessor_octet_number_t* self = (grib_accessor_octet_number_t*)a; int ret = GRIB_SUCCESS; - long offset; - - offset = a->offset + self->right; + long offset = a->offset + self->right; if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->left, offset)) != GRIB_SUCCESS) return ret; @@ -42,6 +41,7 @@ int grib_accessor_class_octet_number_t::unpack_long(grib_accessor* a, long* val, return ret; } -int grib_accessor_class_octet_number_t::pack_long(grib_accessor* a, const long* val, size_t* len){ +int grib_accessor_class_octet_number_t::pack_long(grib_accessor* a, const long* val, size_t* len) +{ return GRIB_SUCCESS; } diff --git a/src/accessor/grib_accessor_class_padding.cc b/src/accessor/grib_accessor_class_padding.cc index 499c77f2b..226e4b75b 100644 --- a/src/accessor/grib_accessor_class_padding.cc +++ b/src/accessor/grib_accessor_class_padding.cc @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * @@ -11,48 +10,55 @@ #include "grib_accessor_class_padding.h" -grib_accessor_class_padding_t _grib_accessor_class_padding{"padding"}; +grib_accessor_class_padding_t _grib_accessor_class_padding{ "padding" }; grib_accessor_class* grib_accessor_class_padding = &_grib_accessor_class_padding; -void grib_accessor_class_padding_t::init(grib_accessor* a, const long len, grib_arguments* arg){ +void grib_accessor_class_padding_t::init(grib_accessor* a, const long len, grib_arguments* arg) +{ grib_accessor_class_bytes_t::init(a, len, arg); a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -int grib_accessor_class_padding_t::compare(grib_accessor* a, grib_accessor* b){ +int grib_accessor_class_padding_t::compare(grib_accessor* a, grib_accessor* b) +{ if (a->length != b->length) return GRIB_COUNT_MISMATCH; return GRIB_SUCCESS; } -void grib_accessor_class_padding_t::update_size(grib_accessor* a, size_t new_size){ +void grib_accessor_class_padding_t::update_size(grib_accessor* a, size_t new_size) +{ a->length = new_size; } -void grib_accessor_class_padding_t::resize(grib_accessor* a, size_t new_size){ +void grib_accessor_class_padding_t::resize(grib_accessor* a, size_t new_size) +{ void* zero = grib_context_malloc_clear(a->context, new_size); grib_buffer_replace(a, (const unsigned char*)zero, new_size, /*update_lengths=*/1, /*update_paddings=*/0); grib_context_free(a->context, zero); - grib_context_log(a->context, GRIB_LOG_DEBUG, - "grib_accessor_class_padding::resize new_size=%zu a->length=%ld %s %s", - new_size, a->length, a->cclass->name, a->name); + grib_context_log(a->context, GRIB_LOG_DEBUG, + "grib_accessor_class_padding::resize new_size=%zu a->length=%ld %s %s", + new_size, a->length, a->cclass->name, a->name); Assert(new_size == a->length); } -int grib_accessor_class_padding_t::value_count(grib_accessor* a, long* c){ +int grib_accessor_class_padding_t::value_count(grib_accessor* a, long* c) +{ *c = a->length; return 0; } -long grib_accessor_class_padding_t::byte_count(grib_accessor* a){ +long grib_accessor_class_padding_t::byte_count(grib_accessor* a) +{ return a->length; } -size_t grib_accessor_class_padding_t::string_length(grib_accessor* a){ +size_t grib_accessor_class_padding_t::string_length(grib_accessor* a) +{ return (size_t)a->length; } diff --git a/src/accessor/grib_accessor_class_padto.cc b/src/accessor/grib_accessor_class_padto.cc index 110d8d858..4fa523acd 100644 --- a/src/accessor/grib_accessor_class_padto.cc +++ b/src/accessor/grib_accessor_class_padto.cc @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * @@ -11,12 +10,12 @@ #include "grib_accessor_class_padto.h" -grib_accessor_class_padto_t _grib_accessor_class_padto{"padto"}; +grib_accessor_class_padto_t _grib_accessor_class_padto{ "padto" }; grib_accessor_class* grib_accessor_class_padto = &_grib_accessor_class_padto; - -size_t grib_accessor_class_padto_t::preferred_size(grib_accessor* a, int from_handle){ +size_t grib_accessor_class_padto_t::preferred_size(grib_accessor* a, int from_handle) +{ grib_accessor_padto_t* self = (grib_accessor_padto_t*)a; long length = 0; @@ -26,13 +25,13 @@ size_t grib_accessor_class_padto_t::preferred_size(grib_accessor* a, int from_ha length = theEnd - a->offset; - /* printf("preferred_size: prefered: %ld current:%ld %s %s %ld\n", (long)length,(long)a->length,a->cclass->name,a->name,(long)a->offset); */ + //printf("preferred_size: prefered: %ld current:%ld %s %s %ld\n", (long)length,(long)a->length,a->cclass->name,a->name,(long)a->offset); return length > 0 ? length : 0; } - -void grib_accessor_class_padto_t::init(grib_accessor* a, const long len, grib_arguments* arg){ +void grib_accessor_class_padto_t::init(grib_accessor* a, const long len, grib_arguments* arg) +{ grib_accessor_class_padding_t::init(a, len, arg); grib_accessor_padto_t* self = (grib_accessor_padto_t*)a; @@ -40,6 +39,7 @@ void grib_accessor_class_padto_t::init(grib_accessor* a, const long len, grib_ar a->length = preferred_size(a, 1); } -void grib_accessor_class_padto_t::dump(grib_accessor* a, grib_dumper* dumper){ - /*grib_dump_string(dumper,a,NULL);*/ +void grib_accessor_class_padto_t::dump(grib_accessor* a, grib_dumper* dumper) +{ + //grib_dump_string(dumper,a,NULL); } diff --git a/src/accessor/grib_accessor_class_padtoeven.cc b/src/accessor/grib_accessor_class_padtoeven.cc index adf8b0d84..b91a9fb51 100644 --- a/src/accessor/grib_accessor_class_padtoeven.cc +++ b/src/accessor/grib_accessor_class_padtoeven.cc @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * @@ -11,14 +10,15 @@ #include "grib_accessor_class_padtoeven.h" -grib_accessor_class_padtoeven_t _grib_accessor_class_padtoeven{"padtoeven"}; +grib_accessor_class_padtoeven_t _grib_accessor_class_padtoeven{ "padtoeven" }; grib_accessor_class* grib_accessor_class_padtoeven = &_grib_accessor_class_padtoeven; -size_t grib_accessor_class_padtoeven_t::preferred_size(grib_accessor* a, int from_handle){ +size_t grib_accessor_class_padtoeven_t::preferred_size(grib_accessor* a, int from_handle) +{ grib_accessor_padtoeven_t* self = (grib_accessor_padtoeven_t*)a; - long offset = 0; - long length = 0; + long offset = 0; + long length = 0; long seclen; grib_get_long_internal(grib_handle_of_accessor(a), self->section_offset, &offset); @@ -31,13 +31,14 @@ size_t grib_accessor_class_padtoeven_t::preferred_size(grib_accessor* a, int fro return 0; } - /* printf("EVEN %ld %ld\n",(long) a->offset,(long) offset);*/ + // printf("EVEN %ld %ld\n",(long) a->offset,(long) offset); seclen = a->offset - offset; return (seclen % 2) ? 1 : 0; } -void grib_accessor_class_padtoeven_t::init(grib_accessor* a, const long len, grib_arguments* args){ +void grib_accessor_class_padtoeven_t::init(grib_accessor* a, const long len, grib_arguments* args) +{ grib_accessor_class_padding_t::init(a, len, args); grib_accessor_padtoeven_t* self = (grib_accessor_padtoeven_t*)a; diff --git a/src/accessor/grib_accessor_class_padtomultiple.cc b/src/accessor/grib_accessor_class_padtomultiple.cc index d4e463578..b76c1d78a 100644 --- a/src/accessor/grib_accessor_class_padtomultiple.cc +++ b/src/accessor/grib_accessor_class_padtomultiple.cc @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * @@ -11,15 +10,16 @@ #include "grib_accessor_class_padtomultiple.h" -grib_accessor_class_padtomultiple_t _grib_accessor_class_padtomultiple{"padtomultiple"}; +grib_accessor_class_padtomultiple_t _grib_accessor_class_padtomultiple{ "padtomultiple" }; grib_accessor_class* grib_accessor_class_padtomultiple = &_grib_accessor_class_padtomultiple; -size_t grib_accessor_class_padtomultiple_t::preferred_size(grib_accessor* a, int from_handle){ +size_t grib_accessor_class_padtomultiple_t::preferred_size(grib_accessor* a, int from_handle) +{ grib_accessor_padtomultiple_t* self = (grib_accessor_padtomultiple_t*)a; - long padding = 0; - long begin = 0; - long multiple = 0; + long padding = 0; + long begin = 0; + long multiple = 0; grib_expression_evaluate_long(grib_handle_of_accessor(a), self->begin, &begin); grib_expression_evaluate_long(grib_handle_of_accessor(a), self->multiple, &multiple); @@ -30,7 +30,8 @@ size_t grib_accessor_class_padtomultiple_t::preferred_size(grib_accessor* a, int return padding == 0 ? multiple : padding; } -void grib_accessor_class_padtomultiple_t::init(grib_accessor* a, const long len, grib_arguments* arg){ +void grib_accessor_class_padtomultiple_t::init(grib_accessor* a, const long len, grib_arguments* arg) +{ grib_accessor_class_padding_t::init(a, len, arg); grib_accessor_padtomultiple_t* self = (grib_accessor_padtomultiple_t*)a; diff --git a/src/accessor/grib_accessor_class_section.cc b/src/accessor/grib_accessor_class_section.cc index ec6e14c2b..8abb7aa01 100644 --- a/src/accessor/grib_accessor_class_section.cc +++ b/src/accessor/grib_accessor_class_section.cc @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * @@ -11,45 +10,51 @@ #include "grib_accessor_class_section.h" -grib_accessor_class_section_t _grib_accessor_class_section{"section"}; +grib_accessor_class_section_t _grib_accessor_class_section{ "section" }; grib_accessor_class* grib_accessor_class_section = &_grib_accessor_class_section; -void grib_accessor_class_section_t::init(grib_accessor* a, const long len, grib_arguments* arg){ +void grib_accessor_class_section_t::init(grib_accessor* a, const long len, grib_arguments* arg) +{ grib_accessor_class_gen_t::init(a, len, arg); a->sub_section = grib_section_create(grib_handle_of_accessor(a), a); a->length = 0; a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -void grib_accessor_class_section_t::dump(grib_accessor* a, grib_dumper* dumper){ +void grib_accessor_class_section_t::dump(grib_accessor* a, grib_dumper* dumper) +{ grib_dump_section(dumper, a, a->sub_section->block); } -long grib_accessor_class_section_t::byte_count(grib_accessor* a){ +long grib_accessor_class_section_t::byte_count(grib_accessor* a) +{ if (!a->length || grib_handle_of_accessor(a)->loader) { if (a->name[1] == '_') return 0; - /* printf("adjusting sizes SECTION %s is %ld %ld\n",a->name,(long)a->offset,(long)a->length); */ + //printf("adjusting sizes SECTION %s is %ld %ld\n",a->name,(long)a->offset,(long)a->length); grib_section_adjust_sizes(a->sub_section, grib_handle_of_accessor(a)->loader != NULL, 0); - /* printf(" SECTION %s is %ld %ld\n",a->name,(long)a->offset,(long)a->length); */ + //printf(" SECTION %s is %ld %ld\n",a->name,(long)a->offset,(long)a->length); } - /* printf("SECTION %s is %ld %d\n",a->name,a->length,a->sub_section->aclength != NULL); */ + // printf("SECTION %s is %ld %d\n",a->name,a->length,a->sub_section->aclength != NULL); return a->length; } -long grib_accessor_class_section_t::next_offset(grib_accessor* a){ +long grib_accessor_class_section_t::next_offset(grib_accessor* a) +{ return a->offset + a->byte_count(); } -void grib_accessor_class_section_t::destroy(grib_context* ct, grib_accessor* a){ +void grib_accessor_class_section_t::destroy(grib_context* ct, grib_accessor* a) +{ grib_section_delete(ct, a->sub_section); grib_accessor_class_gen_t::destroy(ct, a); } -int grib_accessor_class_section_t::get_native_type(grib_accessor* a){ +int grib_accessor_class_section_t::get_native_type(grib_accessor* a) +{ return GRIB_TYPE_SECTION; } @@ -58,22 +63,23 @@ grib_section* grib_accessor_class_section_t::sub_section(grib_accessor* a) return a->sub_section; } -void grib_accessor_class_section_t::update_size(grib_accessor* a, size_t length){ +void grib_accessor_class_section_t::update_size(grib_accessor* a, size_t length) +{ size_t size = 1; long len = length; Assert(length <= 0x7fffffff); if (a->sub_section->aclength) { - int e = a->sub_section->aclength->pack_long(&len, &size); Assert(e == GRIB_SUCCESS); + int e = a->sub_section->aclength->pack_long(&len, &size); + Assert(e == GRIB_SUCCESS); // printf("update_length %s %ld %ld\n", a->sub_section->aclength->name, // (long)a->sub_section->aclength->offset, // (long)a->sub_section->aclength->length); } a->sub_section->length = a->length = length; - a->sub_section->padding = 0; + a->sub_section->padding = 0; // printf("update_size %s %ld\n", a->name, a->length); - Assert(a->length >= 0); } diff --git a/src/accessor/grib_accessor_class_section_length.cc b/src/accessor/grib_accessor_class_section_length.cc index bcc75cc2b..8be4cad56 100644 --- a/src/accessor/grib_accessor_class_section_length.cc +++ b/src/accessor/grib_accessor_class_section_length.cc @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * @@ -11,11 +10,12 @@ #include "grib_accessor_class_section_length.h" -grib_accessor_class_section_length_t _grib_accessor_class_section_length{"section_length"}; +grib_accessor_class_section_length_t _grib_accessor_class_section_length{ "section_length" }; grib_accessor_class* grib_accessor_class_section_length = &_grib_accessor_class_section_length; -void grib_accessor_class_section_length_t::init(grib_accessor* a, const long len, grib_arguments* arg){ +void grib_accessor_class_section_length_t::init(grib_accessor* a, const long len, grib_arguments* arg) +{ grib_accessor_class_unsigned_t::init(a, len, arg); a->parent->aclength = a; a->length = len; @@ -24,11 +24,13 @@ void grib_accessor_class_section_length_t::init(grib_accessor* a, const long len Assert(a->length >= 0); } -void grib_accessor_class_section_length_t::dump(grib_accessor* a, grib_dumper* dumper){ +void grib_accessor_class_section_length_t::dump(grib_accessor* a, grib_dumper* dumper) +{ grib_dump_long(dumper, a, NULL); } -int grib_accessor_class_section_length_t::value_count(grib_accessor* a, long* c){ +int grib_accessor_class_section_length_t::value_count(grib_accessor* a, long* c) +{ *c = 1; return 0; } diff --git a/src/accessor/grib_accessor_class_section_pointer.cc b/src/accessor/grib_accessor_class_section_pointer.cc index 72eb78d6d..c7735d504 100644 --- a/src/accessor/grib_accessor_class_section_pointer.cc +++ b/src/accessor/grib_accessor_class_section_pointer.cc @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * @@ -11,15 +10,16 @@ #include "grib_accessor_class_section_pointer.h" -grib_accessor_class_section_pointer_t _grib_accessor_class_section_pointer{"section_pointer"}; +grib_accessor_class_section_pointer_t _grib_accessor_class_section_pointer{ "section_pointer" }; grib_accessor_class* grib_accessor_class_section_pointer = &_grib_accessor_class_section_pointer; -void grib_accessor_class_section_pointer_t::init(grib_accessor* a, const long len, grib_arguments* arg){ +void grib_accessor_class_section_pointer_t::init(grib_accessor* a, const long len, grib_arguments* arg) +{ grib_accessor_class_gen_t::init(a, len, arg); - int n = 0; grib_accessor_section_pointer_t* self = (grib_accessor_section_pointer_t*)a; + int n = 0; self->sectionOffset = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); self->sectionLength = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); self->sectionNumber = grib_arguments_get_long(grib_handle_of_accessor(a), arg, n++); @@ -29,8 +29,8 @@ void grib_accessor_class_section_pointer_t::init(grib_accessor* a, const long le grib_handle_of_accessor(a)->section_offset[self->sectionNumber] = (char*)self->sectionOffset; grib_handle_of_accessor(a)->section_length[self->sectionNumber] = (char*)self->sectionLength; - /* printf("++++++++++++++ GRIB_API: creating section_pointer%d %s %s\n", */ - /* self->sectionNumber,self->sectionLength,self->sectionLength); */ + // printf("++++++++++++++ creating section_pointer%d %s %s\n", + // self->sectionNumber,self->sectionLength,self->sectionLength); if (grib_handle_of_accessor(a)->sections_count < self->sectionNumber) grib_handle_of_accessor(a)->sections_count = self->sectionNumber; @@ -42,54 +42,56 @@ void grib_accessor_class_section_pointer_t::init(grib_accessor* a, const long le a->length = 0; } -int grib_accessor_class_section_pointer_t::get_native_type(grib_accessor* a){ +int grib_accessor_class_section_pointer_t::get_native_type(grib_accessor* a) +{ return GRIB_TYPE_BYTES; } -int grib_accessor_class_section_pointer_t::unpack_string(grib_accessor* a, char* v, size_t* len){ - /* - unsigned char* p=NULL; - char* s=v; - int i; - long length=a->byte_count(); - if (*len < length) return GRIB_ARRAY_TOO_SMALL; +int grib_accessor_class_section_pointer_t::unpack_string(grib_accessor* a, char* v, size_t* len) +{ + // unsigned char* p=NULL; + // char* s=v; + // int i; + // long length=a->byte_count(); + // if (*len < length) return GRIB_ARRAY_TOO_SMALL; - p = grib_handle_of_accessor(a)->buffer->data + a->byte_offset(); - for (i = 0; i < length; i++) { - snprintf (s,64,"%02x", *(p++)); - s+=2; - } - *len=length; - */ - snprintf(v, 64, "%ld_%ld", a->byte_offset(), a->byte_count()); return GRIB_SUCCESS; + // p = grib_handle_of_accessor(a)->buffer->data + a->byte_offset(); + // for (i = 0; i < length; i++) { + // snprintf (s,64,"%02x", *(p++)); + // s+=2; + // } + // *len=length; + + snprintf(v, 64, "%ld_%ld", a->byte_offset(), a->byte_count()); + return GRIB_SUCCESS; } -long grib_accessor_class_section_pointer_t::byte_count(grib_accessor* a){ +long grib_accessor_class_section_pointer_t::byte_count(grib_accessor* a) +{ grib_accessor_section_pointer_t* self = (grib_accessor_section_pointer_t*)a; long sectionLength = 0; - int ret = 0; - ret = grib_get_long(grib_handle_of_accessor(a), self->sectionLength, §ionLength); - if (ret) { + int err = grib_get_long(grib_handle_of_accessor(a), self->sectionLength, §ionLength); + if (err) { grib_context_log(a->context, GRIB_LOG_ERROR, - "Unable to get %s %s", - self->sectionLength, grib_get_error_message(ret)); + "grib_accessor_class_section_pointer_t::byte_count: Unable to get %s %s", + self->sectionLength, grib_get_error_message(err)); return -1; } return sectionLength; } -long grib_accessor_class_section_pointer_t::byte_offset(grib_accessor* a){ +long grib_accessor_class_section_pointer_t::byte_offset(grib_accessor* a) +{ grib_accessor_section_pointer_t* self = (grib_accessor_section_pointer_t*)a; long sectionOffset = 0; - int ret = 0; - ret = grib_get_long(grib_handle_of_accessor(a), self->sectionOffset, §ionOffset); - if (ret) { + int err = grib_get_long(grib_handle_of_accessor(a), self->sectionOffset, §ionOffset); + if (err) { grib_context_log(a->context, GRIB_LOG_ERROR, - "Unable to get %s %s", - self->sectionOffset, grib_get_error_message(ret)); + "grib_accessor_class_section_pointer_t::byte_offset: Unable to get %s (%s)", + self->sectionOffset, grib_get_error_message(err)); return -1; } diff --git a/src/grib_value.cc b/src/grib_value.cc index 51a839da4..f89cb9725 100644 --- a/src/grib_value.cc +++ b/src/grib_value.cc @@ -272,7 +272,7 @@ int grib_copy_namespace(grib_handle* dest, const char* name, grib_handle* src) switch (type) { case GRIB_TYPE_STRING: - len = 512; + len = 1024; sval = (char*)grib_context_malloc(src->context, len * sizeof(char)); if ((*err = grib_get_string(src, key, sval, &len)) != GRIB_SUCCESS) @@ -309,8 +309,7 @@ int grib_copy_namespace(grib_handle* dest, const char* name, grib_handle* src) break; case GRIB_TYPE_BYTES: - if (len == 0) - len = 512; + len = 1024; uval = (unsigned char*)grib_context_malloc(src->context, len * sizeof(unsigned char)); if ((*err = grib_get_bytes(src, key, uval, &len)) != GRIB_SUCCESS)