diff --git a/src/accessor/grib_accessor_class_ascii.cc b/src/accessor/grib_accessor_class_ascii.cc index f45053267..b3e9f6a8a 100644 --- a/src/accessor/grib_accessor_class_ascii.cc +++ b/src/accessor/grib_accessor_class_ascii.cc @@ -11,35 +11,40 @@ #include "grib_accessor_class_ascii.h" -grib_accessor_class_ascii_t _grib_accessor_class_ascii{"ascii"}; +grib_accessor_class_ascii_t _grib_accessor_class_ascii{ "ascii" }; grib_accessor_class* grib_accessor_class_ascii = &_grib_accessor_class_ascii; -void grib_accessor_class_ascii_t::init(grib_accessor* a, const long len, grib_arguments* arg){ +void grib_accessor_class_ascii_t::init(grib_accessor* a, const long len, grib_arguments* arg) +{ grib_accessor_class_gen_t::init(a, len, arg); a->length = len; Assert(a->length >= 0); } -int grib_accessor_class_ascii_t::value_count(grib_accessor* a, long* count){ +int grib_accessor_class_ascii_t::value_count(grib_accessor* a, long* count) +{ *count = 1; return 0; } -size_t grib_accessor_class_ascii_t::string_length(grib_accessor* a){ +size_t grib_accessor_class_ascii_t::string_length(grib_accessor* a) +{ return a->length; } -void grib_accessor_class_ascii_t::dump(grib_accessor* a, grib_dumper* dumper){ +void grib_accessor_class_ascii_t::dump(grib_accessor* a, grib_dumper* dumper) +{ grib_dump_string(dumper, a, NULL); } -int grib_accessor_class_ascii_t::get_native_type(grib_accessor* a){ +int grib_accessor_class_ascii_t::get_native_type(grib_accessor* a) +{ return GRIB_TYPE_STRING; } -int grib_accessor_class_ascii_t::unpack_string(grib_accessor* a, char* val, size_t* len){ - size_t i = 0; +int grib_accessor_class_ascii_t::unpack_string(grib_accessor* a, char* val, size_t* len) +{ grib_handle* hand = grib_handle_of_accessor(a); const size_t alen = a->length; @@ -47,30 +52,32 @@ int grib_accessor_class_ascii_t::unpack_string(grib_accessor* a, char* val, size const char* cclass_name = a->cclass->name; grib_context_log(a->context, GRIB_LOG_ERROR, "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", - cclass_name, a->name, alen+1, *len); + cclass_name, a->name, alen + 1, *len); *len = alen + 1; return GRIB_BUFFER_TOO_SMALL; } + size_t i = 0; for (i = 0; i < alen; i++) val[i] = hand->buffer->data[a->offset + i]; val[i] = 0; - *len = i; + *len = i; return GRIB_SUCCESS; } -int grib_accessor_class_ascii_t::pack_string(grib_accessor* a, const char* val, size_t* len){ - size_t i = 0; +int grib_accessor_class_ascii_t::pack_string(grib_accessor* a, const char* val, size_t* len) +{ grib_handle* hand = grib_handle_of_accessor(a); const size_t alen = a->length; if (len[0] > (alen + 1)) { grib_context_log(a->context, GRIB_LOG_ERROR, - "pack_string: Wrong size (%zu) for %s, it contains %ld values", len[0], a->name, a->length + 1); + "pack_string: Wrong size (%zu) for %s, it contains %ld values", + len[0], a->name, a->length + 1); len[0] = 0; return GRIB_BUFFER_TOO_SMALL; } - for (i = 0; i < alen; i++) { + for (size_t i = 0; i < alen; i++) { if (i < len[0]) hand->buffer->data[a->offset + i] = val[i]; else @@ -80,17 +87,20 @@ int grib_accessor_class_ascii_t::pack_string(grib_accessor* a, const char* val, return GRIB_SUCCESS; } -int grib_accessor_class_ascii_t::pack_long(grib_accessor* a, const long* v, size_t* len){ +int grib_accessor_class_ascii_t::pack_long(grib_accessor* a, const long* v, size_t* len) +{ grib_context_log(a->context, GRIB_LOG_ERROR, "Should not pack %s as long (It's a string)", a->name); return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_ascii_t::pack_double(grib_accessor* a, const double* v, size_t* len){ +int grib_accessor_class_ascii_t::pack_double(grib_accessor* a, const double* v, size_t* len) +{ grib_context_log(a->context, GRIB_LOG_ERROR, "Should not pack %s as double (It's a string)", a->name); return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_ascii_t::unpack_long(grib_accessor* a, long* v, size_t* len){ +int grib_accessor_class_ascii_t::unpack_long(grib_accessor* a, long* v, size_t* len) +{ char val[1024] = {0,}; size_t l = sizeof(val); size_t i = 0; @@ -116,12 +126,14 @@ int grib_accessor_class_ascii_t::unpack_long(grib_accessor* a, long* v, size_t* return GRIB_SUCCESS; } -int grib_accessor_class_ascii_t::unpack_double(grib_accessor* a, double* v, size_t* len){ +int grib_accessor_class_ascii_t::unpack_double(grib_accessor* a, double* v, size_t* len) +{ char val[1024]; size_t l = sizeof(val); char* last = NULL; - int err = a->unpack_string(val, &l); if (err) return err; + int err = a->unpack_string(val, &l); + if (err) return err; *v = strtod(val, &last); @@ -135,14 +147,15 @@ int grib_accessor_class_ascii_t::unpack_double(grib_accessor* a, double* v, size return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_ascii_t::compare(grib_accessor* a, grib_accessor* b){ +int grib_accessor_class_ascii_t::compare(grib_accessor* a, grib_accessor* b) +{ int retval = 0; char* aval = 0; char* bval = 0; int err = 0; - size_t alen = a->length+1; - size_t blen = b->length+1; + size_t alen = a->length + 1; + size_t blen = b->length + 1; if (alen != blen) return GRIB_COUNT_MISMATCH; @@ -150,8 +163,10 @@ int grib_accessor_class_ascii_t::compare(grib_accessor* a, grib_accessor* b){ aval = (char*)grib_context_malloc(a->context, alen * sizeof(char)); bval = (char*)grib_context_malloc(b->context, blen * sizeof(char)); - err = a->unpack_string(aval, &alen); if (err) return err; - err = b->unpack_string(bval, &blen); if (err) return err; + err = a->unpack_string(aval, &alen); + if (err) return err; + err = b->unpack_string(bval, &blen); + if (err) return err; retval = GRIB_SUCCESS; if (!STR_EQUAL(aval, bval)) diff --git a/src/accessor/grib_accessor_class_bitmap.cc b/src/accessor/grib_accessor_class_bitmap.cc index e507d021b..505871a3a 100644 --- a/src/accessor/grib_accessor_class_bitmap.cc +++ b/src/accessor/grib_accessor_class_bitmap.cc @@ -11,12 +11,11 @@ #include "grib_accessor_class_bitmap.h" -grib_accessor_class_bitmap_t _grib_accessor_class_bitmap{"bitmap"}; +grib_accessor_class_bitmap_t _grib_accessor_class_bitmap{ "bitmap" }; grib_accessor_class* grib_accessor_class_bitmap = &_grib_accessor_class_bitmap; - - -void compute_size(grib_accessor* a){ +static void compute_size(grib_accessor* a) +{ long slen = 0; long off = 0; grib_handle* hand = grib_handle_of_accessor(a); @@ -51,7 +50,8 @@ void compute_size(grib_accessor* a){ Assert(a->length >= 0); } -void grib_accessor_class_bitmap_t::init(grib_accessor* a, const long len, grib_arguments* arg){ +void grib_accessor_class_bitmap_t::init(grib_accessor* a, const long len, grib_arguments* arg) +{ grib_accessor_class_bytes_t::init(a, len, arg); grib_accessor_bitmap_t* self = (grib_accessor_bitmap_t*)a; grib_handle* hand = grib_handle_of_accessor(a); @@ -65,24 +65,29 @@ void grib_accessor_class_bitmap_t::init(grib_accessor* a, const long len, grib_a compute_size(a); } -long grib_accessor_class_bitmap_t::next_offset(grib_accessor* a){ - return a->byte_offset() + a->byte_count();} +long grib_accessor_class_bitmap_t::next_offset(grib_accessor* a) +{ + return a->byte_offset() + a->byte_count(); +} -void grib_accessor_class_bitmap_t::dump(grib_accessor* a, grib_dumper* dumper){ +void grib_accessor_class_bitmap_t::dump(grib_accessor* a, grib_dumper* dumper) +{ long len = 0; char label[1024]; a->value_count(&len); - snprintf(label, 1024, "Bitmap of %ld values", len); + snprintf(label, sizeof(label), "Bitmap of %ld values", len); grib_dump_bytes(dumper, a, label); } -int grib_accessor_class_bitmap_t::unpack_long(grib_accessor* a, long* val, size_t* len){ +int grib_accessor_class_bitmap_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ long pos = a->offset * 8; long tlen = 0; const grib_handle* hand = grib_handle_of_accessor(a); - int err = a->value_count(&tlen); if (err) + int err = a->value_count(&tlen); + if (err) return err; if (*len < tlen) { @@ -99,13 +104,15 @@ int grib_accessor_class_bitmap_t::unpack_long(grib_accessor* a, long* val, size_ } template -int unpack(grib_accessor* a, T* val, size_t* len){ +int unpack(grib_accessor* a, T* val, size_t* len) +{ static_assert(std::is_floating_point::value, "Requires floating points numbers"); long pos = a->offset * 8; long tlen; grib_handle* hand = grib_handle_of_accessor(a); - int err = a->value_count(&tlen); if (err) + int err = a->value_count(&tlen); + if (err) return err; if (*len < tlen) { @@ -121,15 +128,18 @@ int unpack(grib_accessor* a, T* val, size_t* len){ return GRIB_SUCCESS; } -int grib_accessor_class_bitmap_t::unpack_double(grib_accessor* a, double* val, size_t* len){ +int grib_accessor_class_bitmap_t::unpack_double(grib_accessor* a, double* val, size_t* len) +{ return unpack(a, val, len); } -int grib_accessor_class_bitmap_t::unpack_float(grib_accessor* a, float* val, size_t* len){ +int grib_accessor_class_bitmap_t::unpack_float(grib_accessor* a, float* val, size_t* len) +{ return unpack(a, val, len); } -int grib_accessor_class_bitmap_t::unpack_double_element(grib_accessor* a, size_t idx, double* val){ +int grib_accessor_class_bitmap_t::unpack_double_element(grib_accessor* a, size_t idx, double* val) +{ long pos = a->offset * 8; pos += idx; @@ -137,24 +147,28 @@ int grib_accessor_class_bitmap_t::unpack_double_element(grib_accessor* a, size_t return GRIB_SUCCESS; } -int grib_accessor_class_bitmap_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array){ - for (size_t i=0; ilength = s; } -size_t grib_accessor_class_bitmap_t::string_length(grib_accessor* a){ +size_t grib_accessor_class_bitmap_t::string_length(grib_accessor* a) +{ return a->length; } -int grib_accessor_class_bitmap_t::unpack_string(grib_accessor* a, char* val, size_t* len){ +int grib_accessor_class_bitmap_t::unpack_string(grib_accessor* a, char* val, size_t* len) +{ grib_handle* hand = grib_handle_of_accessor(a); - const size_t l = a->length; + const size_t l = a->length; if (*len < l) { const char* cclass_name = a->cclass->name; diff --git a/src/accessor/grib_accessor_class_bits_per_value.cc b/src/accessor/grib_accessor_class_bits_per_value.cc index 590c48d89..dbdef54cb 100644 --- a/src/accessor/grib_accessor_class_bits_per_value.cc +++ b/src/accessor/grib_accessor_class_bits_per_value.cc @@ -11,24 +11,27 @@ #include "grib_accessor_class_bits_per_value.h" -grib_accessor_class_bits_per_value_t _grib_accessor_class_bits_per_value{"bits_per_value"}; +grib_accessor_class_bits_per_value_t _grib_accessor_class_bits_per_value{ "bits_per_value" }; grib_accessor_class* grib_accessor_class_bits_per_value = &_grib_accessor_class_bits_per_value; -void grib_accessor_class_bits_per_value_t::init(grib_accessor* a, const long l, grib_arguments* args){ +void grib_accessor_class_bits_per_value_t::init(grib_accessor* a, const long l, grib_arguments* args) +{ grib_accessor_class_long_t::init(a, l, args); - int n = 0; + int n = 0; grib_accessor_bits_per_value_t* self = (grib_accessor_bits_per_value_t*)a; - self->values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - self->bits_per_value = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); + self->values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); + self->bits_per_value = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; a->length = 0; } -int grib_accessor_class_bits_per_value_t::unpack_long(grib_accessor* a, long* val, size_t* len){ - int ret = 0; +int grib_accessor_class_bits_per_value_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ grib_accessor_bits_per_value_t* self = (grib_accessor_bits_per_value_t*)a; - grib_handle* h = grib_handle_of_accessor(a); + + int ret = 0; + grib_handle* h = grib_handle_of_accessor(a); if ((ret = grib_get_long_internal(h, self->bits_per_value, val)) != GRIB_SUCCESS) return ret; @@ -37,13 +40,15 @@ int grib_accessor_class_bits_per_value_t::unpack_long(grib_accessor* a, long* va return ret; } -int grib_accessor_class_bits_per_value_t::pack_long(grib_accessor* a, const long* val, size_t* len){ - double* values = NULL; - size_t size = 0; - int ret = 0; +int grib_accessor_class_bits_per_value_t::pack_long(grib_accessor* a, const long* val, size_t* len) +{ grib_accessor_bits_per_value_t* self = (grib_accessor_bits_per_value_t*)a; - grib_context* c = a->context; - grib_handle* h = grib_handle_of_accessor(a); + + double* values = NULL; + size_t size = 0; + int ret = 0; + grib_context* c = a->context; + grib_handle* h = grib_handle_of_accessor(a); if ((ret = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) return ret; diff --git a/src/accessor/grib_accessor_class_bufr_data_array.cc b/src/accessor/grib_accessor_class_bufr_data_array.cc index 14f13d966..e0c998950 100644 --- a/src/accessor/grib_accessor_class_bufr_data_array.cc +++ b/src/accessor/grib_accessor_class_bufr_data_array.cc @@ -34,28 +34,32 @@ grib_accessor_class* grib_accessor_class_bufr_data_array = &_grib_accessor_class return retval; \ } -int process_elements(grib_accessor* a, int flag, long onlySubset, long startSubset, long endSubset); +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); -int create_keys(const grib_accessor* a, long onlySubset, long startSubset, long endSubset); -void restart_bitmap(grib_accessor_bufr_data_array_t* self){ +static void restart_bitmap(grib_accessor_bufr_data_array_t* self) +{ self->bitmapCurrent = -1; self->bitmapCurrentElementsDescriptorsIndex = self->bitmapStartElementsDescriptorsIndex - 1; } -void cancel_bitmap(grib_accessor_bufr_data_array_t* self){ +static void cancel_bitmap(grib_accessor_bufr_data_array_t* self) +{ self->bitmapCurrent = -1; self->bitmapStart = -1; } -int is_bitmap_start_defined(grib_accessor_bufr_data_array_t* self){ +static int is_bitmap_start_defined(grib_accessor_bufr_data_array_t* self) +{ return self->bitmapStart == -1 ? 0 : 1; } -size_t get_length(grib_accessor* a){ +size_t get_length(grib_accessor* a) +{ grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; - size_t len = 0; + size_t len = 0; const grib_handle* h = grib_handle_of_accessor(a); @@ -65,7 +69,8 @@ size_t get_length(grib_accessor* a){ } /* Operator 203YYY: Store the TableB code and changed reference value in linked list */ -void tableB_override_store_ref_val(grib_context* c, grib_accessor_bufr_data_array_t* self, int code, long new_ref_val){ +static void tableB_override_store_ref_val(grib_context* c, grib_accessor_bufr_data_array_t* self, 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; @@ -82,7 +87,8 @@ void tableB_override_store_ref_val(grib_context* c, grib_accessor_bufr_data_arra } /* Operator 203YYY: Retrieve changed reference value from linked list */ -int tableB_override_get_ref_val(grib_accessor_bufr_data_array_t* self, int code, long* out_ref_val){ +static int tableB_override_get_ref_val(grib_accessor_bufr_data_array_t* self, int code, long* out_ref_val) +{ bufr_tableb_override* p = self->tableb_override; while (p) { if (p->code == code) { @@ -95,7 +101,8 @@ int tableB_override_get_ref_val(grib_accessor_bufr_data_array_t* self, int code, } /* Operator 203YYY: Clear and free linked list */ -void tableB_override_clear(grib_context* c, grib_accessor_bufr_data_array_t* self){ +void tableB_override_clear(grib_context* c, grib_accessor_bufr_data_array_t* self) +{ bufr_tableb_override* tb = self->tableb_override; while (tb) { bufr_tableb_override* n = tb->next; @@ -106,7 +113,8 @@ void tableB_override_clear(grib_context* c, grib_accessor_bufr_data_array_t* sel } /* Operator 203YYY: Copy contents of linked list to the transient array key */ -int tableB_override_set_key(grib_handle* h, grib_accessor_bufr_data_array_t* self){ +int tableB_override_set_key(grib_handle* h, grib_accessor_bufr_data_array_t* self) +{ int err = GRIB_SUCCESS; size_t size = 0; long* refVals = NULL; @@ -126,7 +134,8 @@ int tableB_override_set_key(grib_handle* h, grib_accessor_bufr_data_array_t* sel return err; } /* Check numBits is sufficient for entries in the overridden reference values list*/ -int check_overridden_reference_values(const grib_context* c, long* refValList, size_t refValListSize, int numBits){ +static int check_overridden_reference_values(const grib_context* c, long* refValList, size_t refValListSize, int numBits) +{ const long maxval = (1 << (numBits - 1)) - 1; const long minval = -(1 << (numBits - 1)); size_t i = 0; @@ -205,7 +214,8 @@ void grib_accessor_class_bufr_data_array_t::init(grib_accessor* a, const long v, // } // } -int check_end_data(grib_context* c, bufr_descriptor* bd, grib_accessor_bufr_data_array_t* self, int size){ +static 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) grib_context_log(c, GRIB_LOG_DEBUG, "BUFR data decoding: \tbitsToEndData=%d elementSize=%d", self->bitsToEndData, size); @@ -302,7 +312,8 @@ void accessor_bufr_data_array_set_unpackMode(grib_accessor* a, int unpackMode) self->unpackMode = unpackMode; } -int get_descriptors(grib_accessor* a){ +static int get_descriptors(grib_accessor* a) +{ 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); @@ -328,7 +339,7 @@ int get_descriptors(grib_accessor* a){ return ret; } -int decode_string_array(grib_context* c, unsigned char* data, long* pos, bufr_descriptor* bd, +static int decode_string_array(grib_context* c, unsigned char* data, long* pos, bufr_descriptor* bd, grib_accessor_bufr_data_array_t* self) { int ret = 0; @@ -469,7 +480,7 @@ grib_darray* decode_double_array(grib_context* c, unsigned char* data, long* pos return ret; } -int encode_string_array(grib_context* c, grib_buffer* buff, long* pos, bufr_descriptor* bd, +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 err = 0, n, ival; @@ -535,7 +546,7 @@ void set_missing_long_to_double(grib_darray* dvalues){ } /* ECC-750: The 'factor' argument is 10^-scale */ -int descriptor_get_min_max(bufr_descriptor* bd, long width, long reference, double factor, +static int descriptor_get_min_max(bufr_descriptor* bd, long width, long reference, double factor, double* minAllowed, double* maxAllowed) { /* Maximum value is allowed to be the largest number (all bits 1) which means it's MISSING */ @@ -551,7 +562,7 @@ int descriptor_get_min_max(bufr_descriptor* bd, long width, long reference, doub return GRIB_SUCCESS; } -int encode_double_array(grib_context* c, grib_buffer* buff, long* pos, bufr_descriptor* bd, +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 err = 0; @@ -769,7 +780,7 @@ int encode_double_array(grib_context* c, grib_buffer* buff, long* pos, bufr_desc return err; } -int encode_double_value(grib_context* c, grib_buffer* buff, long* pos, bufr_descriptor* bd, +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) { size_t lval; @@ -816,7 +827,7 @@ int encode_double_value(grib_context* c, grib_buffer* buff, long* pos, bufr_desc return err; } -int encode_string_value(grib_context* c, grib_buffer* buff, long* pos, bufr_descriptor* bd, +static int encode_string_value(grib_context* c, grib_buffer* buff, long* pos, bufr_descriptor* bd, grib_accessor_bufr_data_array_t* self, char* sval) { int err = 0; @@ -832,7 +843,7 @@ int encode_string_value(grib_context* c, grib_buffer* buff, long* pos, bufr_desc return err; } -char* decode_string_value(grib_context* c, unsigned char* data, long* pos, bufr_descriptor* bd, +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* sval = 0; @@ -855,7 +866,7 @@ char* decode_string_value(grib_context* c, unsigned char* data, long* pos, bufr_ return sval; } -double decode_double_value(grib_context* c, unsigned char* data, long* pos, +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) { @@ -886,7 +897,7 @@ double decode_double_value(grib_context* c, unsigned char* data, long* pos, return dval; } -int decode_element(grib_context* c, grib_accessor_bufr_data_array_t* self, int subsetIndex, +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) { @@ -968,7 +979,7 @@ int decode_element(grib_context* c, grib_accessor_bufr_data_array_t* self, int s return err; } -int decode_replication(grib_context* c, grib_accessor_bufr_data_array_t* self, int subsetIndex, +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 ret = 0; @@ -1033,7 +1044,8 @@ int decode_replication(grib_context* c, grib_accessor_bufr_data_array_t* self, i return ret; } -int encode_new_bitmap(grib_context* c, grib_buffer* buff, long* pos, int idx, grib_accessor_bufr_data_array_t* self){ +static int encode_new_bitmap(grib_context* c, grib_buffer* buff, long* pos, int idx, grib_accessor_bufr_data_array_t* self) +{ grib_darray* doubleValues = NULL; int err = 0; double cdval = 0; @@ -1055,7 +1067,7 @@ int encode_new_bitmap(grib_context* c, grib_buffer* buff, long* pos, int idx, gr } /* Operator 203YYY: Change Reference Values: Encoding definition phase */ -int encode_overridden_reference_value(grib_context* c, grib_accessor_bufr_data_array_t* self, +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 err = 0; @@ -1094,7 +1106,7 @@ int encode_overridden_reference_value(grib_context* c, grib_accessor_bufr_data_a return err; } -int encode_new_element(grib_context* c, grib_accessor_bufr_data_array_t* self, int subsetIndex, +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) { @@ -1154,7 +1166,7 @@ int encode_new_element(grib_context* c, grib_accessor_bufr_data_array_t* self, i return err; } -int encode_new_replication(grib_context* c, grib_accessor_bufr_data_array_t* self, int subsetIndex, +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 err = 0; @@ -1217,7 +1229,7 @@ int encode_new_replication(grib_context* c, grib_accessor_bufr_data_array_t* sel return err; } -int encode_element(grib_context* c, grib_accessor_bufr_data_array_t* self, int subsetIndex, +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) { @@ -1288,7 +1300,7 @@ int encode_element(grib_context* c, grib_accessor_bufr_data_array_t* self, int s return err; } -int encode_replication(grib_context* c, grib_accessor_bufr_data_array_t* self, int subsetIndex, +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) { @@ -1304,7 +1316,7 @@ int encode_replication(grib_context* c, grib_accessor_bufr_data_array_t* self, i return encode_element(c, self, subsetIndex, buff, data, pos, i, 0, elementIndex, dval, 0); } -int build_bitmap(grib_accessor_bufr_data_array_t* self, unsigned char* data, long* pos, +static int build_bitmap(grib_accessor_bufr_data_array_t* self, unsigned char* data, long* pos, int iel, grib_iarray* elementsDescriptorsIndex, int iBitmapOperator) { int bitmapSize = 0, iDelayedReplication = 0; @@ -1402,7 +1414,8 @@ int build_bitmap(grib_accessor_bufr_data_array_t* self, unsigned char* data, lon return GRIB_SUCCESS; } -int consume_bitmap(grib_accessor_bufr_data_array_t* self, int iBitmapOperator){ +static int consume_bitmap(grib_accessor_bufr_data_array_t* self, int iBitmapOperator) +{ int bitmapSize = 0, iDelayedReplication; int i; bufr_descriptor** descriptors = self->expanded->v; @@ -1432,7 +1445,7 @@ int consume_bitmap(grib_accessor_bufr_data_array_t* self, int iBitmapOperator){ return GRIB_SUCCESS; } -int build_bitmap_new_data(grib_accessor_bufr_data_array_t* self, unsigned char* data, long* pos, +static int build_bitmap_new_data(grib_accessor_bufr_data_array_t* self, unsigned char* data, long* pos, int iel, grib_iarray* elementsDescriptorsIndex, int iBitmapOperator) { int bitmapSize = 0, iDelayedReplication = 0; @@ -1519,7 +1532,8 @@ int build_bitmap_new_data(grib_accessor_bufr_data_array_t* self, unsigned char* } /* ECC-1304: Will return an index if successful. In case of an error, a negative number is returned e.g. GRIB_WRONG_BITMAP_SIZE */ -int get_next_bitmap_descriptor_index_new_bitmap(grib_accessor_bufr_data_array_t* self, grib_iarray* elementsDescriptorsIndex, int compressedData){ +static int get_next_bitmap_descriptor_index_new_bitmap(grib_accessor_bufr_data_array_t* self, grib_iarray* elementsDescriptorsIndex, int compressedData) +{ int i; bufr_descriptor** descriptors = self->expanded->v; @@ -1556,7 +1570,8 @@ int get_next_bitmap_descriptor_index_new_bitmap(grib_accessor_bufr_data_array_t* } /* ECC-1304: Will return an index if successful. In case of an error, a negative number is returned e.g. GRIB_WRONG_BITMAP_SIZE */ -int get_next_bitmap_descriptor_index(grib_accessor_bufr_data_array_t* self, grib_iarray* elementsDescriptorsIndex, grib_darray* numericValues){ +static int get_next_bitmap_descriptor_index(grib_accessor_bufr_data_array_t* self, grib_iarray* elementsDescriptorsIndex, grib_darray* numericValues) +{ int i; bufr_descriptor** descriptors = self->expanded->v; @@ -1597,7 +1612,8 @@ int get_next_bitmap_descriptor_index(grib_accessor_bufr_data_array_t* self, grib return elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex]; } -void push_zero_element(grib_accessor_bufr_data_array_t* self, grib_darray* dval){ +static void push_zero_element(grib_accessor_bufr_data_array_t* self, grib_darray* dval) +{ grib_darray* d = 0; grib_accessor* a = (grib_accessor*)self; grib_context* c = a->context; @@ -1611,7 +1627,7 @@ void push_zero_element(grib_accessor_bufr_data_array_t* self, grib_darray* dval) } } -grib_accessor* create_attribute_variable(const char* name, grib_section* section, int type, char* sval, double dval, long lval, unsigned long flags) +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* a = NULL; grib_action creator = {0,}; @@ -1644,7 +1660,8 @@ grib_accessor* create_attribute_variable(const char* name, grib_section* section return a; } -void set_creator_name(grib_action* creator, int code){ +static void set_creator_name(grib_action* creator, int code) +{ switch (code) { case 222000: creator->name = (char*)"qualityInformationFollows"; @@ -1716,7 +1733,8 @@ void set_creator_name(grib_action* creator, int code){ } /* See ECC-741 */ -int adding_extra_key_attributes(grib_handle* h){ +static int adding_extra_key_attributes(grib_handle* h) +{ long skip = 0; /* default is to add */ int err = 0; err = grib_get_long(h, "skipExtraKeyAttributes", &skip); @@ -1725,7 +1743,7 @@ int adding_extra_key_attributes(grib_handle* h){ return (!skip); } -grib_accessor* create_accessor_from_descriptor(const grib_accessor* a, grib_accessor* attribute, grib_section* section, +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) { @@ -1978,7 +1996,8 @@ static grib_accessor* get_element_from_bitmap(const grib_accessor* a, bitmap_s* // significanceQualifierGroup[i]=0; // } -void grib_convert_to_attribute(grib_accessor* a){ +static void grib_convert_to_attribute(grib_accessor* a) +{ if (a->h == NULL && a->parent != NULL) { a->h = grib_handle_of_accessor(a); a->parent = NULL; @@ -2025,7 +2044,8 @@ static grib_iarray* set_subset_list( return list; } -int bitmap_ref_skip(grib_accessors_list* al, int* err){ +static int bitmap_ref_skip(grib_accessors_list* al, int* err) +{ grib_accessor* acode = NULL; long code[1]; size_t l = 1; @@ -2057,7 +2077,8 @@ int bitmap_ref_skip(grib_accessors_list* al, int* err){ } /* Return 1 if the descriptor is an operator marking the start of a bitmap */ -int is_bitmap_start_descriptor(grib_accessors_list* al, int* err){ +static int is_bitmap_start_descriptor(grib_accessors_list* al, int* err) +{ grib_accessor* acode = NULL; long code[1]; size_t l = 1; @@ -2089,7 +2110,8 @@ int is_bitmap_start_descriptor(grib_accessors_list* al, int* err){ return 0; } -void print_bitmap_debug_info(grib_context* c, bitmap_s* bitmap, grib_accessors_list* bitmapStart, int bitmapSize){ +static void print_bitmap_debug_info(grib_context* c, bitmap_s* bitmap, grib_accessors_list* bitmapStart, int bitmapSize) +{ int i = 0, ret = 0; fprintf(stderr, "ECCODES DEBUG: bitmap_init: bitmapSize=%d\n", bitmapSize); bitmap->cursor = bitmapStart->next_; @@ -2180,11 +2202,13 @@ static grib_accessor* accessor_or_attribute_with_same_name(grib_accessor* a, con // return *r; // } -int grib_data_accessors_trie_push(grib_trie_with_rank* accessorsTrie, grib_accessor* a){ +int grib_data_accessors_trie_push(grib_trie_with_rank* accessorsTrie, grib_accessor* a) +{ return grib_trie_with_rank_insert(accessorsTrie, a->name, a); } -int create_keys(const grib_accessor* a, long onlySubset, long startSubset, long endSubset){ +static int create_keys(const grib_accessor* a, long onlySubset, long startSubset, long endSubset) +{ grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; int err = 0; int rank; @@ -2509,7 +2533,8 @@ int create_keys(const grib_accessor* a, long onlySubset, long startSubset, long return err; } -void set_input_replications(grib_handle* h, grib_accessor_bufr_data_array_t* self){ +static void set_input_replications(grib_handle* h, grib_accessor_bufr_data_array_t* self) +{ size_t nInputReplications; size_t nInputExtendedReplications; size_t nInputShortReplications; @@ -2554,7 +2579,8 @@ void set_input_replications(grib_handle* h, grib_accessor_bufr_data_array_t* sel } } -void set_input_bitmap(grib_handle* h, grib_accessor_bufr_data_array_t* self){ +static void set_input_bitmap(grib_handle* h, grib_accessor_bufr_data_array_t* self) +{ size_t nInputBitmap; self->nInputBitmap = -1; self->iInputBitmap = 0; @@ -2571,7 +2597,8 @@ void set_input_bitmap(grib_handle* h, grib_accessor_bufr_data_array_t* self){ } } -int set_to_missing_if_out_of_range(grib_handle* h){ +static int set_to_missing_if_out_of_range(grib_handle* h) +{ /* First check if the transient key is set */ long setToMissingIfOutOfRange = 0; if (grib_get_long(h, "setToMissingIfOutOfRange", &setToMissingIfOutOfRange) == GRIB_SUCCESS && @@ -2582,7 +2609,8 @@ int set_to_missing_if_out_of_range(grib_handle* h){ return h->context->bufr_set_to_missing_if_out_of_range; } -int process_elements(grib_accessor* a, int flag, long onlySubset, long startSubset, long endSubset){ +static int process_elements(grib_accessor* a, int flag, long onlySubset, long startSubset, long endSubset) +{ int err = 0; long inr, innr, ir, ip; long n[MAX_NESTED_REPLICATIONS] = {0,}; diff --git a/src/accessor/grib_accessor_class_bufr_elements_table.cc b/src/accessor/grib_accessor_class_bufr_elements_table.cc index 42e7a1324..ddd055544 100644 --- a/src/accessor/grib_accessor_class_bufr_elements_table.cc +++ b/src/accessor/grib_accessor_class_bufr_elements_table.cc @@ -41,13 +41,14 @@ void thread_init() #endif -grib_accessor_class_bufr_elements_table_t _grib_accessor_class_bufr_elements_table{"bufr_elements_table"}; +grib_accessor_class_bufr_elements_table_t _grib_accessor_class_bufr_elements_table{ "bufr_elements_table" }; grib_accessor_class* grib_accessor_class_bufr_elements_table = &_grib_accessor_class_bufr_elements_table; -void grib_accessor_class_bufr_elements_table_t::init(grib_accessor* a, const long len, grib_arguments* params){ +void grib_accessor_class_bufr_elements_table_t::init(grib_accessor* a, const long len, grib_arguments* params) +{ grib_accessor_class_gen_t::init(a, len, params); - int n = 0; + int n = 0; grib_accessor_bufr_elements_table_t* self = (grib_accessor_bufr_elements_table_t*)a; self->dictionary = grib_arguments_get_string(grib_handle_of_accessor(a), params, n++); @@ -68,7 +69,9 @@ static grib_trie* load_bufr_elements_table(grib_accessor* a, int* err) char localDir[1024] = {0,}; char dictName[1024] = {0,}; char masterRecomposed[1024] = {0,}; /*e.g. bufr/tables/0/wmo/36/element.table */ - char localRecomposed[1024] = {0,}; /*e.g. bufr/tables/0/local/0/98/0/element.table */ + char localRecomposed[1024] = { + 0, + }; /*e.g. bufr/tables/0/local/0/98/0/element.table */ char* localFilename = 0; char** list = 0; char** cached_list = 0; @@ -113,9 +116,9 @@ 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); - if (strlen(masterRecomposed) > 0) grib_context_log(c, GRIB_LOG_DEBUG,"master path=%s", masterRecomposed); + 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; + *err = GRIB_FILE_NOT_FOUND; dictionary = NULL; goto the_end; } @@ -139,7 +142,7 @@ static grib_trie* load_bufr_elements_table(grib_accessor* a, int* err) dictionary = grib_trie_new(c); while (fgets(line, sizeof(line) - 1, f)) { - DEBUG_ASSERT( strlen(line) > 0 ); + DEBUG_ASSERT(strlen(line) > 0); if (line[0] == '#') continue; /* Ignore first line with column titles */ list = string_split(line, "|"); grib_trie_insert(dictionary, list[0], list); @@ -156,14 +159,15 @@ static grib_trie* load_bufr_elements_table(grib_accessor* a, int* err) } while (fgets(line, sizeof(line) - 1, f)) { - DEBUG_ASSERT( strlen(line) > 0 ); - if (line[0] == '#') continue; /* Ignore first line with column titles */ + DEBUG_ASSERT(strlen(line) > 0); + if (line[0] == '#') continue; /* Ignore first line with column titles */ list = string_split(line, "|"); /* Look for the descriptor code in the trie. It might be there from before */ cached_list = (char**)grib_trie_get(dictionary, list[0]); if (cached_list) { /* If found, we are about to overwrite it. So free memory */ int i; - for (i = 0; cached_list[i] != NULL; ++i) free(cached_list[i]); + for (i = 0; cached_list[i] != NULL; ++i) + free(cached_list[i]); free(cached_list); } grib_trie_insert(dictionary, list[0], list); @@ -178,7 +182,8 @@ static grib_trie* load_bufr_elements_table(grib_accessor* a, int* err) return dictionary; } -int convert_type(const char* stype){ +static int convert_type(const char* stype) +{ int ret = BUFR_DESCRIPTOR_TYPE_UNKNOWN; switch (stype[0]) { case 's': @@ -208,16 +213,18 @@ int convert_type(const char* stype){ return ret; } -long atol_fast(const char* input){ +long atol_fast(const char* input) +{ if (strcmp(input, "0") == 0) return 0; return atol(input); } -int bufr_get_from_table(grib_accessor* a, bufr_descriptor* v){ - int ret = 0; - char** list = 0; - char code[7] = { 0 }; +int bufr_get_from_table(grib_accessor* a, 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); @@ -235,8 +242,8 @@ int bufr_get_from_table(grib_accessor* a, bufr_descriptor* v){ /* ECC-1137: check descriptor key name and unit lengths */ const size_t maxlen_shortName = sizeof(v->shortName); const size_t maxlen_units = sizeof(v->units); - Assert( strlen(list[1]) < maxlen_shortName ); - Assert( strlen(list[4]) < maxlen_units ); + Assert(strlen(list[1]) < maxlen_shortName); + Assert(strlen(list[4]) < maxlen_units); } #endif @@ -310,23 +317,28 @@ bufr_descriptor* accessor_bufr_elements_table_get_descriptor(grib_accessor* a, i return v; } -int grib_accessor_class_bufr_elements_table_t::unpack_string(grib_accessor* a, char* buffer, size_t* len){ +int grib_accessor_class_bufr_elements_table_t::unpack_string(grib_accessor* a, char* buffer, size_t* len) +{ return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_bufr_elements_table_t::value_count(grib_accessor* a, long* count){ +int grib_accessor_class_bufr_elements_table_t::value_count(grib_accessor* a, long* count) +{ *count = 1; return 0; } -int grib_accessor_class_bufr_elements_table_t::get_native_type(grib_accessor* a){ +int grib_accessor_class_bufr_elements_table_t::get_native_type(grib_accessor* a) +{ return GRIB_TYPE_STRING; } -int grib_accessor_class_bufr_elements_table_t::unpack_long(grib_accessor* a, long* val, size_t* len){ +int grib_accessor_class_bufr_elements_table_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_bufr_elements_table_t::unpack_double(grib_accessor* a, double* val, size_t* len){ +int grib_accessor_class_bufr_elements_table_t::unpack_double(grib_accessor* a, double* val, size_t* len) +{ return GRIB_NOT_IMPLEMENTED; } 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 9a2310635..91a34c72c 100644 --- a/src/accessor/grib_accessor_class_bufr_extract_area_subsets.cc +++ b/src/accessor/grib_accessor_class_bufr_extract_area_subsets.cc @@ -11,15 +11,16 @@ #include "grib_accessor_class_bufr_extract_area_subsets.h" -grib_accessor_class_bufr_extract_area_subsets_t _grib_accessor_class_bufr_extract_area_subsets{"bufr_extract_area_subsets"}; +grib_accessor_class_bufr_extract_area_subsets_t _grib_accessor_class_bufr_extract_area_subsets{ "bufr_extract_area_subsets" }; grib_accessor_class* grib_accessor_class_bufr_extract_area_subsets = &_grib_accessor_class_bufr_extract_area_subsets; -void grib_accessor_class_bufr_extract_area_subsets_t::init(grib_accessor* a, const long len, grib_arguments* arg){ +void grib_accessor_class_bufr_extract_area_subsets_t::init(grib_accessor* a, const long len, grib_arguments* arg) +{ grib_accessor_class_gen_t::init(a, len, arg); grib_accessor_bufr_extract_area_subsets_t* self = (grib_accessor_bufr_extract_area_subsets_t*)a; - grib_handle* h = grib_handle_of_accessor(a); - int n = 0; + grib_handle* h = grib_handle_of_accessor(a); + int n = 0; a->length = 0; self->doExtractSubsets = grib_arguments_get_name(h, arg, n++); @@ -36,23 +37,26 @@ void grib_accessor_class_bufr_extract_area_subsets_t::init(grib_accessor* a, con a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; } -int grib_accessor_class_bufr_extract_area_subsets_t::get_native_type(grib_accessor* a){ +int grib_accessor_class_bufr_extract_area_subsets_t::get_native_type(grib_accessor* a) +{ return GRIB_TYPE_LONG; } /* Copy first element of array into all others */ -void fill_in(double a[], long length){ +static void fill_in(double a[], long length) +{ long i; for (i = 1; i < length; ++i) a[i] = a[0]; } -int select_area(grib_accessor* a){ +static int select_area(grib_accessor* a) +{ grib_accessor_bufr_extract_area_subsets_t* self = (grib_accessor_bufr_extract_area_subsets_t*)a; - int ret = 0; + int ret = 0; long compressed = 0; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(a); grib_context* c = h->context; double* lat = NULL; @@ -61,8 +65,8 @@ int select_area(grib_accessor* a){ double lonWest, lonEast, latNorth, latSouth; long numberOfSubsets, i, latRank, lonRank; grib_iarray* subsets = NULL; - size_t nsubsets = 0; - char latstr[32] = {0,}; + size_t nsubsets = 0; + char latstr[32] = {0,}; char lonstr[32] = {0,}; ret = grib_get_long(h, "compressedData", &compressed); @@ -160,7 +164,7 @@ int select_area(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, self->extractSubsetList, subsets_ar, nsubsets); grib_context_free(c, subsets_ar); if (ret) return ret; @@ -176,7 +180,8 @@ int select_area(grib_accessor* a){ return ret; } -int grib_accessor_class_bufr_extract_area_subsets_t::pack_long(grib_accessor* a, const long* val, size_t* len){ +int grib_accessor_class_bufr_extract_area_subsets_t::pack_long(grib_accessor* a, 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) 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 368f49f0c..d47652984 100644 --- a/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.cc +++ b/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.cc @@ -11,13 +11,14 @@ #include "grib_accessor_class_bufr_extract_datetime_subsets.h" -grib_accessor_class_bufr_extract_datetime_subsets_t _grib_accessor_class_bufr_extract_datetime_subsets{"bufr_extract_datetime_subsets"}; +grib_accessor_class_bufr_extract_datetime_subsets_t _grib_accessor_class_bufr_extract_datetime_subsets{ "bufr_extract_datetime_subsets" }; grib_accessor_class* grib_accessor_class_bufr_extract_datetime_subsets = &_grib_accessor_class_bufr_extract_datetime_subsets; -void grib_accessor_class_bufr_extract_datetime_subsets_t::init(grib_accessor* a, const long len, grib_arguments* arg){ +void grib_accessor_class_bufr_extract_datetime_subsets_t::init(grib_accessor* a, const long len, grib_arguments* arg) +{ grib_accessor_class_gen_t::init(a, len, arg); - int n = 0; + int n = 0; grib_accessor_bufr_extract_datetime_subsets_t* self = (grib_accessor_bufr_extract_datetime_subsets_t*)a; a->length = 0; @@ -28,12 +29,14 @@ void grib_accessor_class_bufr_extract_datetime_subsets_t::init(grib_accessor* a, a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; } -int grib_accessor_class_bufr_extract_datetime_subsets_t::get_native_type(grib_accessor* a){ +int grib_accessor_class_bufr_extract_datetime_subsets_t::get_native_type(grib_accessor* a) +{ return GRIB_TYPE_LONG; } /* Convert input date to Julian number. If date is invalid, return -1 */ -double date_to_julian(long year, long month, long day, long hour, long minute, double second){ +double date_to_julian(long year, long month, long day, long hour, long minute, double second) +{ double result = 0; /* Julian number in units of days */ /* For validating the date/time, we specify seconds as an integer */ @@ -85,7 +88,9 @@ static int build_long_array(grib_context* c, grib_handle* h, int compressed, } else { /* uncompressed */ - char keystr[32] = {0,}; + char keystr[32] = { + 0, + }; size_t values_len = 0; for (i = 0; i < numberOfSubsets; ++i) { long lVal = 0; @@ -104,15 +109,24 @@ static int build_long_array(grib_context* c, grib_handle* h, int compressed, return err; } -int select_datetime(grib_accessor* a){ - int ret = 0; - long compressed = 0; +static int select_datetime(grib_accessor* a) +{ + int ret = 0; + long compressed = 0; grib_accessor_bufr_extract_datetime_subsets_t* self = (grib_accessor_bufr_extract_datetime_subsets_t*)a; - grib_handle* h = grib_handle_of_accessor(a); - grib_context* c = h->context; + grib_handle* h = grib_handle_of_accessor(a); + grib_context* c = h->context; size_t n; double julianStart = 0, julianEnd = 0, julianDT = 0; - char start_str[80] = {0,}, end_str[80] = {0,}, datetime_str[80] = {0,}; + char start_str[80] = { + 0, + }, + end_str[80] = { + 0, + }, + datetime_str[80] = { + 0, + }; long yearRank, monthRank, dayRank, hourRank, minuteRank, secondRank; long yearStart, monthStart, dayStart, hourStart, minuteStart, secondStart; long yearEnd, monthEnd, dayEnd, hourEnd, minuteEnd, secondEnd; @@ -120,13 +134,13 @@ int select_datetime(grib_accessor* a){ double* second = NULL; long numberOfSubsets, i; grib_iarray* subsets = NULL; - size_t nsubsets = 0; - char yearstr[32] = "year"; - char monthstr[32] = "month"; - char daystr[32] = "day"; - char hourstr[32] = "hour"; - char minutestr[32] = "minute"; - char secondstr[32] = "second"; + size_t nsubsets = 0; + char yearstr[32] = "year"; + char monthstr[32] = "month"; + char daystr[32] = "day"; + char hourstr[32] = "hour"; + char minutestr[32] = "minute"; + char secondstr[32] = "second"; ret = grib_get_long(h, "compressedData", &compressed); if (ret) return ret; @@ -265,7 +279,7 @@ int select_datetime(grib_accessor* a){ if (ret) secondEnd = 0; snprintf(end_str, sizeof(end_str), "%04ld/%02ld/%02ld %02ld:%02ld:%02ld", - yearEnd, monthEnd, dayEnd, hourEnd, minuteEnd, secondEnd); + yearEnd, monthEnd, dayEnd, hourEnd, minuteEnd, secondEnd); if (c->debug) fprintf(stderr, "ECCODES DEBUG bufr_extract_datetime_subsets: end =%s\n", end_str); julianEnd = date_to_julian(yearEnd, monthEnd, dayEnd, hourEnd, minuteEnd, secondEnd); if (julianEnd == -1) { @@ -311,7 +325,7 @@ 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, self->extractSubsetList, subsets_ar, nsubsets); grib_context_free(c, subsets_ar); if (ret) return ret; @@ -332,7 +346,8 @@ int select_datetime(grib_accessor* a){ return ret; } -int grib_accessor_class_bufr_extract_datetime_subsets_t::pack_long(grib_accessor* a, const long* val, size_t* len){ +int grib_accessor_class_bufr_extract_datetime_subsets_t::pack_long(grib_accessor* a, const long* val, size_t* len) +{ /*grib_accessor_bufr_extract_datetime_subsets_t *self =(grib_accessor_bufr_extract_datetime_subsets_t*)a;*/ if (*len == 0) diff --git a/src/accessor/grib_accessor_class_bufr_simple_thinning.cc b/src/accessor/grib_accessor_class_bufr_simple_thinning.cc index 2c66d4585..a74d7a74c 100644 --- a/src/accessor/grib_accessor_class_bufr_simple_thinning.cc +++ b/src/accessor/grib_accessor_class_bufr_simple_thinning.cc @@ -11,15 +11,16 @@ #include "grib_accessor_class_bufr_simple_thinning.h" -grib_accessor_class_bufr_simple_thinning_t _grib_accessor_class_bufr_simple_thinning{"bufr_simple_thinning"}; +grib_accessor_class_bufr_simple_thinning_t _grib_accessor_class_bufr_simple_thinning{ "bufr_simple_thinning" }; grib_accessor_class* grib_accessor_class_bufr_simple_thinning = &_grib_accessor_class_bufr_simple_thinning; -void grib_accessor_class_bufr_simple_thinning_t::init(grib_accessor* a, const long len, grib_arguments* arg){ +void grib_accessor_class_bufr_simple_thinning_t::init(grib_accessor* a, const long len, grib_arguments* arg) +{ grib_accessor_class_gen_t::init(a, len, arg); grib_accessor_bufr_simple_thinning_t* self = (grib_accessor_bufr_simple_thinning_t*)a; - grib_handle* h = grib_handle_of_accessor(a); - int n = 0; + grib_handle* h = grib_handle_of_accessor(a); + int n = 0; a->length = 0; self->doExtractSubsets = grib_arguments_get_name(h, arg, n++); @@ -32,11 +33,13 @@ void grib_accessor_class_bufr_simple_thinning_t::init(grib_accessor* a, const lo a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; } -int grib_accessor_class_bufr_simple_thinning_t::get_native_type(grib_accessor* a){ +int grib_accessor_class_bufr_simple_thinning_t::get_native_type(grib_accessor* a) +{ return GRIB_TYPE_LONG; } -int apply_thinning(grib_accessor* a){ +static int apply_thinning(grib_accessor* a) +{ const grib_accessor_bufr_simple_thinning_t* self = (grib_accessor_bufr_simple_thinning_t*)a; long skip; @@ -101,7 +104,8 @@ int apply_thinning(grib_accessor* a){ return ret; } -int grib_accessor_class_bufr_simple_thinning_t::pack_long(grib_accessor* a, const long* val, size_t* len){ +int grib_accessor_class_bufr_simple_thinning_t::pack_long(grib_accessor* a, const long* val, size_t* len) +{ const grib_accessor_bufr_simple_thinning_t* self = (grib_accessor_bufr_simple_thinning_t*)a; if (*len == 0) diff --git a/src/accessor/grib_accessor_class_codeflag.cc b/src/accessor/grib_accessor_class_codeflag.cc index 75b73aca4..6cfda6942 100644 --- a/src/accessor/grib_accessor_class_codeflag.cc +++ b/src/accessor/grib_accessor_class_codeflag.cc @@ -11,11 +11,12 @@ #include "grib_accessor_class_codeflag.h" -grib_accessor_class_codeflag_t _grib_accessor_class_codeflag{"codeflag"}; +grib_accessor_class_codeflag_t _grib_accessor_class_codeflag{ "codeflag" }; grib_accessor_class* grib_accessor_class_codeflag = &_grib_accessor_class_codeflag; -void grib_accessor_class_codeflag_t::init(grib_accessor* a, const long len, grib_arguments* param){ +void grib_accessor_class_codeflag_t::init(grib_accessor* a, const long len, grib_arguments* param) +{ grib_accessor_class_unsigned_t::init(a, len, param); grib_accessor_codeflag_t* self = (grib_accessor_codeflag_t*)a; a->length = len; @@ -23,12 +24,14 @@ void grib_accessor_class_codeflag_t::init(grib_accessor* a, const long len, grib Assert(a->length >= 0); } -int test_bit(long a, long b){ - DEBUG_ASSERT(b>=0); +static int test_bit(long a, long b) +{ + DEBUG_ASSERT(b >= 0); return a & (1 << b); } -int grib_get_codeflag(grib_accessor* a, long code, char* codename){ +static int grib_get_codeflag(grib_accessor* a, long code, char* codename) +{ const grib_accessor_codeflag_t* self = (grib_accessor_codeflag_t*)a; FILE* f = NULL; char fname[1024]; @@ -42,8 +45,8 @@ int grib_get_codeflag(grib_accessor* a, long code, char* codename){ err = grib_recompose_name(grib_handle_of_accessor(a), NULL, self->tablename, fname, 1); if (err) { - strncpy(fname, self->tablename, sizeof(fname)-1); - fname[sizeof(fname)-1] = '\0'; + strncpy(fname, self->tablename, sizeof(fname) - 1); + fname[sizeof(fname) - 1] = '\0'; } if ((filename = grib_context_full_defs_path(a->context, fname)) == NULL) { @@ -98,12 +101,14 @@ int grib_get_codeflag(grib_accessor* a, long code, char* codename){ return GRIB_SUCCESS; } -int grib_accessor_class_codeflag_t::value_count(grib_accessor* a, long* count){ +int grib_accessor_class_codeflag_t::value_count(grib_accessor* a, long* count) +{ *count = 1; return 0; } -void grib_accessor_class_codeflag_t::dump(grib_accessor* a, grib_dumper* dumper){ +void grib_accessor_class_codeflag_t::dump(grib_accessor* a, grib_dumper* dumper) +{ const grib_accessor_codeflag_t* self = (grib_accessor_codeflag_t*)a; long v = 0; char flagname[1024] = {0,}; diff --git a/src/accessor/grib_accessor_class_codetable.cc b/src/accessor/grib_accessor_class_codetable.cc index 552274e75..f21ef0f86 100644 --- a/src/accessor/grib_accessor_class_codetable.cc +++ b/src/accessor/grib_accessor_class_codetable.cc @@ -44,10 +44,7 @@ void thread_init() } #endif - - - -int grib_load_codetable(grib_context* c, const char* filename, const char* recomposed_name, size_t size, grib_codetable* t); +static int grib_load_codetable(grib_context* c, const char* filename, const char* recomposed_name, size_t size, grib_codetable* t); void grib_accessor_class_codetable_t::init(grib_accessor* a, const long len, grib_arguments* params) { @@ -145,6 +142,7 @@ GRIB_INLINE static int grib_inline_strcmp(const char* a, const char* b) return (*a == 0 && *b == 0) ? 0 : 1; } +// Cater for parameters being NULL static int str_eq(const char* a, const char* b) { if (a && b && (grib_inline_strcmp(a, b) == 0)) @@ -267,7 +265,7 @@ static grib_codetable* load_table(grib_accessor* a) return t; } -int grib_load_codetable(grib_context* c, const char* filename, +static int grib_load_codetable(grib_context* c, const char* filename, const char* recomposed_name, size_t size, grib_codetable* t) { char line[1024]; diff --git a/src/accessor/grib_accessor_class_concept.cc b/src/accessor/grib_accessor_class_concept.cc index a4261f8ee..98f0fb35c 100644 --- a/src/accessor/grib_accessor_class_concept.cc +++ b/src/accessor/grib_accessor_class_concept.cc @@ -11,7 +11,7 @@ #include "grib_accessor_class_concept.h" -grib_accessor_class_concept_t _grib_accessor_class_concept{"concept"}; +grib_accessor_class_concept_t _grib_accessor_class_concept{ "concept" }; grib_accessor_class* grib_accessor_class_concept = &_grib_accessor_class_concept; @@ -33,17 +33,20 @@ GRIB_INLINE static int grib_inline_strcmp(const char* a, const char* b) return (*a == 0 && *b == 0) ? 0 : 1; } -void grib_accessor_class_concept_t::init(grib_accessor* a, const long len, grib_arguments* args){ +void grib_accessor_class_concept_t::init(grib_accessor* a, const long len, grib_arguments* args) +{ grib_accessor_class_gen_t::init(a, len, args); a->length = 0; } -void grib_accessor_class_concept_t::dump(grib_accessor* a, grib_dumper* dumper){ +void grib_accessor_class_concept_t::dump(grib_accessor* a, grib_dumper* dumper) +{ grib_dump_string(dumper, a, NULL); } /* Return 1 (=True) or 0 (=False) */ -int concept_condition_expression_true(grib_handle* h, grib_concept_condition* c){ +static int concept_condition_expression_true(grib_handle* h, grib_concept_condition* c) +{ long lval; long lres = 0; int ok = FALSE; /* Boolean */ @@ -87,8 +90,9 @@ int concept_condition_expression_true(grib_handle* h, grib_concept_condition* c) } /* Return 1 (=True) or 0 (=False) */ -int concept_condition_iarray_true(grib_handle* h, grib_concept_condition* c){ - long* val = NULL; +static int concept_condition_iarray_true(grib_handle* h, grib_concept_condition* c) +{ + long* val = NULL; size_t size = 0, i; int ret; /* Boolean */ int err = 0; @@ -117,7 +121,8 @@ int concept_condition_iarray_true(grib_handle* h, grib_concept_condition* c){ } /* Return 1 (=True) or 0 (=False) */ -int concept_condition_true(grib_handle* h, grib_concept_condition* c){ +static int concept_condition_true(grib_handle* h, grib_concept_condition* c) +{ if (c->expression == NULL) return concept_condition_iarray_true(h, c); else @@ -158,8 +163,8 @@ static const char* concept_evaluate(grib_accessor* a) } #define MAX_NUM_CONCEPT_VALUES 40 - -int concept_conditions_expression_apply(grib_handle* h, grib_concept_condition* e, grib_values* values, grib_sarray* sa, int* n){ +static int concept_conditions_expression_apply(grib_handle* h, grib_concept_condition* e, grib_values* values, grib_sarray* sa, int* n) +{ long lres = 0; double dres = 0.0; int count = *n; @@ -190,27 +195,31 @@ int concept_conditions_expression_apply(grib_handle* h, grib_concept_condition* return err; } -int concept_conditions_iarray_apply(grib_handle* h, grib_concept_condition* c){ +static int concept_conditions_iarray_apply(grib_handle* h, grib_concept_condition* c) +{ size_t size = grib_iarray_used_size(c->iarray); return grib_set_long_array(h, c->name, c->iarray->v, size); } -int concept_conditions_apply(grib_handle* h, grib_concept_condition* c, grib_values* values, grib_sarray* sa, int* n){ +static int concept_conditions_apply(grib_handle* h, grib_concept_condition* c, grib_values* values, grib_sarray* sa, int* n) +{ if (c->expression == NULL) return concept_conditions_iarray_apply(h, c); else return concept_conditions_expression_apply(h, c, values, sa, n); } -int cmpstringp(const void* p1, const void* p2){ +static int cmpstringp(const void* p1, const void* p2) +{ /* The actual arguments to this function are "pointers to pointers to char", but strcmp(3) arguments are "pointers to char", hence the following cast plus dereference */ return strcmp(*(char* const*)p1, *(char* const*)p2); } -bool blacklisted(grib_handle* h, long edition, const char* concept_name, const char* concept_value){ - if ( strcmp(concept_name, "packingType")==0 ) { +bool blacklisted(grib_handle* h, long edition, const char* concept_name, const char* concept_value) +{ + if (strcmp(concept_name, "packingType") == 0) { char input_packing_type[100]; size_t len = sizeof(input_packing_type); if (strstr(concept_value, "SPD")) { @@ -226,17 +235,18 @@ bool blacklisted(grib_handle* h, long edition, const char* concept_name, const c return true; } grib_get_string(h, "packingType", input_packing_type, &len); - if (strstr(input_packing_type,"grid_") && !strstr(concept_value,"grid_")) { + if (strstr(input_packing_type, "grid_") && !strstr(concept_value, "grid_")) { return true; } - if (strstr(input_packing_type,"spectral_") && !strstr(concept_value,"spectral_")) { + if (strstr(input_packing_type, "spectral_") && !strstr(concept_value, "spectral_")) { return true; } } return false; } -int grib_concept_apply(grib_accessor* a, const char* name){ +static int grib_concept_apply(grib_accessor* a, const char* name) +{ int err = 0; int count = 0; grib_concept_condition* e = NULL; @@ -261,8 +271,10 @@ int grib_concept_apply(grib_accessor* a, const char* name){ size_t i = 0, concept_count = 0; long dummy = 0, editionNumber = 0; char centre_s[32] = {0,}; - size_t centre_len = sizeof(centre_s); - char* all_concept_vals[MAX_NUM_CONCEPT_VALUES] = {NULL,}; /* sorted array containing concept values */ + size_t centre_len = sizeof(centre_s); + char* all_concept_vals[MAX_NUM_CONCEPT_VALUES] = { + NULL, + }; /* sorted array containing concept values */ grib_concept_value* pCon = concepts; grib_context_log(h->context, GRIB_LOG_ERROR, "concept: no match for %s=%s", act->name, name); @@ -279,11 +291,12 @@ int grib_concept_apply(grib_accessor* a, const char* name){ if (string_to_long(name, &dummy, 1) == GRIB_SUCCESS) { // The paramId value is an integer. Show them the param DB grib_context_log(h->context, GRIB_LOG_ERROR, - "Please check the Parameter Database 'https://codes.ecmwf.int/grib/param-db/?id=%s'", name); - } else { + "Please check the Parameter Database 'https://codes.ecmwf.int/grib/param-db/?id=%s'", name); + } + else { // paramId being set to a non-integer grib_context_log(h->context, GRIB_LOG_ERROR, - "The paramId value should be an integer. Are you trying to set the shortName?"); + "The paramId value should be an integer. Are you trying to set the shortName?"); } } if (strcmp(act->name, "shortName") == 0) { @@ -335,29 +348,31 @@ int grib_concept_apply(grib_accessor* a, const char* name){ return err; } -int grib_accessor_class_concept_t::pack_double(grib_accessor* a, const double* val, size_t* len){ +int grib_accessor_class_concept_t::pack_double(grib_accessor* a, const double* val, size_t* len) +{ return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_concept_t::pack_long(grib_accessor* a, const long* val, size_t* len){ +int grib_accessor_class_concept_t::pack_long(grib_accessor* a, const long* val, size_t* len) +{ char buf[80]; size_t s; snprintf(buf, sizeof(buf), "%ld", *val); - //if(*len > 1) - // return GRIB_NOT_IMPLEMENTED; + // if(*len > 1) + // return GRIB_NOT_IMPLEMENTED; // ECC-1806: GRIB: Change of paramId in conversion from GRIB1 to GRIB2 if (STR_EQUAL(a->name, "paramId")) { grib_handle* h = grib_handle_of_accessor(a); - long edition = 0; + long edition = 0; if (grib_get_long(h, "edition", &edition) == GRIB_SUCCESS && edition == 2) { long newParamId = 0; if (grib_get_long(h, "paramIdForConversion", &newParamId) == GRIB_SUCCESS && newParamId > 0) { if (a->context->debug) { const char* cclass_name = a->cclass->name; fprintf(stderr, "ECCODES DEBUG %s::%s: Changing %s from %ld to %ld\n", - cclass_name, __func__, a->name, *val, newParamId); + cclass_name, __func__, a->name, *val, newParamId); } snprintf(buf, sizeof(buf), "%ld", newParamId); } @@ -368,7 +383,8 @@ int grib_accessor_class_concept_t::pack_long(grib_accessor* a, const long* val, return pack_string(a, buf, &s); } -int grib_accessor_class_concept_t::unpack_double(grib_accessor* a, double* val, size_t* len){ +int grib_accessor_class_concept_t::unpack_double(grib_accessor* a, double* val, size_t* len) +{ /* * If we want to have a condition which contains tests for paramId as well * as a floating point key, then need to be able to evaluate paramId as a @@ -400,7 +416,8 @@ int grib_accessor_class_concept_t::unpack_double(grib_accessor* a, double* val, return ret; } -int grib_accessor_class_concept_t::unpack_long(grib_accessor* a, long* val, size_t* len){ +int grib_accessor_class_concept_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ const char* p = concept_evaluate(a); if (!p) { @@ -419,14 +436,14 @@ int grib_accessor_class_concept_t::unpack_long(grib_accessor* a, long* val, size * Keep this check in DEBUG mode only */ { - char *endptr; + char* endptr; *val = strtol(p, &endptr, 10); if (endptr == p || *endptr != '\0') { /* Failed to convert string into integer */ int type = GRIB_TYPE_UNDEFINED; - grib_context_log(a->context,GRIB_LOG_ERROR,"Cannot unpack %s as long",a->name); + grib_context_log(a->context, GRIB_LOG_ERROR, "Cannot unpack %s as long", a->name); if (grib_get_native_type(grib_handle_of_accessor(a), a->name, &type) == GRIB_SUCCESS) { - grib_context_log(a->context,GRIB_LOG_ERROR,"Hint: Try unpacking as %s", grib_get_type_name(type)); + grib_context_log(a->context, GRIB_LOG_ERROR, "Hint: Try unpacking as %s", grib_get_type_name(type)); } return GRIB_DECODING_ERROR; } @@ -435,7 +452,8 @@ int grib_accessor_class_concept_t::unpack_long(grib_accessor* a, long* val, size return GRIB_SUCCESS; } -int grib_accessor_class_concept_t::get_native_type(grib_accessor* a){ +int grib_accessor_class_concept_t::get_native_type(grib_accessor* a) +{ int type = GRIB_TYPE_STRING; if (a->flags & GRIB_ACCESSOR_FLAG_LONG_TYPE) type = GRIB_TYPE_LONG; @@ -443,13 +461,15 @@ int grib_accessor_class_concept_t::get_native_type(grib_accessor* a){ return type; } -void grib_accessor_class_concept_t::destroy(grib_context* c, grib_accessor* a){ - //grib_accessor_concept_t *self = (grib_accessor_concept_t*)a; - //grib_context_free(c,self->cval); +void grib_accessor_class_concept_t::destroy(grib_context* c, grib_accessor* a) +{ + // grib_accessor_concept_t *self = (grib_accessor_concept_t*)a; + // grib_context_free(c,self->cval); grib_accessor_class_gen_t::destroy(c, a); } -int grib_accessor_class_concept_t::unpack_string(grib_accessor* a, char* val, size_t* len){ +int grib_accessor_class_concept_t::unpack_string(grib_accessor* a, char* val, size_t* len) +{ size_t slen; const char* p = concept_evaluate(a); @@ -464,7 +484,7 @@ int grib_accessor_class_concept_t::unpack_string(grib_accessor* a, char* val, si slen = strlen(p) + 1; if (*len < slen) { grib_context_log(a->context, GRIB_LOG_ERROR, - "Concept unpack_string. Buffer too small for %s, value='%s' which requires %lu bytes (len=%lu)", + "Concept unpack_string. Buffer too small for %s, value='%s' which requires %lu bytes (len=%lu)", a->name, p, slen, *len); *len = slen; return GRIB_BUFFER_TOO_SMALL; @@ -472,30 +492,34 @@ int grib_accessor_class_concept_t::unpack_string(grib_accessor* a, char* val, si strcpy(val, p); /* NOLINT: CWE-119 clang-analyzer-security.insecureAPI.strcpy */ *len = slen; -// if (a->context->debug==1) { -// int err = 0; -// char result[1024] = {0,}; -// err = get_concept_condition_string(grib_handle_of_accessor(a), a->name, val, result); -// if (!err) fprintf(stderr, "ECCODES DEBUG concept name=%s, value=%s, conditions=%s\n", a->name, val, result); -// } + // if (a->context->debug==1) { + // int err = 0; + // char result[1024] = {0,}; + // err = get_concept_condition_string(grib_handle_of_accessor(a), a->name, val, result); + // if (!err) fprintf(stderr, "ECCODES DEBUG concept name=%s, value=%s, conditions=%s\n", a->name, val, result); + // } return GRIB_SUCCESS; } -int grib_accessor_class_concept_t::pack_string(grib_accessor* a, const char* val, size_t* len){ +int grib_accessor_class_concept_t::pack_string(grib_accessor* a, const char* val, size_t* len) +{ return grib_concept_apply(a, val); } -size_t grib_accessor_class_concept_t::string_length(grib_accessor* a){ +size_t grib_accessor_class_concept_t::string_length(grib_accessor* a) +{ return MAX_CONCEPT_STRING_LENGTH; } -int grib_accessor_class_concept_t::value_count(grib_accessor* a, long* count){ +int grib_accessor_class_concept_t::value_count(grib_accessor* a, long* count) +{ *count = 1; return 0; } -int grib_accessor_class_concept_t::compare(grib_accessor* a, grib_accessor* b){ +int grib_accessor_class_concept_t::compare(grib_accessor* a, grib_accessor* b) +{ int retval = 0; char* aval = 0; char* bval = 0; @@ -505,10 +529,12 @@ int grib_accessor_class_concept_t::compare(grib_accessor* a, grib_accessor* b){ int err = 0; long count = 0; - err = a->value_count(&count); if (err) return err; + err = a->value_count(&count); + if (err) return err; alen = count; - err = b->value_count(&count); if (err) return err; + err = b->value_count(&count); + if (err) return err; blen = count; if (alen != blen) @@ -519,8 +545,10 @@ int grib_accessor_class_concept_t::compare(grib_accessor* a, grib_accessor* b){ aval = (char*)grib_context_malloc(a->context, alen * sizeof(char)); bval = (char*)grib_context_malloc(b->context, blen * sizeof(char)); - err = a->unpack_string(aval, &alen); if (err) return err; - err = b->unpack_string(bval, &blen); if (err) return err; + err = a->unpack_string(aval, &alen); + if (err) return err; + err = b->unpack_string(bval, &blen); + if (err) return err; retval = GRIB_SUCCESS; if (!aval || !bval || grib_inline_strcmp(aval, bval)) diff --git a/src/accessor/grib_accessor_class_count_missing.cc b/src/accessor/grib_accessor_class_count_missing.cc index c381be043..7a3232175 100644 --- a/src/accessor/grib_accessor_class_count_missing.cc +++ b/src/accessor/grib_accessor_class_count_missing.cc @@ -11,7 +11,7 @@ #include "grib_accessor_class_count_missing.h" -grib_accessor_class_count_missing_t _grib_accessor_class_count_missing{"count_missing"}; +grib_accessor_class_count_missing_t _grib_accessor_class_count_missing{ "count_missing" }; grib_accessor_class* grib_accessor_class_count_missing = &_grib_accessor_class_count_missing; @@ -34,22 +34,24 @@ static const unsigned char bitsoff[] = { 0 }; -void grib_accessor_class_count_missing_t::init(grib_accessor* a, const long len, grib_arguments* arg){ +void grib_accessor_class_count_missing_t::init(grib_accessor* a, const long len, grib_arguments* arg) +{ grib_accessor_class_long_t::init(a, len, arg); - int n = 0; + int n = 0; grib_accessor_count_missing_t* self = (grib_accessor_count_missing_t*)a; - grib_handle* h = grib_handle_of_accessor(a); - a->length = 0; + grib_handle* h = grib_handle_of_accessor(a); + a->length = 0; a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - self->bitmap = grib_arguments_get_name(h, arg, n++); - self->unusedBitsInBitmap = grib_arguments_get_name(h, arg, n++); - self->numberOfDataPoints = grib_arguments_get_name(h, arg, n++); + self->bitmap = grib_arguments_get_name(h, arg, n++); + self->unusedBitsInBitmap = grib_arguments_get_name(h, arg, n++); + self->numberOfDataPoints = grib_arguments_get_name(h, arg, n++); self->missingValueManagementUsed = grib_arguments_get_name(h, arg, n++); /* Can be NULL */ } static const int used[] = { 0, 1, 3, 7, 15, 31, 63, 127, 255 }; -int get_count_of_missing_values(grib_handle* h, long* p_count_of_missing){ +static int get_count_of_missing_values(grib_handle* h, long* p_count_of_missing) +{ int err = 0; long count_of_missing = 0; size_t vsize = 0, ii = 0; @@ -72,7 +74,8 @@ int get_count_of_missing_values(grib_handle* h, long* p_count_of_missing){ return GRIB_SUCCESS; } -int grib_accessor_class_count_missing_t::unpack_long(grib_accessor* a, long* val, size_t* len){ +int grib_accessor_class_count_missing_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ grib_accessor_count_missing_t* self = (grib_accessor_count_missing_t*)a; unsigned char* p; int i; @@ -88,11 +91,10 @@ int grib_accessor_class_count_missing_t::unpack_long(grib_accessor* a, long* val if (!bitmap) { long mvmu = 0; if (self->missingValueManagementUsed && - grib_get_long(h, self->missingValueManagementUsed, &mvmu) == GRIB_SUCCESS && mvmu != 0) - { + grib_get_long(h, self->missingValueManagementUsed, &mvmu) == GRIB_SUCCESS && mvmu != 0) { /* ECC-523: No bitmap. Missing values are encoded in the Data Section. * So we must decode all the data values and count how many are missing - */ + */ long count_of_missing = 0; if (get_count_of_missing_values(h, &count_of_missing) == GRIB_SUCCESS) { *val = count_of_missing; @@ -101,7 +103,8 @@ int grib_accessor_class_count_missing_t::unpack_long(grib_accessor* a, long* val return GRIB_SUCCESS; } - size = bitmap->byte_count(); offset = bitmap->byte_offset(); + size = bitmap->byte_count(); + offset = bitmap->byte_offset(); if (grib_get_long(h, self->unusedBitsInBitmap, &unusedBitsInBitmap) != GRIB_SUCCESS) { if (grib_get_long(h, self->numberOfDataPoints, &numberOfDataPoints) != GRIB_SUCCESS) { grib_context_log(a->context, GRIB_LOG_ERROR, "Unable to count missing values"); @@ -110,7 +113,7 @@ int grib_accessor_class_count_missing_t::unpack_long(grib_accessor* a, long* val unusedBitsInBitmap = size * 8 - numberOfDataPoints; if (unusedBitsInBitmap < 0) { grib_context_log(a->context, GRIB_LOG_ERROR, "Inconsistent number of bitmap points: Check the bitmap and data sections!"); - grib_context_log(a->context, GRIB_LOG_ERROR, "Bitmap size=%ld, numberOfDataPoints=%ld", size*8, numberOfDataPoints); + grib_context_log(a->context, GRIB_LOG_ERROR, "Bitmap size=%ld, numberOfDataPoints=%ld", size * 8, numberOfDataPoints); return GRIB_DECODING_ERROR; } } @@ -128,7 +131,8 @@ int grib_accessor_class_count_missing_t::unpack_long(grib_accessor* a, long* val return GRIB_SUCCESS; } -int grib_accessor_class_count_missing_t::value_count(grib_accessor* a, long* count){ +int grib_accessor_class_count_missing_t::value_count(grib_accessor* a, long* count) +{ *count = 1; return 0; } diff --git a/src/accessor/grib_accessor_class_data_g1second_order_general_extended_packing.cc b/src/accessor/grib_accessor_class_data_g1second_order_general_extended_packing.cc index a5c1084ac..f78bb1806 100644 --- a/src/accessor/grib_accessor_class_data_g1second_order_general_extended_packing.cc +++ b/src/accessor/grib_accessor_class_data_g1second_order_general_extended_packing.cc @@ -12,12 +12,12 @@ #include "grib_accessor_class_data_g1second_order_general_extended_packing.h" #include "grib_scaling.h" -grib_accessor_class_data_g1second_order_general_extended_packing_t _grib_accessor_class_data_g1second_order_general_extended_packing{"data_g1second_order_general_extended_packing"}; +grib_accessor_class_data_g1second_order_general_extended_packing_t _grib_accessor_class_data_g1second_order_general_extended_packing{ "data_g1second_order_general_extended_packing" }; grib_accessor_class* grib_accessor_class_data_g1second_order_general_extended_packing = &_grib_accessor_class_data_g1second_order_general_extended_packing; #define MAX_NUMBER_OF_GROUPS 65534 -#define EFDEBUG 0 +#define EFDEBUG 0 static const unsigned long nbits[64] = { 0x1, 0x2, 0x4, 0x8, @@ -38,7 +38,8 @@ static const unsigned long nbits[64] = { 0x1000000000000000, 0x2000000000000000, 0x4000000000000000, 0x8000000000000000 }; -long number_of_bits(grib_handle* h, unsigned long x){ +long number_of_bits(grib_handle* h, unsigned long x) +{ const unsigned long* n = nbits; const int count = sizeof(nbits) / sizeof(nbits[0]); long i = 0; @@ -54,10 +55,11 @@ long number_of_bits(grib_handle* h, unsigned long x){ return i; } -void grib_accessor_class_data_g1second_order_general_extended_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){ +void grib_accessor_class_data_g1second_order_general_extended_packing_t::init(grib_accessor* a, const long v, grib_arguments* args) +{ grib_accessor_class_data_simple_packing_t::init(a, v, args); grib_accessor_data_g1second_order_general_extended_packing_t* self = (grib_accessor_data_g1second_order_general_extended_packing_t*)a; - grib_handle* handle = grib_handle_of_accessor(a); + grib_handle* handle = grib_handle_of_accessor(a); self->half_byte = grib_arguments_get_name(handle, args, self->carg++); self->packingType = grib_arguments_get_name(handle, args, self->carg++); @@ -83,17 +85,18 @@ void grib_accessor_class_data_g1second_order_general_extended_packing_t::init(gr self->dataFlag = grib_arguments_get_name(handle, args, self->carg++); self->edition = 1; self->dirty = 1; - self->dvalues = NULL; - self->fvalues = NULL; + self->dvalues = NULL; + self->fvalues = NULL; self->double_dirty = self->float_dirty = 1; - self->size = 0; + self->size = 0; a->flags |= GRIB_ACCESSOR_FLAG_DATA; } -int grib_accessor_class_data_g1second_order_general_extended_packing_t::value_count(grib_accessor* a, long* count){ +int grib_accessor_class_data_g1second_order_general_extended_packing_t::value_count(grib_accessor* a, long* count) +{ grib_accessor_data_g1second_order_general_extended_packing_t* self = (grib_accessor_data_g1second_order_general_extended_packing_t*)a; - long numberOfCodedValues = 0; - long numberOfGroups = 0; + long numberOfCodedValues = 0; + long numberOfGroups = 0; size_t ngroups; long* groupLengths; long orderOfSPD = 0; @@ -126,7 +129,8 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::value_co return err; } -int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val){ +int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val) +{ size_t size; double* values; int err = 0; @@ -149,7 +153,8 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack_d return GRIB_SUCCESS; } -int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array){ +int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array) +{ size_t size = 0, i = 0; double* values; int err = 0; @@ -176,9 +181,10 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack_d return GRIB_SUCCESS; } -int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack(grib_accessor* a, double* dvalues, float* fvalues, size_t* len){ +int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack(grib_accessor* a, double* dvalues, float* fvalues, size_t* len) +{ grib_accessor_data_g1second_order_general_extended_packing_t* self = (grib_accessor_data_g1second_order_general_extended_packing_t*)a; - int ret = 0; + int ret = 0; long numberOfGroups, numberOfSecondOrderPackedValues; long* firstOrderValues = 0; long* X = 0; @@ -292,14 +298,13 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack(g n++; } -// for (j=0;jdvalues) { if (numberOfValues != self->size) { grib_context_free(a->context, self->dvalues); @@ -396,11 +401,13 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack(g return ret; } -int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack_float(grib_accessor* a, float* values, size_t* len){ +int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack_float(grib_accessor* a, float* values, size_t* len) +{ return unpack(a, NULL, values, len); } -int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack_double(grib_accessor* a, double* values, size_t* len){ +int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack_double(grib_accessor* a, double* values, size_t* len) +{ return unpack(a, values, NULL, len); } @@ -513,7 +520,8 @@ static void grib_split_long_groups(grib_handle* hand, grib_context* c, long* num grib_context_free(c, localFirstOrderValues); } -int get_bits_per_value(grib_handle* h, const char* bits_per_value_str, long* bits_per_value){ +static int get_bits_per_value(grib_handle* h, const char* bits_per_value_str, long* bits_per_value) +{ int err = 0; if ((err = grib_get_long_internal(h, bits_per_value_str, bits_per_value)) != GRIB_SUCCESS) return err; @@ -526,7 +534,8 @@ int get_bits_per_value(grib_handle* h, const char* bits_per_value_str, long* bit /* Note: on a 32bit system, the most significant bit is for signedness, so we have to drop one bit */ if (sizeof(long) == 4) { *bits_per_value = 31; - } else { + } + else { *bits_per_value = 32; } } @@ -536,10 +545,11 @@ int get_bits_per_value(grib_handle* h, const char* bits_per_value_str, long* bit // For the old implementation of pack_double, see // src/deprecated/grib_accessor_class_data_g1second_order_general_extended_packing.pack_double.cc // See ECC-441 and ECC-261 -int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len){ +int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len) +{ grib_accessor_data_g1second_order_general_extended_packing_t* self = (grib_accessor_data_g1second_order_general_extended_packing_t*)a; - int ret = 0; - int grib2 = 0; + int ret = 0; + int grib2 = 0; long bits_per_value, orderOfSPD, binary_scale_factor; long numberOfValues; double max, min; @@ -1130,7 +1140,9 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_dou pos = 0; if (orderOfSPD) { - long SPD[4] = {0,}; + long SPD[4] = { + 0, + }; size_t nSPD = orderOfSPD + 1; Assert(orderOfSPD <= 3); for (i = 0; i < orderOfSPD; i++) @@ -1192,7 +1204,8 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_dou return GRIB_SUCCESS; } -void grib_accessor_class_data_g1second_order_general_extended_packing_t::destroy(grib_context* context, grib_accessor* a){ +void grib_accessor_class_data_g1second_order_general_extended_packing_t::destroy(grib_context* context, grib_accessor* a) +{ grib_accessor_data_g1second_order_general_extended_packing_t* self = (grib_accessor_data_g1second_order_general_extended_packing_t*)a; if (self->dvalues != NULL) { grib_context_free(context, self->dvalues); diff --git a/src/accessor/grib_accessor_class_data_g22order_packing.cc b/src/accessor/grib_accessor_class_data_g22order_packing.cc index 43fbce6ba..bbc698100 100644 --- a/src/accessor/grib_accessor_class_data_g22order_packing.cc +++ b/src/accessor/grib_accessor_class_data_g22order_packing.cc @@ -130,7 +130,7 @@ void add_bitstream(bitstream_context* ctx, grib_accessor* a, int t, int n_bits) // find min/max of an integer array // return 0: if min max found // return 1: if min max not found, min = max = 0 -int int_min_max_array(int* data, unsigned int n, int* min, int* max) +static int int_min_max_array(int* data, unsigned int n, int* min, int* max) { unsigned int first; int mn, mx; @@ -172,7 +172,7 @@ int int_min_max_array(int* data, unsigned int n, int* min, int* max) return 0; } -double Int_Power(double x, int y) +static double Int_Power(double x, int y) { double value; @@ -192,7 +192,7 @@ double Int_Power(double x, int y) return value; } -int min_max_array(double* data, unsigned int n, double* min, double* max) +static int min_max_array(double* data, unsigned int n, double* min, double* max) { unsigned int first; double mn, mx; @@ -366,7 +366,7 @@ static int post_process(grib_context* c, long* vals, long len, long order, long return GRIB_SUCCESS; } -int find_nbits(unsigned int i) +static int find_nbits(unsigned int i) { #if !defined __GNUC__ || __GNUC__ < 4 int j; @@ -405,7 +405,7 @@ struct section struct section *head, *tail; }; -int sizeofsection(struct section* s, int ref_bits, int width_bits, int has_undef) +static int sizeofsection(struct section* s, int ref_bits, int width_bits, int has_undef) { if (s->mn == INT_MAX) { // all undef return ref_bits + width_bits; @@ -434,7 +434,7 @@ static int sizeofsection2(int mn, int mx, int n, int ref_bits, int width_bits, return find_nbits(mx - mn + has_undef) * n + ref_bits + width_bits; } -int size_all(struct section* s, int ref_bits, int width_bits, int has_undef) +static int size_all(struct section* s, int ref_bits, int width_bits, int has_undef) { int bits; @@ -446,7 +446,7 @@ int size_all(struct section* s, int ref_bits, int width_bits, int has_undef) return (bits + 7) / 8; } -void move_one_left(struct section* s, int* v) +static void move_one_left(struct section* s, int* v) { struct section* t; int val, i, j, k; @@ -512,7 +512,7 @@ void move_one_left(struct section* s, int* v) } } -void move_one_right(struct section* s, int* v) +static void move_one_right(struct section* s, int* v) { struct section* t; int val, i, j, k; @@ -594,7 +594,7 @@ void move_one_right(struct section* s, int* v) return; } -void exchange(struct section* s, int* v, int has_undef, int LEN_SEC_MAX) +static void exchange(struct section* s, int* v, int has_undef, int LEN_SEC_MAX) { struct section* t; int val0, val1, nbit_s, nbit_t; @@ -670,7 +670,7 @@ void exchange(struct section* s, int* v, int has_undef, int LEN_SEC_MAX) } } -void merge_j(struct section* h, int ref_bits, int width_bits, int has_undef, int param, int LEN_SEC_MAX) +static void merge_j(struct section* h, int ref_bits, int width_bits, int has_undef, int param, int LEN_SEC_MAX) { struct section *t, *m; int size_head, size_mid, size_tail, saving_mt, saving_hm; diff --git a/src/accessor/grib_accessor_class_data_g2bifourier_packing.cc b/src/accessor/grib_accessor_class_data_g2bifourier_packing.cc index 60cf8e0f9..a014ef3c2 100644 --- a/src/accessor/grib_accessor_class_data_g2bifourier_packing.cc +++ b/src/accessor/grib_accessor_class_data_g2bifourier_packing.cc @@ -50,7 +50,8 @@ int grib_accessor_class_data_g2bifourier_packing_t::value_count(grib_accessor* a return grib_get_long_internal(gh, self->number_of_values, numberOfValues); } -void ellipse(long ni, long nj, long itrunc[], long jtrunc[]){ +static void ellipse(long ni, long nj, long itrunc[], long jtrunc[]) +{ const double zeps = 1.E-10; const double zauxil = 0.; int i, j; @@ -91,7 +92,8 @@ void ellipse(long ni, long nj, long itrunc[], long jtrunc[]){ } } -void rectangle(long ni, long nj, long itrunc[], long jtrunc[]){ +static void rectangle(long ni, long nj, long itrunc[], long jtrunc[]) +{ int i, j; /* @@ -109,7 +111,8 @@ void rectangle(long ni, long nj, long itrunc[], long jtrunc[]){ jtrunc[i] = nj; } -void diamond(long ni, long nj, long itrunc[], long jtrunc[]){ +static void diamond(long ni, long nj, long itrunc[], long jtrunc[]) +{ int i, j; if (nj == 0) @@ -171,7 +174,8 @@ typedef struct bif_trunc_t /* * Total number of coefficients */ -size_t size_bif(bif_trunc_t* bt){ +static size_t size_bif(bif_trunc_t* bt) +{ size_t n_vals = 0; int j; for (j = 0; j <= bt->bif_j; j++) @@ -182,7 +186,8 @@ size_t size_bif(bif_trunc_t* bt){ /* * Number of unpacked coefficients */ -size_t size_sub(bif_trunc_t* bt){ +static size_t size_sub(bif_trunc_t* bt) +{ size_t n_vals = 0; int i, j; for_ij() @@ -197,7 +202,8 @@ size_t size_sub(bif_trunc_t* bt){ return n_vals; } -double laplam(bif_trunc_t* bt, const double val[]){ +static double laplam(bif_trunc_t* bt, const double val[]) +{ /* * For bi-Fourier spectral fields, the Laplacian operator is a multiplication by (i*i+j*j) */ @@ -333,7 +339,8 @@ double laplam(bif_trunc_t* bt, const double val[]){ return zp; } -void free_bif_trunc(bif_trunc_t* bt, grib_accessor* a){ +static void free_bif_trunc(bif_trunc_t* bt, grib_accessor* a) +{ grib_handle* gh = grib_handle_of_accessor(a); if (bt == NULL) return; diff --git a/src/accessor/grib_accessor_class_data_g2simple_packing_with_preprocessing.cc b/src/accessor/grib_accessor_class_data_g2simple_packing_with_preprocessing.cc index fa653c0cb..fc87df231 100644 --- a/src/accessor/grib_accessor_class_data_g2simple_packing_with_preprocessing.cc +++ b/src/accessor/grib_accessor_class_data_g2simple_packing_with_preprocessing.cc @@ -13,11 +13,12 @@ #define DIRECT 0 #define INVERSE 1 -grib_accessor_class_data_g2simple_packing_with_preprocessing_t _grib_accessor_class_data_g2simple_packing_with_preprocessing{"data_g2simple_packing_with_preprocessing"}; +grib_accessor_class_data_g2simple_packing_with_preprocessing_t _grib_accessor_class_data_g2simple_packing_with_preprocessing{ "data_g2simple_packing_with_preprocessing" }; grib_accessor_class* grib_accessor_class_data_g2simple_packing_with_preprocessing = &_grib_accessor_class_data_g2simple_packing_with_preprocessing; -void grib_accessor_class_data_g2simple_packing_with_preprocessing_t::init(grib_accessor* a, const long v, grib_arguments* args){ +void grib_accessor_class_data_g2simple_packing_with_preprocessing_t::init(grib_accessor* a, const long v, grib_arguments* args) +{ grib_accessor_class_data_g2simple_packing_t::init(a, v, args); grib_accessor_data_g2simple_packing_with_preprocessing_t* self = (grib_accessor_data_g2simple_packing_with_preprocessing_t*)a; self->pre_processing = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); @@ -25,7 +26,8 @@ void grib_accessor_class_data_g2simple_packing_with_preprocessing_t::init(grib_a a->flags |= GRIB_ACCESSOR_FLAG_DATA; } -int grib_accessor_class_data_g2simple_packing_with_preprocessing_t::value_count(grib_accessor* a, long* n_vals){ +int grib_accessor_class_data_g2simple_packing_with_preprocessing_t::value_count(grib_accessor* a, long* n_vals) +{ grib_accessor_data_g2simple_packing_with_preprocessing_t* self = (grib_accessor_data_g2simple_packing_with_preprocessing_t*)a; *n_vals = 0; @@ -35,7 +37,7 @@ int grib_accessor_class_data_g2simple_packing_with_preprocessing_t::value_count( static int pre_processing_func(double* values, long length, long pre_processing, double* pre_processing_parameter, int mode) { - int i = 0, ret = 0; + int i = 0, ret = 0; double min = values[0]; double next_min = values[0]; Assert(length > 0); @@ -96,10 +98,9 @@ static int pre_processing_func(double* values, long length, long pre_processing, return ret; } -int grib_accessor_class_data_g2simple_packing_with_preprocessing_t::unpack_double(grib_accessor* a, double* val, size_t* len){ +int grib_accessor_class_data_g2simple_packing_with_preprocessing_t::unpack_double(grib_accessor* a, double* val, size_t* len) +{ grib_accessor_data_g2simple_packing_with_preprocessing_t* self = (grib_accessor_data_g2simple_packing_with_preprocessing_t*)a; - //grib_accessor_class* super = *(a->cclass->super); - //grib_accessor_class* super2 = NULL; size_t n_vals = 0; long nn = 0; @@ -108,7 +109,8 @@ int grib_accessor_class_data_g2simple_packing_with_preprocessing_t::unpack_doubl long pre_processing; double pre_processing_parameter; - err = a->value_count(&nn); n_vals = nn; + err = a->value_count(&nn); + n_vals = nn; if (err) return err; @@ -140,7 +142,8 @@ int grib_accessor_class_data_g2simple_packing_with_preprocessing_t::unpack_doubl return err; } -int grib_accessor_class_data_g2simple_packing_with_preprocessing_t::pack_double(grib_accessor* a, const double* val, size_t* len){ +int grib_accessor_class_data_g2simple_packing_with_preprocessing_t::pack_double(grib_accessor* a, const double* val, size_t* len) +{ grib_accessor_data_g2simple_packing_with_preprocessing_t* self = (grib_accessor_data_g2simple_packing_with_preprocessing_t*)a; size_t n_vals = *len; diff --git a/src/accessor/grib_accessor_class_data_jpeg2000_packing.cc b/src/accessor/grib_accessor_class_data_jpeg2000_packing.cc index a68a3eae7..5ce5ae154 100644 --- a/src/accessor/grib_accessor_class_data_jpeg2000_packing.cc +++ b/src/accessor/grib_accessor_class_data_jpeg2000_packing.cc @@ -428,7 +428,7 @@ int grib_accessor_class_data_jpeg2000_packing_t::pack_double(grib_accessor* a, c } #else -void print_error_feature_not_enabled(grib_context* c){ +static void print_error_feature_not_enabled(grib_context* c){ grib_context_log(c, GRIB_LOG_ERROR, "JPEG support not enabled. Please rebuild with -DENABLE_JPG=ON"); } diff --git a/src/accessor/grib_accessor_class_data_png_packing.cc b/src/accessor/grib_accessor_class_data_png_packing.cc index 8db2e5b3b..690070214 100644 --- a/src/accessor/grib_accessor_class_data_png_packing.cc +++ b/src/accessor/grib_accessor_class_data_png_packing.cc @@ -53,14 +53,16 @@ typedef struct png_read_callback_data size_t offset; } png_read_callback_data; -void png_read_callback(png_structp png, png_bytep data, png_size_t length){ +static void png_read_callback(png_structp png, png_bytep data, png_size_t length) +{ png_read_callback_data* p = (png_read_callback_data*)png_get_io_ptr(png); Assert(p->offset + length <= p->length); memcpy(data, p->buffer + p->offset, length); p->offset += length; } -void png_write_callback(png_structp png, png_bytep data, png_size_t length){ +static void png_write_callback(png_structp png, png_bytep data, png_size_t length) +{ png_read_callback_data* p = (png_read_callback_data*)png_get_io_ptr(png); /* printf("p.offset=%zu len=%zu p.len=%zu\n", p->offset, length, p->length); */ /* Assert(p->offset + length <= p->length); */ @@ -73,7 +75,8 @@ void png_write_callback(png_structp png, png_bytep data, png_size_t length){ p->offset += length; } -void png_flush_callback(png_structp png){ +static void png_flush_callback(png_structp png) +{ /* Empty */ } @@ -218,7 +221,8 @@ int grib_accessor_class_data_png_packing_t::unpack_double(grib_accessor* a, doub return err; } -bool is_constant(const double* values, size_t n_vals){ +static bool is_constant(const double* values, size_t n_vals) +{ bool isConstant = true; double v = 0; size_t i; diff --git a/src/accessor/grib_accessor_class_element.cc b/src/accessor/grib_accessor_class_element.cc index eb2a874f2..3d150d79e 100644 --- a/src/accessor/grib_accessor_class_element.cc +++ b/src/accessor/grib_accessor_class_element.cc @@ -15,7 +15,8 @@ grib_accessor_class_element_t _grib_accessor_class_element{"element"}; grib_accessor_class* grib_accessor_class_element = &_grib_accessor_class_element; -void grib_accessor_class_element_t::init(grib_accessor* a, const long l, grib_arguments* c){ +void grib_accessor_class_element_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ grib_accessor_class_long_t::init(a, l, c); grib_accessor_element_t* self = (grib_accessor_element_t*)a; grib_handle* hand = grib_handle_of_accessor(a); @@ -25,7 +26,8 @@ void grib_accessor_class_element_t::init(grib_accessor* a, const long l, grib_ar self->element = grib_arguments_get_long(hand, c, n++); } -int check_element_index(const char* func, const char* array_name, long index, size_t size){ +static int check_element_index(const char* func, const char* array_name, long index, size_t size) +{ const grib_context* c = grib_context_get_default(); if (index < 0 || index >= size) { grib_context_log(c, GRIB_LOG_ERROR, "%s: Invalid element index %ld for array '%s'. Value must be between 0 and %zu", @@ -35,7 +37,8 @@ int check_element_index(const char* func, const char* array_name, long index, si return GRIB_SUCCESS; } -int grib_accessor_class_element_t::unpack_long(grib_accessor* a, long* val, size_t* len){ +int grib_accessor_class_element_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ grib_accessor_element_t* self = (grib_accessor_element_t*)a; int ret = 0; size_t size = 0; @@ -77,7 +80,8 @@ int grib_accessor_class_element_t::unpack_long(grib_accessor* a, long* val, size return ret; } -int grib_accessor_class_element_t::pack_long(grib_accessor* a, const long* val, size_t* len){ +int grib_accessor_class_element_t::pack_long(grib_accessor* a, const long* val, size_t* len) +{ grib_accessor_element_t* self = (grib_accessor_element_t*)a; int ret = 0; size_t size = 0; @@ -124,7 +128,8 @@ int grib_accessor_class_element_t::pack_long(grib_accessor* a, const long* val, return ret; } -int grib_accessor_class_element_t::unpack_double(grib_accessor* a, double* val, size_t* len){ +int grib_accessor_class_element_t::unpack_double(grib_accessor* a, double* val, size_t* len) +{ grib_accessor_element_t* self = (grib_accessor_element_t*)a; int ret = 0; size_t size = 0; diff --git a/src/accessor/grib_accessor_class_expanded_descriptors.cc b/src/accessor/grib_accessor_class_expanded_descriptors.cc index ff91dbc6f..b30e745a9 100644 --- a/src/accessor/grib_accessor_class_expanded_descriptors.cc +++ b/src/accessor/grib_accessor_class_expanded_descriptors.cc @@ -41,7 +41,8 @@ typedef struct change_coding_params result = grib_bufr_descriptors_array_pop_front(array); \ } -void grib_accessor_class_expanded_descriptors_t::init(grib_accessor* a, const long len, grib_arguments* args){ +void grib_accessor_class_expanded_descriptors_t::init(grib_accessor* a, const long len, grib_arguments* args) +{ grib_accessor_class_long_t::init(a, len, args); grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; int n = 0; @@ -88,7 +89,8 @@ static char* descriptor_type_name(int dtype) } #endif -void __expand(grib_accessor* a, bufr_descriptors_array* unexpanded, bufr_descriptors_array* expanded, change_coding_params* ccp, int* err){ +static void __expand(grib_accessor* a, bufr_descriptors_array* unexpanded, bufr_descriptors_array* expanded, change_coding_params* ccp, int* err) +{ int k, j, i; grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; size_t size = 0; @@ -463,7 +465,8 @@ static bufr_descriptors_array* do_expand(grib_accessor* a, bufr_descriptors_arra return expanded; } -int expand(grib_accessor* a){ +static int expand(grib_accessor* a) +{ grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; int err = 0; size_t unexpandedSize = 0; @@ -599,7 +602,8 @@ bufr_descriptors_array* grib_accessor_class_expanded_descriptors_get_expanded(gr return self->expanded; } -int grib_accessor_class_expanded_descriptors_t::unpack_double(grib_accessor* a, double* val, size_t* len){ +int grib_accessor_class_expanded_descriptors_t::unpack_double(grib_accessor* a, double* val, size_t* len) +{ grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; int ret = 0; size_t i = 0; @@ -633,7 +637,8 @@ int grib_accessor_class_expanded_descriptors_t::unpack_double(grib_accessor* a, return ret; } -int grib_accessor_class_expanded_descriptors_t::unpack_long(grib_accessor* a, long* val, size_t* len){ +int grib_accessor_class_expanded_descriptors_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; int ret = 0; size_t rlen = 0; @@ -678,7 +683,8 @@ int grib_accessor_class_expanded_descriptors_t::unpack_long(grib_accessor* a, lo return GRIB_SUCCESS; } -int grib_accessor_class_expanded_descriptors_t::unpack_string_array(grib_accessor* a, char** buffer, size_t* len){ +int grib_accessor_class_expanded_descriptors_t::unpack_string_array(grib_accessor* a, char** buffer, size_t* len) +{ int err = 0; long* v = NULL; char buf[25] = {0,}; @@ -702,13 +708,15 @@ int grib_accessor_class_expanded_descriptors_t::unpack_string_array(grib_accesso return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_expanded_descriptors_t::pack_long(grib_accessor* a, const long* val, size_t* len){ +int grib_accessor_class_expanded_descriptors_t::pack_long(grib_accessor* a, const long* val, size_t* len) +{ grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; self->do_expand = 1; return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_expanded_descriptors_t::value_count(grib_accessor* a, long* rlen){ +int grib_accessor_class_expanded_descriptors_t::value_count(grib_accessor* a, long* rlen) +{ grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; int err = 0; *rlen = 0; @@ -723,14 +731,16 @@ int grib_accessor_class_expanded_descriptors_t::value_count(grib_accessor* a, lo return err; } -void grib_accessor_class_expanded_descriptors_t::destroy(grib_context* c, grib_accessor* a){ +void grib_accessor_class_expanded_descriptors_t::destroy(grib_context* c, grib_accessor* a) +{ grib_accessor_class_long_t::destroy(c, a); // grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; // if (self->rank==0 && self->expanded) // grib_bufr_descriptors_array_delete(self->expanded); } -int grib_accessor_class_expanded_descriptors_t::get_native_type(grib_accessor* a){ +int grib_accessor_class_expanded_descriptors_t::get_native_type(grib_accessor* a) +{ grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; if (self->rank == 2) return GRIB_TYPE_DOUBLE; diff --git a/src/accessor/grib_accessor_class_g1forecastmonth.cc b/src/accessor/grib_accessor_class_g1forecastmonth.cc index 7da455773..7ec448cf6 100644 --- a/src/accessor/grib_accessor_class_g1forecastmonth.cc +++ b/src/accessor/grib_accessor_class_g1forecastmonth.cc @@ -11,11 +11,12 @@ #include "grib_accessor_class_g1forecastmonth.h" -grib_accessor_class_g1forecastmonth_t _grib_accessor_class_g1forecastmonth{"g1forecastmonth"}; +grib_accessor_class_g1forecastmonth_t _grib_accessor_class_g1forecastmonth{ "g1forecastmonth" }; grib_accessor_class* grib_accessor_class_g1forecastmonth = &_grib_accessor_class_g1forecastmonth; -void grib_accessor_class_g1forecastmonth_t::init(grib_accessor* a, const long l, grib_arguments* c){ +void grib_accessor_class_g1forecastmonth_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ grib_accessor_class_long_t::init(a, l, c); grib_accessor_g1forecastmonth_t* self = (grib_accessor_g1forecastmonth_t*)a; grib_handle* h = grib_handle_of_accessor(a); @@ -31,17 +32,19 @@ void grib_accessor_class_g1forecastmonth_t::init(grib_accessor* a, const long l, } } -void grib_accessor_class_g1forecastmonth_t::dump(grib_accessor* a, grib_dumper* dumper){ +void grib_accessor_class_g1forecastmonth_t::dump(grib_accessor* a, grib_dumper* dumper) +{ grib_dump_long(dumper, a, NULL); } -int calculate_fcmonth(grib_accessor* a, long verification_yearmonth, long base_date, long day, long hour, long* result){ +static int calculate_fcmonth(grib_accessor* a, long verification_yearmonth, long base_date, long day, long hour, long* result) +{ long base_yearmonth = 0; - long vyear = 0; - long vmonth = 0; - long byear = 0; - long bmonth = 0; - long fcmonth = 0; + long vyear = 0; + long vmonth = 0; + long byear = 0; + long bmonth = 0; + long fcmonth = 0; base_yearmonth = base_date / 100; @@ -58,7 +61,8 @@ int calculate_fcmonth(grib_accessor* a, long verification_yearmonth, long base_d return GRIB_SUCCESS; } -int unpack_long_edition2(grib_accessor* a, long* val, size_t* len){ +static int unpack_long_edition2(grib_accessor* a, long* val, size_t* len) +{ int err = 0; grib_handle* h = grib_handle_of_accessor(a); long dataDate, verification_yearmonth; @@ -67,10 +71,10 @@ int unpack_long_edition2(grib_accessor* a, long* val, size_t* len){ long forecastTime, indicatorOfUnitOfTimeRange; double jul_base, jul2, dstep; - if ((err = grib_get_long(h, "year", &year)) != GRIB_SUCCESS) return err; + if ((err = grib_get_long(h, "year", &year)) != GRIB_SUCCESS) return err; if ((err = grib_get_long(h, "month", &month)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long(h, "day", &day)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long(h, "hour", &hour)) != GRIB_SUCCESS) return err; + if ((err = grib_get_long(h, "day", &day)) != GRIB_SUCCESS) return err; + if ((err = grib_get_long(h, "hour", &hour)) != GRIB_SUCCESS) return err; if ((err = grib_get_long(h, "minute", &minute)) != GRIB_SUCCESS) return err; if ((err = grib_get_long(h, "second", &second)) != GRIB_SUCCESS) return err; @@ -90,19 +94,20 @@ int unpack_long_edition2(grib_accessor* a, long* val, size_t* len){ return err; dstep = (((double)forecastTime) * 3600) / 86400; /* as a fraction of a day */ - jul2 = jul_base + dstep; + jul2 = jul_base + dstep; if ((err = grib_julian_to_datetime(jul2, &year2, &month2, &day2, &hour2, &minute2, &second2)) != GRIB_SUCCESS) return err; - verification_yearmonth = year2*100 + month2; + verification_yearmonth = year2 * 100 + month2; if ((err = calculate_fcmonth(a, verification_yearmonth, dataDate, day, hour, val)) != GRIB_SUCCESS) return err; return GRIB_SUCCESS; } -int unpack_long_edition1(grib_accessor* a, long* val, size_t* len){ +int unpack_long_edition1(grib_accessor* a, long* val, size_t* len) +{ int err = 0; grib_accessor_g1forecastmonth_t* self = (grib_accessor_g1forecastmonth_t*)a; @@ -110,9 +115,9 @@ int unpack_long_edition1(grib_accessor* a, long* val, size_t* len){ long base_date = 0; long day = 0; long hour = 0; - long gribForecastMonth = 0; - long check = 0; - long fcmonth = 0; + long gribForecastMonth = 0; + long check = 0; + long fcmonth = 0; if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->verification_yearmonth, &verification_yearmonth)) != GRIB_SUCCESS) @@ -148,10 +153,11 @@ int unpack_long_edition1(grib_accessor* a, long* val, size_t* len){ return GRIB_SUCCESS; } -int grib_accessor_class_g1forecastmonth_t::unpack_long(grib_accessor* a, long* val, size_t* len){ - int err = 0; +int grib_accessor_class_g1forecastmonth_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ + int err = 0; grib_handle* hand = grib_handle_of_accessor(a); - long edition = 0; + long edition = 0; if ((err = grib_get_long(hand, "edition", &edition)) != GRIB_SUCCESS) return err; @@ -165,7 +171,8 @@ int grib_accessor_class_g1forecastmonth_t::unpack_long(grib_accessor* a, long* v } /* TODO: Check for a valid date */ -int grib_accessor_class_g1forecastmonth_t::pack_long(grib_accessor* a, const long* val, size_t* len){ +int grib_accessor_class_g1forecastmonth_t::pack_long(grib_accessor* a, const long* val, size_t* len) +{ grib_accessor_g1forecastmonth_t* self = (grib_accessor_g1forecastmonth_t*)a; return grib_set_long_internal(grib_handle_of_accessor(a), self->fcmonth, *val); } diff --git a/src/accessor/grib_accessor_class_g2_mars_labeling.cc b/src/accessor/grib_accessor_class_g2_mars_labeling.cc index 4ea0f5e7c..b9059220f 100644 --- a/src/accessor/grib_accessor_class_g2_mars_labeling.cc +++ b/src/accessor/grib_accessor_class_g2_mars_labeling.cc @@ -11,15 +11,16 @@ #include "grib_accessor_class_g2_mars_labeling.h" -grib_accessor_class_g2_mars_labeling_t _grib_accessor_class_g2_mars_labeling{"g2_mars_labeling"}; +grib_accessor_class_g2_mars_labeling_t _grib_accessor_class_g2_mars_labeling{ "g2_mars_labeling" }; grib_accessor_class* grib_accessor_class_g2_mars_labeling = &_grib_accessor_class_g2_mars_labeling; -void grib_accessor_class_g2_mars_labeling_t::init(grib_accessor* a, const long l, grib_arguments* c){ +void grib_accessor_class_g2_mars_labeling_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ grib_accessor_class_gen_t::init(a, l, c); grib_accessor_g2_mars_labeling_t* self = (grib_accessor_g2_mars_labeling_t*)a; - int n = 0; - grib_handle* hand = grib_handle_of_accessor(a); + int n = 0; + grib_handle* hand = grib_handle_of_accessor(a); self->index = grib_arguments_get_long(hand, c, n++); self->the_class = grib_arguments_get_name(hand, c, n++); @@ -33,9 +34,10 @@ void grib_accessor_class_g2_mars_labeling_t::init(grib_accessor* a, const long l self->typeOfGeneratingProcess = grib_arguments_get_name(hand, c, n++); } -int grib_accessor_class_g2_mars_labeling_t::unpack_long(grib_accessor* a, long* val, size_t* len){ +int grib_accessor_class_g2_mars_labeling_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ grib_accessor_g2_mars_labeling_t* self = (grib_accessor_g2_mars_labeling_t*)a; - char* key = NULL; + char* key = NULL; switch (self->index) { case 0: @@ -56,9 +58,10 @@ int grib_accessor_class_g2_mars_labeling_t::unpack_long(grib_accessor* a, long* return grib_get_long(grib_handle_of_accessor(a), key, val); } -int grib_accessor_class_g2_mars_labeling_t::unpack_string(grib_accessor* a, char* val, size_t* len){ +int grib_accessor_class_g2_mars_labeling_t::unpack_string(grib_accessor* a, char* val, size_t* len) +{ grib_accessor_g2_mars_labeling_t* self = (grib_accessor_g2_mars_labeling_t*)a; - char* key = NULL; + char* key = NULL; switch (self->index) { case 0: @@ -79,11 +82,12 @@ int grib_accessor_class_g2_mars_labeling_t::unpack_string(grib_accessor* a, char return grib_get_string(grib_handle_of_accessor(a), key, val, len); } -int extra_set(grib_accessor* a, long val){ - int ret = 0; +static int extra_set(grib_accessor* a, long val) +{ + int ret = 0; grib_accessor_g2_mars_labeling_t* self = (grib_accessor_g2_mars_labeling_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); - char stepType[30] = {0,}; + grib_handle* hand = grib_handle_of_accessor(a); + char stepType[30] = {0,}; size_t stepTypelen = 30; long derivedForecast = -1; long productDefinitionTemplateNumberNew = -1; @@ -301,11 +305,12 @@ int extra_set(grib_accessor* a, long val){ return ret; } -int grib_accessor_class_g2_mars_labeling_t::pack_string(grib_accessor* a, const char* val, size_t* len){ +int grib_accessor_class_g2_mars_labeling_t::pack_string(grib_accessor* a, const char* val, size_t* len) +{ grib_accessor_g2_mars_labeling_t* self = (grib_accessor_g2_mars_labeling_t*)a; - char* key = NULL; - int ret = 0; - long lval = 0; + char* key = NULL; + int ret = 0; + long lval = 0; switch (self->index) { case 0: @@ -334,10 +339,11 @@ int grib_accessor_class_g2_mars_labeling_t::pack_string(grib_accessor* a, const return extra_set(a, lval); } -int grib_accessor_class_g2_mars_labeling_t::pack_long(grib_accessor* a, const long* val, size_t* len){ +int grib_accessor_class_g2_mars_labeling_t::pack_long(grib_accessor* a, const long* val, size_t* len) +{ grib_accessor_g2_mars_labeling_t* self = (grib_accessor_g2_mars_labeling_t*)a; - char* key = NULL; - int ret = 0; + char* key = NULL; + int ret = 0; switch (self->index) { case 0: @@ -362,16 +368,18 @@ int grib_accessor_class_g2_mars_labeling_t::pack_long(grib_accessor* a, const lo return extra_set(a, *val); } -int grib_accessor_class_g2_mars_labeling_t::value_count(grib_accessor* a, long* count){ +int grib_accessor_class_g2_mars_labeling_t::value_count(grib_accessor* a, long* count) +{ *count = 1; return 0; } -int grib_accessor_class_g2_mars_labeling_t::get_native_type(grib_accessor* a){ +int grib_accessor_class_g2_mars_labeling_t::get_native_type(grib_accessor* a) +{ grib_accessor_g2_mars_labeling_t* self = (grib_accessor_g2_mars_labeling_t*)a; - char* key = NULL; - int ret = 0; - int type = 0; + char* key = NULL; + int ret = 0; + int type = 0; switch (self->index) { case 0: @@ -389,7 +397,8 @@ int grib_accessor_class_g2_mars_labeling_t::get_native_type(grib_accessor* a){ return GRIB_INTERNAL_ERROR; } - ret = grib_get_native_type(grib_handle_of_accessor(a), key, &type); if (ret) + ret = grib_get_native_type(grib_handle_of_accessor(a), key, &type); + if (ret) grib_context_log(a->context, GRIB_LOG_ERROR, "unable to get native type for %s", key); return type; diff --git a/src/accessor/grib_accessor_class_g2end_step.cc b/src/accessor/grib_accessor_class_g2end_step.cc index 70fb9451c..6e8cfcda3 100644 --- a/src/accessor/grib_accessor_class_g2end_step.cc +++ b/src/accessor/grib_accessor_class_g2end_step.cc @@ -14,15 +14,16 @@ #include "step_utilities.h" #include -grib_accessor_class_g2end_step_t _grib_accessor_class_g2end_step{"g2end_step"}; +grib_accessor_class_g2end_step_t _grib_accessor_class_g2end_step{ "g2end_step" }; grib_accessor_class* grib_accessor_class_g2end_step = &_grib_accessor_class_g2end_step; -void grib_accessor_class_g2end_step_t::init(grib_accessor* a, const long l, grib_arguments* c){ +void grib_accessor_class_g2end_step_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ grib_accessor_class_long_t::init(a, l, c); grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a; - int n = 0; - grib_handle* h = grib_handle_of_accessor(a); + int n = 0; + grib_handle* h = grib_handle_of_accessor(a); self->start_step_value = grib_arguments_get_name(h, c, n++); self->step_units = grib_arguments_get_name(h, c, n++); @@ -41,29 +42,31 @@ void grib_accessor_class_g2end_step_t::init(grib_accessor* a, const long l, grib self->minute_of_end_of_interval = grib_arguments_get_name(h, c, n++); self->second_of_end_of_interval = grib_arguments_get_name(h, c, n++); - self->time_range_unit = grib_arguments_get_name(h, c, n++); + self->time_range_unit = grib_arguments_get_name(h, c, n++); self->time_range_value = grib_arguments_get_name(h, c, n++); self->typeOfTimeIncrement = grib_arguments_get_name(h, c, n++); self->numberOfTimeRange = grib_arguments_get_name(h, c, n++); } -void grib_accessor_class_g2end_step_t::dump(grib_accessor* a, grib_dumper* dumper){ +void grib_accessor_class_g2end_step_t::dump(grib_accessor* a, grib_dumper* dumper) +{ grib_dump_double(dumper, a, NULL); } // See GRIB-488 -bool is_special_expver(const grib_handle* h){ - int ret = 0; +bool is_special_expver(const grib_handle* h) +{ + int ret = 0; char strMarsExpVer[50] = {0,}; char strMarsClass[50] = {0,}; size_t slen = 50; - ret = grib_get_string(h, "mars.class", strMarsClass, &slen); + ret = grib_get_string(h, "mars.class", strMarsClass, &slen); if (ret == GRIB_SUCCESS && STR_EQUAL(strMarsClass, "em")) { // em = ERA-CLIM model integration for the 20th-century (ERA-20CM) slen = 50; - ret = grib_get_string(h, "experimentVersionNumber", strMarsExpVer, &slen); + ret = grib_get_string(h, "experimentVersionNumber", strMarsExpVer, &slen); if (ret == GRIB_SUCCESS && STR_EQUAL(strMarsExpVer, "1605")) { - return true; // Special case of expVer 1605 in class "em" + return true; // Special case of expVer 1605 in class "em" } } @@ -80,8 +83,8 @@ static int convert_time_range_long_( Assert(lengthOfTimeRange != NULL); if (indicatorOfUnitForTimeRange != stepUnits) { - eccodes::Step time_range{*lengthOfTimeRange, indicatorOfUnitForTimeRange}; - time_range.set_unit(eccodes::Unit{stepUnits}); + eccodes::Step time_range{ *lengthOfTimeRange, indicatorOfUnitForTimeRange }; + time_range.set_unit(eccodes::Unit{ stepUnits }); if (time_range.value() != time_range.value()) { return GRIB_DECODING_ERROR; } @@ -91,9 +94,10 @@ static int convert_time_range_long_( return GRIB_SUCCESS; } -int unpack_one_time_range_long_(grib_accessor* a, long* val, size_t* len){ +static int unpack_one_time_range_long_(grib_accessor* a, long* val, size_t* len) +{ grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a; - int err = 0; + int err = 0; long start_step_value; long step_units; long time_range_unit; @@ -139,9 +143,10 @@ int unpack_one_time_range_long_(grib_accessor* a, long* val, size_t* len){ return GRIB_SUCCESS; } -int unpack_one_time_range_double_(grib_accessor* a, double *val , size_t* len){ +static int unpack_one_time_range_double_(grib_accessor* a, double* val, size_t* len) +{ grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a; - int err = 0; + int err = 0; double start_step_value; long start_step_unit; long step_units; @@ -165,8 +170,8 @@ int unpack_one_time_range_double_(grib_accessor* a, double *val , size_t* len){ if ((err = grib_get_long_internal(h, self->typeOfTimeIncrement, &typeOfTimeIncrement))) return err; - eccodes::Step start_step{start_step_value, start_step_unit}; - eccodes::Step time_range{time_range_value, time_range_unit}; + eccodes::Step start_step{ start_step_value, start_step_unit }; + eccodes::Step time_range{ time_range_value, time_range_unit }; if (typeOfTimeIncrement == 1) { /* See GRIB-488 */ @@ -191,16 +196,23 @@ int unpack_one_time_range_double_(grib_accessor* a, double *val , size_t* len){ } #define MAX_NUM_TIME_RANGES 16 /* maximum number of time range specifications */ -int unpack_multiple_time_ranges_long_(grib_accessor* a, long* val, size_t* len){ +static int unpack_multiple_time_ranges_long_(grib_accessor* a, 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(a); long numberOfTimeRange = 0, step_units = 0, start_step_value = 0; - size_t count = 0; - long arr_typeOfTimeIncrement[MAX_NUM_TIME_RANGES] = {0,}; - long arr_coded_unit[MAX_NUM_TIME_RANGES] = {0,}; - long arr_coded_time_range[MAX_NUM_TIME_RANGES] = {0,}; + size_t count = 0; + long arr_typeOfTimeIncrement[MAX_NUM_TIME_RANGES] = { + 0, + }; + long arr_coded_unit[MAX_NUM_TIME_RANGES] = { + 0, + }; + long arr_coded_time_range[MAX_NUM_TIME_RANGES] = { + 0, + }; if ((err = grib_get_long_internal(h, self->start_step_value, &start_step_value))) return err; @@ -243,30 +255,37 @@ int unpack_multiple_time_ranges_long_(grib_accessor* a, long* val, size_t* len){ return GRIB_DECODING_ERROR; } -int unpack_multiple_time_ranges_double_(grib_accessor* a, double* val, size_t* len){ +static int unpack_multiple_time_ranges_double_(grib_accessor* a, 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(a); long numberOfTimeRange = 0; - long step_units = 0; - long start_step_value = 0; - long start_step_unit = 0; - - size_t count = 0; - long arr_typeOfTimeIncrement[MAX_NUM_TIME_RANGES] = {0, }; - long arr_coded_unit[MAX_NUM_TIME_RANGES] = {0, }; - long arr_coded_time_range[MAX_NUM_TIME_RANGES] = {0, }; + long step_units = 0; + long start_step_value = 0; + long start_step_unit = 0; + + size_t count = 0; + long arr_typeOfTimeIncrement[MAX_NUM_TIME_RANGES] = { + 0, + }; + long arr_coded_unit[MAX_NUM_TIME_RANGES] = { + 0, + }; + long arr_coded_time_range[MAX_NUM_TIME_RANGES] = { + 0, + }; if ((err = grib_get_long_internal(h, self->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}; + eccodes::Step start_step{ start_step_value, start_step_unit }; if ((err = grib_get_long_internal(h, self->step_units, &step_units))) return err; - + if ((err = grib_get_long_internal(h, self->numberOfTimeRange, &numberOfTimeRange))) return err; if (numberOfTimeRange > MAX_NUM_TIME_RANGES) { @@ -290,7 +309,7 @@ int unpack_multiple_time_ranges_double_(grib_accessor* a, double* val, size_t* l long the_coded_unit = arr_coded_unit[i]; long the_coded_time_range = arr_coded_time_range[i]; - eccodes::Step time_range{the_coded_unit, the_coded_time_range}; + eccodes::Step time_range{ the_coded_unit, the_coded_time_range }; *val = (start_step + time_range).value(eccodes::Unit(step_units)); return GRIB_SUCCESS; @@ -305,10 +324,11 @@ int unpack_multiple_time_ranges_double_(grib_accessor* a, double* val, size_t* l // For the old implementation of unpack_long, see // src/deprecated/grib_accessor_class_g2end_step.unpack_long.cc // -int grib_accessor_class_g2end_step_t::unpack_long(grib_accessor* a, long* val, size_t* len){ +int grib_accessor_class_g2end_step_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a; - grib_handle* h = grib_handle_of_accessor(a); - int ret = 0; + grib_handle* h = grib_handle_of_accessor(a); + int ret = 0; long start_step_value; long start_step_unit; long numberOfTimeRange; @@ -333,7 +353,7 @@ int grib_accessor_class_g2end_step_t::unpack_long(grib_accessor* a, long* val, s try { if (numberOfTimeRange == 1) { - ret = unpack_one_time_range_long_(a, val, len); + ret = unpack_one_time_range_long_(a, val, len); } else { ret = unpack_multiple_time_ranges_long_(a, val, len); @@ -347,10 +367,11 @@ int grib_accessor_class_g2end_step_t::unpack_long(grib_accessor* a, long* val, s return ret; } -int grib_accessor_class_g2end_step_t::unpack_double(grib_accessor* a, double* val, size_t* len){ +int grib_accessor_class_g2end_step_t::unpack_double(grib_accessor* a, double* val, size_t* len) +{ grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a; - grib_handle* h = grib_handle_of_accessor(a); - int ret = 0; + grib_handle* h = grib_handle_of_accessor(a); + int ret = 0; long start_step_value; long start_step_unit; long numberOfTimeRange; @@ -375,7 +396,7 @@ int grib_accessor_class_g2end_step_t::unpack_double(grib_accessor* a, double* va try { if (numberOfTimeRange == 1) { - ret = unpack_one_time_range_double_(a, val, len); + ret = unpack_one_time_range_double_(a, val, len); } else { ret = unpack_multiple_time_ranges_double_(a, val, len); @@ -389,10 +410,11 @@ int grib_accessor_class_g2end_step_t::unpack_double(grib_accessor* a, double* va return ret; } -int pack_long_(grib_accessor* a, const long end_step_value, const long end_step_unit){ +static int pack_long_(grib_accessor* a, 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); - int err = 0; + grib_handle* h = grib_handle_of_accessor(a); + int err = 0; long year; long month; @@ -415,7 +437,7 @@ int pack_long_(grib_accessor* a, const long end_step_value, const long end_step_ double dend, dstep; const int show_units_for_hours = a->context->grib_hourly_steps_with_units; - eccodes::Step end_step{end_step_value, end_step_unit}; + eccodes::Step end_step{ end_step_value, end_step_unit }; /*point in time */ if (self->year == NULL) { @@ -446,10 +468,10 @@ int pack_long_(grib_accessor* a, const long end_step_value, const long end_step_ return err; long force_step_units; - if ((err= grib_get_long_internal(h, "forceStepUnits", &force_step_units)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, "forceStepUnits", &force_step_units)) != GRIB_SUCCESS) return err; - if (eccodes::Unit{start_step_unit} == eccodes::Unit{eccodes::Unit::Value::MISSING}) { + if (eccodes::Unit{ start_step_unit } == eccodes::Unit{ eccodes::Unit::Value::MISSING }) { grib_context_log(h->context, GRIB_LOG_ERROR, "missing start step unit"); return GRIB_WRONG_STEP_UNIT; @@ -458,7 +480,7 @@ int pack_long_(grib_accessor* a, const long end_step_value, const long end_step_ if ((err = grib_get_long_internal(h, self->typeOfTimeIncrement, &typeOfTimeIncrement))) return err; - eccodes::Step start_step{start_step_value, start_step_unit}; + eccodes::Step start_step{ start_step_value, start_step_unit }; eccodes::Step time_range = end_step - start_step; if (time_range.value() < 0) { @@ -473,7 +495,7 @@ int pack_long_(grib_accessor* a, const long end_step_value, const long end_step_ if (err != GRIB_SUCCESS) return err; - dstep = end_step.value(eccodes::Unit{eccodes::Unit::Value::DAY}); + dstep = end_step.value(eccodes::Unit{ eccodes::Unit::Value::DAY }); dend += dstep; err = grib_julian_to_datetime(dend, &year_of_end_of_interval, &month_of_end_of_interval, @@ -496,15 +518,15 @@ int pack_long_(grib_accessor* a, const long end_step_value, const long end_step_ return err; const char* forecast_time_value_key = "forecastTime"; - const char* forecast_time_unit_key = "indicatorOfUnitOfTimeRange"; + const char* forecast_time_unit_key = "indicatorOfUnitOfTimeRange"; eccodes::Step forecast_time_opt; eccodes::Step time_range_opt; - if (eccodes::Unit{force_step_units} == eccodes::Unit{eccodes::Unit::Value::MISSING}) { + if (eccodes::Unit{ force_step_units } == eccodes::Unit{ eccodes::Unit::Value::MISSING }) { std::tie(forecast_time_opt, time_range_opt) = find_common_units(start_step.optimize_unit(), time_range.optimize_unit()); } else { - forecast_time_opt = eccodes::Step{start_step.value(eccodes::Unit{force_step_units}), eccodes::Unit{force_step_units}}; - time_range_opt = eccodes::Step{time_range.value(eccodes::Unit{force_step_units}), eccodes::Unit{force_step_units}}; + forecast_time_opt = eccodes::Step{ start_step.value(eccodes::Unit{ force_step_units }), eccodes::Unit{ force_step_units } }; + 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) @@ -519,13 +541,14 @@ int pack_long_(grib_accessor* a, const long end_step_value, const long end_step_ return GRIB_SUCCESS; } -int grib_accessor_class_g2end_step_t::unpack_string(grib_accessor* a, char* val, size_t* len){ +int grib_accessor_class_g2end_step_t::unpack_string(grib_accessor* a, char* val, size_t* len) +{ grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a; - grib_handle* h = grib_handle_of_accessor(a); - int ret = 0; - char fp_format[128] = "%g"; - size_t fp_format_len = sizeof(fp_format); - size_t step_len = 0; + grib_handle* h = grib_handle_of_accessor(a); + int ret = 0; + char fp_format[128] = "%g"; + size_t fp_format_len = sizeof(fp_format); + size_t step_len = 0; long step_value; long step_units; const int show_units_for_hours = a->context->grib_hourly_steps_with_units; @@ -562,7 +585,8 @@ int grib_accessor_class_g2end_step_t::unpack_string(grib_accessor* a, char* val, return GRIB_SUCCESS; } -int grib_accessor_class_g2end_step_t::pack_long(grib_accessor* a, const long* val, size_t* len){ +int grib_accessor_class_g2end_step_t::pack_long(grib_accessor* a, const long* val, size_t* len) +{ grib_handle* h = grib_handle_of_accessor(a); int ret; @@ -572,12 +596,12 @@ int grib_accessor_class_g2end_step_t::pack_long(grib_accessor* a, const long* va try { long end_step_unit; - if (eccodes::Unit{force_step_units} == eccodes::Unit{eccodes::Unit::Value::MISSING}) { + if (eccodes::Unit{ force_step_units } == eccodes::Unit{ eccodes::Unit::Value::MISSING }) { if ((ret = grib_get_long_internal(h, "endStepUnit", &end_step_unit)) != GRIB_SUCCESS) return ret; - if (eccodes::Unit{end_step_unit} == eccodes::Unit{eccodes::Unit::Value::MISSING}) - end_step_unit = eccodes::Unit{eccodes::Unit::Value::HOUR}.value(); + if (eccodes::Unit{ end_step_unit } == eccodes::Unit{ eccodes::Unit::Value::MISSING }) + end_step_unit = eccodes::Unit{ eccodes::Unit::Value::HOUR }.value(); } else { end_step_unit = force_step_units; @@ -591,15 +615,16 @@ int grib_accessor_class_g2end_step_t::pack_long(grib_accessor* a, const long* va return ret; } -int grib_accessor_class_g2end_step_t::pack_string(grib_accessor* a, const char* val, size_t* len){ +int grib_accessor_class_g2end_step_t::pack_string(grib_accessor* a, const char* val, size_t* len) +{ grib_handle* h = grib_handle_of_accessor(a); - int ret = 0; + int ret = 0; long force_step_units; if ((ret = grib_get_long_internal(h, "forceStepUnits", &force_step_units)) != GRIB_SUCCESS) return ret; try { - eccodes::Step end_step = step_from_string(val, eccodes::Unit{force_step_units}); + eccodes::Step end_step = step_from_string(val, eccodes::Unit{ force_step_units }); end_step.optimize_unit(); if ((ret = grib_set_long_internal(h, "endStepUnit", end_step.unit().value())) != GRIB_SUCCESS) @@ -615,15 +640,16 @@ int grib_accessor_class_g2end_step_t::pack_string(grib_accessor* a, const char* return GRIB_SUCCESS; } -int grib_accessor_class_g2end_step_t::get_native_type(grib_accessor* a){ - grib_handle* h = grib_handle_of_accessor(a); +int grib_accessor_class_g2end_step_t::get_native_type(grib_accessor* a) +{ + grib_handle* h = grib_handle_of_accessor(a); const int show_units_for_hours = a->context->grib_hourly_steps_with_units; if (!show_units_for_hours) { long step_units = 0; if (grib_get_long_internal(h, "stepUnits", &step_units) == GRIB_SUCCESS) { - if (eccodes::Unit{step_units} == eccodes::Unit::Value::HOUR) { - return GRIB_TYPE_LONG; // For backward compatibility + if (eccodes::Unit{ step_units } == eccodes::Unit::Value::HOUR) { + return GRIB_TYPE_LONG; // For backward compatibility } } } diff --git a/src/accessor/grib_accessor_class_g2grid.cc b/src/accessor/grib_accessor_class_g2grid.cc index 8f0bee1e5..3bc0a9a22 100644 --- a/src/accessor/grib_accessor_class_g2grid.cc +++ b/src/accessor/grib_accessor_class_g2grid.cc @@ -19,8 +19,8 @@ void grib_accessor_class_g2grid_t::init(grib_accessor* a, const long l, grib_arg { grib_accessor_class_double_t::init(a, l, c); grib_accessor_g2grid_t* self = (grib_accessor_g2grid_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int n = 0; + grib_handle* hand = grib_handle_of_accessor(a); + int n = 0; self->latitude_first = grib_arguments_get_name(hand, c, n++); self->longitude_first = grib_arguments_get_name(hand, c, n++); @@ -108,7 +108,7 @@ int grib_accessor_class_g2grid_t::unpack_double(grib_accessor* a, double* val, s return GRIB_SUCCESS; } -long gcd(long a, long b) +static long gcd(long a, long b) { if (b > a) return gcd(b, a); @@ -117,12 +117,12 @@ long gcd(long a, long b) return gcd(b, a % b); } -long lcm(long a, long b) +static long lcm(long a, long b) { return a * b / gcd(a, b); } -int is_ok(const double* val, long v[6], double basic_angle, double sub_division) +static int is_ok(const double* val, long v[6], double basic_angle, double sub_division) { int i; int ok = 1; @@ -147,7 +147,7 @@ int is_ok(const double* val, long v[6], double basic_angle, double sub_division) return ok; } -int trial(const double* val, long v[6], long* basic_angle, long* sub_division) +static int trial(const double* val, long v[6], long* basic_angle, long* sub_division) { int i = 0; long ni, nj; diff --git a/src/accessor/grib_accessor_class_longitudes.cc b/src/accessor/grib_accessor_class_longitudes.cc index 72b96aaf9..a9ae31309 100644 --- a/src/accessor/grib_accessor_class_longitudes.cc +++ b/src/accessor/grib_accessor_class_longitudes.cc @@ -15,7 +15,6 @@ grib_accessor_class_longitudes_t _grib_accessor_class_longitudes{"longitudes"}; grib_accessor_class* grib_accessor_class_longitudes = &_grib_accessor_class_longitudes; - static int get_distinct(grib_accessor* a, double** val, long* len); int compare_doubles(const void* a, const void* b); void grib_accessor_class_longitudes_t::init(grib_accessor* a, const long l, grib_arguments* c){ 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 9cabea10c..39324fbd3 100644 --- a/src/accessor/grib_accessor_class_number_of_points_gaussian.cc +++ b/src/accessor/grib_accessor_class_number_of_points_gaussian.cc @@ -11,27 +11,29 @@ #include "grib_accessor_class_number_of_points_gaussian.h" -grib_accessor_class_number_of_points_gaussian_t _grib_accessor_class_number_of_points_gaussian{"number_of_points_gaussian"}; +grib_accessor_class_number_of_points_gaussian_t _grib_accessor_class_number_of_points_gaussian{ "number_of_points_gaussian" }; grib_accessor_class* grib_accessor_class_number_of_points_gaussian = &_grib_accessor_class_number_of_points_gaussian; #define EFDEBUG 0 -void grib_accessor_class_number_of_points_gaussian_t::init(grib_accessor* a, const long l, grib_arguments* c){ +void grib_accessor_class_number_of_points_gaussian_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ grib_accessor_class_long_t::init(a, l, c); - int n = 0; - grib_handle* h = grib_handle_of_accessor(a); + int n = 0; + grib_handle* h = grib_handle_of_accessor(a); grib_accessor_number_of_points_gaussian_t* self = (grib_accessor_number_of_points_gaussian_t*)a; - self->ni = grib_arguments_get_name(h, c, n++); - self->nj = grib_arguments_get_name(h, c, n++); - self->plpresent = grib_arguments_get_name(h, c, n++); - self->pl = grib_arguments_get_name(h, c, n++); - self->order = grib_arguments_get_name(h, c, n++); - self->lat_first = grib_arguments_get_name(h, c, n++); - self->lon_first = grib_arguments_get_name(h, c, n++); - self->lat_last = grib_arguments_get_name(h, c, n++); - self->lon_last = grib_arguments_get_name(h, c, n++); - self->support_legacy = grib_arguments_get_name(h, c, n++); + + self->ni = grib_arguments_get_name(h, c, n++); + self->nj = grib_arguments_get_name(h, c, n++); + self->plpresent = grib_arguments_get_name(h, c, n++); + self->pl = grib_arguments_get_name(h, c, n++); + self->order = grib_arguments_get_name(h, c, n++); + self->lat_first = grib_arguments_get_name(h, c, n++); + self->lon_first = grib_arguments_get_name(h, c, n++); + self->lat_last = grib_arguments_get_name(h, c, n++); + self->lon_last = grib_arguments_get_name(h, c, n++); + self->support_legacy = grib_arguments_get_name(h, c, n++); a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; a->length = 0; @@ -40,12 +42,13 @@ void grib_accessor_class_number_of_points_gaussian_t::init(grib_accessor* a, con // Old implementation of num_points_reduced_gauss_old // See src/deprecated/grib_accessor_class_number_of_points_gaussian.cc // - -int angleApproximatelyEqual(double A, double B, double angular_precision){ +static int angleApproximatelyEqual(double A, double B, double angular_precision) +{ return angular_precision > 0 ? (fabs(A - B) <= angular_precision) : (A == B); } -double longitude_normalise(double lon, double minimum){ +static double longitude_normalise(double lon, double minimum) +{ while (lon < minimum) { lon += 360; } @@ -55,7 +58,8 @@ double longitude_normalise(double lon, double minimum){ return lon; } -void correctWestEast(long max_pl, double angular_precision, double* pWest, double* pEast){ +static void correctWestEast(long max_pl, double angular_precision, double* pWest, double* pEast) +{ double w, e; const double inc = 360.0 / max_pl; /*smallest increment*/ if (*pWest > *pEast) @@ -76,7 +80,8 @@ void correctWestEast(long max_pl, double angular_precision, double* pWest, doubl } } -int get_number_of_data_values(grib_handle* h, size_t* numDataValues){ +static int get_number_of_data_values(grib_handle* h, size_t* numDataValues) +{ int err = 0; long bpv = 0, bitmapPresent = 0; size_t bitmapLength = 0; @@ -110,11 +115,12 @@ int get_number_of_data_values(grib_handle* h, size_t* numDataValues){ int unpack_long_with_legacy_support(grib_accessor* a, long* val, size_t* len); int unpack_long_new(grib_accessor* a, long* val, size_t* len); -int grib_accessor_class_number_of_points_gaussian_t::unpack_long(grib_accessor* a, long* val, size_t* len){ - int err = GRIB_SUCCESS; - long support_legacy = 1; +int grib_accessor_class_number_of_points_gaussian_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ + int err = GRIB_SUCCESS; + long support_legacy = 1; grib_accessor_number_of_points_gaussian_t* self = (grib_accessor_number_of_points_gaussian_t*)a; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(a); if ((err = grib_get_long_internal(h, self->support_legacy, &support_legacy)) != GRIB_SUCCESS) return err; @@ -126,7 +132,8 @@ int grib_accessor_class_number_of_points_gaussian_t::unpack_long(grib_accessor* } /* New algorithm */ -int unpack_long_new(grib_accessor* a, long* val, size_t* len){ +int unpack_long_new(grib_accessor* a, long* val, size_t* len) +{ int err = GRIB_SUCCESS; int is_global = 0; long ni = 0, nj = 0, plpresent = 0, order = 0; @@ -141,7 +148,7 @@ int unpack_long_new(grib_accessor* a, long* val, size_t* len){ grib_handle* h = grib_handle_of_accessor(a); grib_accessor_number_of_points_gaussian_t* self = (grib_accessor_number_of_points_gaussian_t*)a; - grib_context* c = a->context; + grib_context* c = a->context; if ((err = grib_get_long_internal(h, self->ni, &ni)) != GRIB_SUCCESS) return err; @@ -161,8 +168,8 @@ int unpack_long_new(grib_accessor* a, long* val, size_t* len){ } if (plpresent) { - long max_pl = 0; - int j = 0; + long max_pl = 0; + int j = 0; // double lon_first_row = 0, lon_last_row = 0; /*reduced*/ @@ -211,8 +218,8 @@ int unpack_long_new(grib_accessor* a, long* val, size_t* len){ return GRIB_GEOCALCULUS_PROBLEM; } grib_get_reduced_row_wrapper(h, pl[j], lon_first, lon_last, &row_count, &ilon_first, &ilon_last); - //lon_first_row = ((ilon_first)*360.0) / pl[j]; - //lon_last_row = ((ilon_last)*360.0) / pl[j]; + // lon_first_row = ((ilon_first)*360.0) / pl[j]; + // lon_last_row = ((ilon_last)*360.0) / pl[j]; *val += row_count; } } @@ -234,7 +241,8 @@ int unpack_long_new(grib_accessor* a, long* val, size_t* len){ } /* With Legacy support */ -int unpack_long_with_legacy_support(grib_accessor* a, long* val, size_t* len){ +int unpack_long_with_legacy_support(grib_accessor* a, long* val, size_t* len) +{ int err = GRIB_SUCCESS; int is_global = 0; long ni = 0, nj = 0, plpresent = 0, order = 0; @@ -250,7 +258,7 @@ int unpack_long_with_legacy_support(grib_accessor* a, long* val, size_t* len){ size_t numDataValues = 0; grib_accessor_number_of_points_gaussian_t* self = (grib_accessor_number_of_points_gaussian_t*)a; - grib_context* c = a->context; + grib_context* c = a->context; if ((err = grib_get_long_internal(h, self->ni, &ni)) != GRIB_SUCCESS) return err; @@ -271,7 +279,7 @@ int unpack_long_with_legacy_support(grib_accessor* a, long* val, size_t* len){ if (plpresent) { long max_pl = 0; - int j = 0; + int j = 0; // double lon_first_row = 0, lon_last_row = 0; /*reduced*/ @@ -333,9 +341,9 @@ int unpack_long_with_legacy_support(grib_accessor* a, long* val, size_t* len){ } grib_get_reduced_row_wrapper(h, pl[j], lon_first, lon_last, &row_count, &ilon_first, &ilon_last); -// if ( row_count != pl[j] ) { -// printf("oops...... rc=%ld but pl[%d]=%ld\n", row_count, j,pl[j]); -// } + // if ( row_count != pl[j] ) { + // printf("oops...... rc=%ld but pl[%d]=%ld\n", row_count, j,pl[j]); + // } // lon_first_row = ((ilon_first)*360.0) / pl[j]; // lon_last_row = ((ilon_last)*360.0) / pl[j]; *val += row_count; diff --git a/src/accessor/grib_accessor_class_octahedral_gaussian.cc b/src/accessor/grib_accessor_class_octahedral_gaussian.cc index ca106dd4a..8c556e84a 100644 --- a/src/accessor/grib_accessor_class_octahedral_gaussian.cc +++ b/src/accessor/grib_accessor_class_octahedral_gaussian.cc @@ -36,7 +36,7 @@ void grib_accessor_class_octahedral_gaussian_t::init(grib_accessor* a, const lon * -4 ..-4 All below equator * Anything else is considered not octahedral */ -int is_pl_octahedral(const long pl[], size_t size){ +static int is_pl_octahedral(const long pl[], size_t size){ long i; long prev_diff = -1; for (i = 1; i < size; ++i) { diff --git a/src/accessor/grib_accessor_class_second_order_bits_per_value.cc b/src/accessor/grib_accessor_class_second_order_bits_per_value.cc index 1c253764a..ea7c4c931 100644 --- a/src/accessor/grib_accessor_class_second_order_bits_per_value.cc +++ b/src/accessor/grib_accessor_class_second_order_bits_per_value.cc @@ -35,7 +35,7 @@ static const size_t nbits[64] = { 0x1000000000000000, 0x2000000000000000, 0x4000000000000000, 0x8000000000000000 }; -int number_of_bits(size_t x, long* result){ +static int number_of_bits(size_t x, long* result){ const size_t* n = nbits; const int count = sizeof(nbits) / sizeof(nbits[0]); *result = 0; diff --git a/src/accessor/grib_accessor_class_smart_table.cc b/src/accessor/grib_accessor_class_smart_table.cc index b08e8b13b..1c49f2ab0 100644 --- a/src/accessor/grib_accessor_class_smart_table.cc +++ b/src/accessor/grib_accessor_class_smart_table.cc @@ -42,7 +42,7 @@ void thread_init() } #endif -int grib_load_smart_table(grib_context* c, const char* filename, const char* recomposed_name, size_t size, grib_smart_table* t); +static int grib_load_smart_table(grib_context* c, const char* filename, const char* recomposed_name, size_t size, grib_smart_table* t); void grib_accessor_class_smart_table_t::init(grib_accessor* a, const long len, grib_arguments* params) { @@ -162,7 +162,7 @@ grib_smart_table* load_table(grib_accessor* a) return t; } -int grib_load_smart_table(grib_context* c, const char* filename, +static int grib_load_smart_table(grib_context* c, const char* filename, const char* recomposed_name, size_t size, grib_smart_table* t) { char line[1024] = {0,}; @@ -324,7 +324,7 @@ int grib_accessor_class_smart_table_t::unpack_string(grib_accessor* a, char* buf return GRIB_SUCCESS; } -int get_table_codes(grib_accessor* a) +static int get_table_codes(grib_accessor* a) { grib_accessor_smart_table_t* self = (grib_accessor_smart_table_t*)a; size_t size = 0; diff --git a/src/accessor/grib_accessor_class_step_human_readable.cc b/src/accessor/grib_accessor_class_step_human_readable.cc index ea5280632..929733705 100644 --- a/src/accessor/grib_accessor_class_step_human_readable.cc +++ b/src/accessor/grib_accessor_class_step_human_readable.cc @@ -11,28 +11,31 @@ #include "grib_accessor_class_step_human_readable.h" -grib_accessor_class_step_human_readable_t _grib_accessor_class_step_human_readable{"step_human_readable"}; +grib_accessor_class_step_human_readable_t _grib_accessor_class_step_human_readable{ "step_human_readable" }; grib_accessor_class* grib_accessor_class_step_human_readable = &_grib_accessor_class_step_human_readable; -void grib_accessor_class_step_human_readable_t::init(grib_accessor* a, const long len, grib_arguments* params){ +void grib_accessor_class_step_human_readable_t::init(grib_accessor* a, const long len, grib_arguments* params) +{ grib_accessor_class_gen_t::init(a, len, params); grib_accessor_step_human_readable_t* self = (grib_accessor_step_human_readable_t*)a; - int n = 0; + int n = 0; grib_handle* h = grib_handle_of_accessor(a); - self->stepUnits = grib_arguments_get_name(h, params, n++); - self->step = grib_arguments_get_name(h, params, n++); - a->length = 0; + self->stepUnits = grib_arguments_get_name(h, params, n++); + self->step = grib_arguments_get_name(h, params, n++); + a->length = 0; a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -int grib_accessor_class_step_human_readable_t::get_native_type(grib_accessor* a){ +int grib_accessor_class_step_human_readable_t::get_native_type(grib_accessor* a) +{ return GRIB_TYPE_STRING; } -int get_step_human_readable(grib_handle* h, char* result, size_t* length){ - int err = 0; +static int get_step_human_readable(grib_handle* h, char* result, size_t* length) +{ + int err = 0; size_t slen = 2; long step, hour, minute, second; @@ -41,29 +44,33 @@ int get_step_human_readable(grib_handle* h, char* result, size_t* length){ */ if ((err = grib_set_string(h, "stepUnits", "s", &slen)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long(h, "step", &step)) != GRIB_SUCCESS) + if ((err = grib_get_long(h, "step", &step)) != GRIB_SUCCESS) return err; - hour = step/3600; - minute = step/60 % 60; + hour = step / 3600; + minute = step / 60 % 60; second = step % 60; /* sprintf(result, "%ld:%ld:%ld", hour, minute, second); */ if (second) { snprintf(result, 1024, "%ldh %ldm %lds", hour, minute, second); - } else { - if (minute) snprintf(result, 1024, "%ldh %ldm", hour, minute); - else snprintf(result, 1024, "%ldh", hour); + } + else { + if (minute) + snprintf(result, 1024, "%ldh %ldm", hour, minute); + else + snprintf(result, 1024, "%ldh", hour); } *length = strlen(result); return GRIB_SUCCESS; } -int grib_accessor_class_step_human_readable_t::unpack_string(grib_accessor* a, char* buffer, size_t* len){ +int grib_accessor_class_step_human_readable_t::unpack_string(grib_accessor* a, char* buffer, size_t* len) +{ grib_accessor_step_human_readable_t* self = (grib_accessor_step_human_readable_t*)a; grib_handle* h = grib_handle_of_accessor(a); - long stepUnits; + long stepUnits = 0; int err = 0; /* Save the current value of stepUnits */ diff --git a/src/accessor/grib_accessor_class_suppressed.cc b/src/accessor/grib_accessor_class_suppressed.cc index 14d5932bc..10a99ee64 100644 --- a/src/accessor/grib_accessor_class_suppressed.cc +++ b/src/accessor/grib_accessor_class_suppressed.cc @@ -11,23 +11,25 @@ #include "grib_accessor_class_suppressed.h" -grib_accessor_class_suppressed_t _grib_accessor_class_suppressed{"suppressed"}; +grib_accessor_class_suppressed_t _grib_accessor_class_suppressed{ "suppressed" }; grib_accessor_class* grib_accessor_class_suppressed = &_grib_accessor_class_suppressed; -void grib_accessor_class_suppressed_t::init(grib_accessor* a, const long l, grib_arguments* c){ +void grib_accessor_class_suppressed_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ grib_accessor_class_long_t::init(a, l, c); grib_accessor_suppressed_t* self = (grib_accessor_suppressed_t*)a; - self->args = c; + self->args = c; a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; a->length = 0; } -void log_message(grib_accessor* a){ +static void log_message(grib_accessor* a) +{ grib_accessor_suppressed_t* self = (grib_accessor_suppressed_t*)a; - int i = 0; - grib_handle* hand = grib_handle_of_accessor(a); + int i = 0; + grib_handle* hand = grib_handle_of_accessor(a); grib_context_log(a->context, GRIB_LOG_ERROR, "key '%s' is unavailable in this version.", a->name); @@ -40,26 +42,31 @@ void log_message(grib_accessor* a){ } } -int grib_accessor_class_suppressed_t::unpack_string(grib_accessor* a, char* val, size_t* len){ +int grib_accessor_class_suppressed_t::unpack_string(grib_accessor* a, char* val, size_t* len) +{ log_message(a); return GRIB_NOT_FOUND; } -int grib_accessor_class_suppressed_t::unpack_long(grib_accessor* a, long* val, size_t* len){ +int grib_accessor_class_suppressed_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ log_message(a); return GRIB_NOT_FOUND; } -int grib_accessor_class_suppressed_t::unpack_double(grib_accessor* a, double* val, size_t* len){ +int grib_accessor_class_suppressed_t::unpack_double(grib_accessor* a, double* val, size_t* len) +{ log_message(a); return GRIB_NOT_FOUND; } -int grib_accessor_class_suppressed_t::value_count(grib_accessor* a, long* count){ +int grib_accessor_class_suppressed_t::value_count(grib_accessor* a, long* count) +{ *count = 1; return 0; } -int grib_accessor_class_suppressed_t::get_native_type(grib_accessor* a){ +int grib_accessor_class_suppressed_t::get_native_type(grib_accessor* a) +{ return GRIB_TYPE_STRING; }