diff --git a/src/accessor/grib_accessor_class_position.cc b/src/accessor/grib_accessor_class_position.cc index f1a429270..a2c3daacd 100644 --- a/src/accessor/grib_accessor_class_position.cc +++ b/src/accessor/grib_accessor_class_position.cc @@ -11,11 +11,12 @@ #include "grib_accessor_class_position.h" -grib_accessor_class_position_t _grib_accessor_class_position{"position"}; +grib_accessor_class_position_t _grib_accessor_class_position{ "position" }; grib_accessor_class* grib_accessor_class_position = &_grib_accessor_class_position; -void grib_accessor_class_position_t::init(grib_accessor* a, const long len, grib_arguments* arg){ +void grib_accessor_class_position_t::init(grib_accessor* a, const long len, grib_arguments* arg) +{ grib_accessor_class_gen_t::init(a, len, arg); a->length = 0; a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; @@ -23,17 +24,20 @@ void grib_accessor_class_position_t::init(grib_accessor* a, const long len, grib a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; } -int grib_accessor_class_position_t::get_native_type(grib_accessor* a){ +int grib_accessor_class_position_t::get_native_type(grib_accessor* a) +{ return GRIB_TYPE_LONG; } -void grib_accessor_class_position_t::dump(grib_accessor* a, grib_dumper* dumper){ +void grib_accessor_class_position_t::dump(grib_accessor* a, grib_dumper* dumper) +{ grib_dump_long(dumper, a, NULL); } -int grib_accessor_class_position_t::unpack_long(grib_accessor* a, long* val, size_t* len){ +int grib_accessor_class_position_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ if (*len < 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values ", a->name, 1); + grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %d values ", a->name, 1); *len = 0; return GRIB_ARRAY_TOO_SMALL; } diff --git a/src/accessor/grib_accessor_class_proj_string.cc b/src/accessor/grib_accessor_class_proj_string.cc index f8c8e127f..03866753d 100644 --- a/src/accessor/grib_accessor_class_proj_string.cc +++ b/src/accessor/grib_accessor_class_proj_string.cc @@ -11,14 +11,15 @@ #include "grib_accessor_class_proj_string.h" -grib_accessor_class_proj_string_t _grib_accessor_class_proj_string{"proj_string"}; +grib_accessor_class_proj_string_t _grib_accessor_class_proj_string{ "proj_string" }; grib_accessor_class* grib_accessor_class_proj_string = &_grib_accessor_class_proj_string; -void grib_accessor_class_proj_string_t::init(grib_accessor* a, const long len, grib_arguments* arg){ +void grib_accessor_class_proj_string_t::init(grib_accessor* a, const long len, grib_arguments* arg) +{ grib_accessor_class_gen_t::init(a, len, arg); grib_accessor_proj_string_t* self = (grib_accessor_proj_string_t*)a; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(a); self->grid_type = grib_arguments_get_name(h, arg, 0); self->endpoint = grib_arguments_get_long(h, arg, 1); @@ -27,7 +28,8 @@ void grib_accessor_class_proj_string_t::init(grib_accessor* a, const long len, g a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; } -int grib_accessor_class_proj_string_t::get_native_type(grib_accessor* a){ +int grib_accessor_class_proj_string_t::get_native_type(grib_accessor* a) +{ return GRIB_TYPE_STRING; } @@ -35,13 +37,14 @@ int grib_accessor_class_proj_string_t::get_native_type(grib_accessor* a){ typedef int (*proj_func)(grib_handle*, char*); struct proj_mapping { - const char* gridType; // key gridType - proj_func func; // function to compute proj string + const char* gridType; // key gridType + proj_func func; // function to compute proj string }; typedef struct proj_mapping proj_mapping; // This should only be called for GRID POINT data (not spherical harmonics etc) -static int get_major_minor_axes(grib_handle* h, double* pMajor, double* pMinor){ +static int get_major_minor_axes(grib_handle* h, double* pMajor, double* pMinor) +{ int err = 0; if (grib_is_earth_oblate(h)) { if ((err = grib_get_double_internal(h, "earthMinorAxisInMetres", pMinor)) != GRIB_SUCCESS) return err; @@ -56,19 +59,21 @@ static int get_major_minor_axes(grib_handle* h, double* pMajor, double* pMinor){ } // Caller must have allocated enough space in the 'result' argument -static int get_earth_shape(grib_handle* h, char* result){ +static int get_earth_shape(grib_handle* h, char* result) +{ int err = 0; double major = 0, minor = 0; if ((err = get_major_minor_axes(h, &major, &minor)) != GRIB_SUCCESS) return err; if (major == minor) - snprintf(result, 128, "+R=%lf", major); // spherical + snprintf(result, 128, "+R=%lf", major); // spherical else - snprintf(result, 128, "+a=%lf +b=%lf", major, minor); // oblate + snprintf(result, 128, "+a=%lf +b=%lf", major, minor); // oblate return err; } -static int proj_space_view(grib_handle* h, char* result){ +static int proj_space_view(grib_handle* h, char* result) +{ return GRIB_NOT_IMPLEMENTED; // int err = 0; // char shape[128] = {0,}; @@ -84,18 +89,22 @@ static int proj_space_view(grib_handle* h, char* result){ // return err; } -static int proj_albers(grib_handle* h, char* result){ +static int proj_albers(grib_handle* h, char* result) +{ return GRIB_NOT_IMPLEMENTED; } -static int proj_transverse_mercator(grib_handle* h, char* result){ +static int proj_transverse_mercator(grib_handle* h, char* result) +{ return GRIB_NOT_IMPLEMENTED; } -static int proj_equatorial_azimuthal_equidistant(grib_handle* h, char* result){ +static int proj_equatorial_azimuthal_equidistant(grib_handle* h, char* result) +{ return GRIB_NOT_IMPLEMENTED; } -static int proj_lambert_conformal(grib_handle* h, char* result){ - int err = 0; +static int proj_lambert_conformal(grib_handle* h, char* result) +{ + int err = 0; char shape[128] = {0,}; double LoVInDegrees = 0, LaDInDegrees = 0, Latin1InDegrees = 0, Latin2InDegrees = 0; @@ -110,12 +119,13 @@ static int proj_lambert_conformal(grib_handle* h, char* result){ if ((err = grib_get_double_internal(h, "LaDInDegrees", &LaDInDegrees)) != GRIB_SUCCESS) return err; snprintf(result, 1024, "+proj=lcc +lon_0=%lf +lat_0=%lf +lat_1=%lf +lat_2=%lf %s", - LoVInDegrees, LaDInDegrees, Latin1InDegrees, Latin2InDegrees, shape); + LoVInDegrees, LaDInDegrees, Latin1InDegrees, Latin2InDegrees, shape); return err; } -static int proj_lambert_azimuthal_equal_area(grib_handle* h, char* result){ - int err = 0; +static int proj_lambert_azimuthal_equal_area(grib_handle* h, char* result) +{ + int err = 0; char shape[128] = {0,}; double standardParallel = 0, centralLongitude = 0; @@ -126,11 +136,12 @@ static int proj_lambert_azimuthal_equal_area(grib_handle* h, char* result){ if ((err = grib_get_double_internal(h, "centralLongitudeInDegrees", ¢ralLongitude)) != GRIB_SUCCESS) return err; snprintf(result, 1024, "+proj=laea +lon_0=%lf +lat_0=%lf %s", - centralLongitude, standardParallel, shape); + centralLongitude, standardParallel, shape); return err; } -static int proj_polar_stereographic(grib_handle* h, char* result){ +static int proj_polar_stereographic(grib_handle* h, char* result) +{ int err = 0; double centralLongitude = 0, centralLatitude = 0; int has_northPole = 0; @@ -147,33 +158,35 @@ static int proj_polar_stereographic(grib_handle* h, char* result){ return err; has_northPole = ((projectionCentreFlag & 128) == 0); snprintf(result, 1024, "+proj=stere +lat_ts=%lf +lat_0=%s +lon_0=%lf +k_0=1 +x_0=0 +y_0=0 %s", - centralLatitude, has_northPole ? "90" : "-90", centralLongitude, shape); + centralLatitude, has_northPole ? "90" : "-90", centralLongitude, shape); return err; } // ECC-1552: This is for regular_ll, regular_gg, reduced_ll, reduced_gg // These are not 'projected' grids! -static int proj_unprojected(grib_handle* h, char* result){ +static int proj_unprojected(grib_handle* h, char* result) +{ int err = 0; - //char shape[128] = {0,}; - //if ((err = get_earth_shape(h, shape)) != GRIB_SUCCESS) return err; - //snprintf(result, 1024, "+proj=longlat %s", shape); + // char shape[128] = {0,}; + // if ((err = get_earth_shape(h, shape)) != GRIB_SUCCESS) return err; + // snprintf(result, 1024, "+proj=longlat %s", shape); snprintf(result, 1024, "+proj=longlat +datum=WGS84 +no_defs +type=crs"); return err; } -static int proj_mercator(grib_handle* h, char* result){ +static int proj_mercator(grib_handle* h, char* result) +{ int err = 0; double LaDInDegrees = 0; - char shape[128] = {0,}; + char shape[128] = {0,}; if ((err = grib_get_double_internal(h, "LaDInDegrees", &LaDInDegrees)) != GRIB_SUCCESS) return err; if ((err = get_earth_shape(h, shape)) != GRIB_SUCCESS) return err; snprintf(result, 1024, "+proj=merc +lat_ts=%lf +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 %s", - LaDInDegrees, shape); + LaDInDegrees, shape); return err; } @@ -195,17 +208,18 @@ static proj_mapping proj_mappings[] = { #define ENDPOINT_SOURCE 0 #define ENDPOINT_TARGET 1 -int grib_accessor_class_proj_string_t::unpack_string(grib_accessor* a, char* v, size_t* len){ +int grib_accessor_class_proj_string_t::unpack_string(grib_accessor* a, char* v, size_t* len) +{ grib_accessor_proj_string_t* self = (grib_accessor_proj_string_t*)a; int err = 0, found = 0; - size_t i = 0; + size_t i = 0; char grid_type[64] = {0,}; grib_handle* h = grib_handle_of_accessor(a); - size_t size = sizeof(grid_type) / sizeof(*grid_type); + size_t size = sizeof(grid_type) / sizeof(*grid_type); Assert(self->endpoint == ENDPOINT_SOURCE || self->endpoint == ENDPOINT_TARGET); - size_t l = 100; // Safe bet + size_t l = 100; // Safe bet if (*len < l) { const char* cclass_name = a->cclass->name; grib_context_log(a->context, GRIB_LOG_ERROR, diff --git a/src/accessor/grib_accessor_class_raw.cc b/src/accessor/grib_accessor_class_raw.cc index 4a80b772a..cf1f502c7 100644 --- a/src/accessor/grib_accessor_class_raw.cc +++ b/src/accessor/grib_accessor_class_raw.cc @@ -11,11 +11,12 @@ #include "grib_accessor_class_raw.h" -grib_accessor_class_raw_t _grib_accessor_class_raw{"raw"}; +grib_accessor_class_raw_t _grib_accessor_class_raw{ "raw" }; grib_accessor_class* grib_accessor_class_raw = &_grib_accessor_class_raw; -void grib_accessor_class_raw_t::init(grib_accessor* a, const long len, grib_arguments* arg){ +void grib_accessor_class_raw_t::init(grib_accessor* a, const long len, grib_arguments* arg) +{ grib_accessor_class_gen_t::init(a, len, arg); int n = 0; int err = 0; @@ -42,31 +43,37 @@ void grib_accessor_class_raw_t::init(grib_accessor* a, const long len, grib_argu /* Assert(a->length>=0); */ } -int grib_accessor_class_raw_t::get_native_type(grib_accessor* a){ +int grib_accessor_class_raw_t::get_native_type(grib_accessor* a) +{ return GRIB_TYPE_BYTES; } -int grib_accessor_class_raw_t::compare(grib_accessor* a, grib_accessor* b){ +int grib_accessor_class_raw_t::compare(grib_accessor* a, grib_accessor* b) +{ int retval = GRIB_SUCCESS; - size_t alen = (size_t)a->byte_count(); size_t blen = (size_t)b->byte_count(); + size_t alen = (size_t)a->byte_count(); + size_t blen = (size_t)b->byte_count(); if (alen != blen) return GRIB_COUNT_MISMATCH; return retval; } -long grib_accessor_class_raw_t::byte_count(grib_accessor* a){ +long grib_accessor_class_raw_t::byte_count(grib_accessor* a) +{ return a->length; } -int grib_accessor_class_raw_t::value_count(grib_accessor* a, long* len){ +int grib_accessor_class_raw_t::value_count(grib_accessor* a, long* len) +{ *len = a->length; return 0; } -int grib_accessor_class_raw_t::unpack_bytes(grib_accessor* a, unsigned char* buffer, size_t* len){ +int grib_accessor_class_raw_t::unpack_bytes(grib_accessor* a, unsigned char* buffer, size_t* len) +{ if (*len < a->length) { *len = a->length; return GRIB_ARRAY_TOO_SMALL; @@ -78,7 +85,8 @@ int grib_accessor_class_raw_t::unpack_bytes(grib_accessor* a, unsigned char* buf return GRIB_SUCCESS; } -void grib_accessor_class_raw_t::update_size(grib_accessor* a, size_t s){ +void grib_accessor_class_raw_t::update_size(grib_accessor* a, size_t s) +{ grib_context_log(a->context, GRIB_LOG_DEBUG, "updating size of %s old %ld new %ld", a->name, a->length, s); a->length = s; Assert(a->length >= 0); @@ -94,13 +102,14 @@ long accessor_raw_get_offset(grib_accessor* a) return a->offset; } -int grib_accessor_class_raw_t::pack_bytes(grib_accessor* a, const unsigned char* val, size_t* len){ +int grib_accessor_class_raw_t::pack_bytes(grib_accessor* a, const unsigned char* val, size_t* len) +{ size_t length = *len; long totalLength; long sectionLength; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(a); grib_accessor_raw_t* self = (grib_accessor_raw_t*)a; - long dlen = length - a->length; + long dlen = length - a->length; grib_get_long(h, self->totalLength, &totalLength); totalLength += dlen; diff --git a/src/accessor/grib_accessor_class_rdbtime_guess_date.cc b/src/accessor/grib_accessor_class_rdbtime_guess_date.cc index 173e0a3dc..f4b317daa 100644 --- a/src/accessor/grib_accessor_class_rdbtime_guess_date.cc +++ b/src/accessor/grib_accessor_class_rdbtime_guess_date.cc @@ -15,10 +15,11 @@ grib_accessor_class_rdbtime_guess_date_t _grib_accessor_class_rdbtime_guess_date grib_accessor_class* grib_accessor_class_rdbtime_guess_date = &_grib_accessor_class_rdbtime_guess_date; -void grib_accessor_class_rdbtime_guess_date_t::init(grib_accessor* a, const long l, grib_arguments* c){ +void grib_accessor_class_rdbtime_guess_date_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ grib_accessor_class_long_t::init(a, l, c); grib_accessor_rdbtime_guess_date_t* self = (grib_accessor_rdbtime_guess_date_t*)a; - int n = 0; + int n = 0; self->typicalYear = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); self->typicalMonth = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); @@ -29,14 +30,14 @@ void grib_accessor_class_rdbtime_guess_date_t::init(grib_accessor* a, const long /* a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; */ } -int grib_accessor_class_rdbtime_guess_date_t::unpack_long(grib_accessor* a, long* val, size_t* len){ +int grib_accessor_class_rdbtime_guess_date_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ grib_accessor_rdbtime_guess_date_t* self = (grib_accessor_rdbtime_guess_date_t*)a; - grib_handle* h = grib_handle_of_accessor(a); - int ret = 0; + grib_handle* h = grib_handle_of_accessor(a); long typicalYear, typicalMonth, typicalDay, rdbDay; long rdbYear, rdbMonth; - ret = grib_get_long(h, self->typicalYear, &typicalYear); + int ret = grib_get_long(h, self->typicalYear, &typicalYear); if (ret) return ret; ret = grib_get_long(h, self->typicalMonth, &typicalMonth); @@ -70,7 +71,8 @@ int grib_accessor_class_rdbtime_guess_date_t::unpack_long(grib_accessor* a, long return GRIB_SUCCESS; } -int grib_accessor_class_rdbtime_guess_date_t::pack_long(grib_accessor* a, const long* v, size_t* len){ +int grib_accessor_class_rdbtime_guess_date_t::pack_long(grib_accessor* a, const long* v, size_t* len) +{ /* do nothing*/ return GRIB_SUCCESS; } diff --git a/src/accessor/grib_accessor_class_reference_value_error.cc b/src/accessor/grib_accessor_class_reference_value_error.cc index 9a1dba20b..fbf1a1c1b 100644 --- a/src/accessor/grib_accessor_class_reference_value_error.cc +++ b/src/accessor/grib_accessor_class_reference_value_error.cc @@ -11,14 +11,15 @@ #include "grib_accessor_class_reference_value_error.h" -grib_accessor_class_reference_value_error_t _grib_accessor_class_reference_value_error{"reference_value_error"}; +grib_accessor_class_reference_value_error_t _grib_accessor_class_reference_value_error{ "reference_value_error" }; grib_accessor_class* grib_accessor_class_reference_value_error = &_grib_accessor_class_reference_value_error; -void grib_accessor_class_reference_value_error_t::init(grib_accessor* a, const long l, grib_arguments* c){ +void grib_accessor_class_reference_value_error_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ grib_accessor_class_double_t::init(a, l, c); grib_accessor_reference_value_error_t* self = (grib_accessor_reference_value_error_t*)a; - int n = 0; + int n = 0; self->referenceValue = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); self->floatType = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); @@ -27,10 +28,11 @@ void grib_accessor_class_reference_value_error_t::init(grib_accessor* a, const l a->length = 0; } -int grib_accessor_class_reference_value_error_t::unpack_double(grib_accessor* a, double* val, size_t* len){ +int grib_accessor_class_reference_value_error_t::unpack_double(grib_accessor* a, double* val, size_t* len) +{ grib_accessor_reference_value_error_t* self = (grib_accessor_reference_value_error_t*)a; - int ret = 0; - double referenceValue = 0; + int ret = GRIB_SUCCESS; + double referenceValue = 0; if ((ret = grib_get_double_internal(grib_handle_of_accessor(a), self->referenceValue, &referenceValue)) != GRIB_SUCCESS) diff --git a/src/accessor/grib_accessor_class_round.cc b/src/accessor/grib_accessor_class_round.cc index f56fa4a1c..e1d6aaeda 100644 --- a/src/accessor/grib_accessor_class_round.cc +++ b/src/accessor/grib_accessor_class_round.cc @@ -11,11 +11,12 @@ #include "grib_accessor_class_round.h" -grib_accessor_class_round_t _grib_accessor_class_round{"round"}; +grib_accessor_class_round_t _grib_accessor_class_round{ "round" }; grib_accessor_class* grib_accessor_class_round = &_grib_accessor_class_round; -int grib_accessor_class_round_t::unpack_double(grib_accessor* a, double* val, size_t* len){ +int grib_accessor_class_round_t::unpack_double(grib_accessor* a, double* val, size_t* len) +{ grib_accessor_round_t* self = (grib_accessor_round_t*)a; int ret = GRIB_SUCCESS; @@ -42,7 +43,8 @@ int grib_accessor_class_round_t::unpack_double(grib_accessor* a, double* val, si return ret; } -int grib_accessor_class_round_t::unpack_string(grib_accessor* a, char* val, size_t* len){ +int grib_accessor_class_round_t::unpack_string(grib_accessor* a, char* val, size_t* len) +{ char result[1024]; int ret = GRIB_SUCCESS; size_t replen = 1; diff --git a/src/accessor/grib_accessor_class_scale.cc b/src/accessor/grib_accessor_class_scale.cc index eb01412d2..59ab7bfb4 100644 --- a/src/accessor/grib_accessor_class_scale.cc +++ b/src/accessor/grib_accessor_class_scale.cc @@ -11,14 +11,15 @@ #include "grib_accessor_class_scale.h" -grib_accessor_class_scale_t _grib_accessor_class_scale{"scale"}; +grib_accessor_class_scale_t _grib_accessor_class_scale{ "scale" }; grib_accessor_class* grib_accessor_class_scale = &_grib_accessor_class_scale; -void grib_accessor_class_scale_t::init(grib_accessor* a, const long l, grib_arguments* c){ +void grib_accessor_class_scale_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ grib_accessor_class_double_t::init(a, l, c); grib_accessor_scale_t* self = (grib_accessor_scale_t*)a; - int n = 0; + int n = 0; self->value = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); self->multiplier = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); @@ -26,12 +27,13 @@ void grib_accessor_class_scale_t::init(grib_accessor* a, const long l, grib_argu self->truncating = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); } -int grib_accessor_class_scale_t::unpack_double(grib_accessor* a, double* val, size_t* len){ +int grib_accessor_class_scale_t::unpack_double(grib_accessor* a, double* val, size_t* len) +{ grib_accessor_scale_t* self = (grib_accessor_scale_t*)a; - int ret = 0; - long value = 0; - long multiplier = 0; - long divisor = 0; + int ret = 0; + long value = 0; + long multiplier = 0; + long divisor = 0; if (*len < 1) { ret = GRIB_ARRAY_TOO_SMALL; @@ -61,14 +63,16 @@ int grib_accessor_class_scale_t::unpack_double(grib_accessor* a, double* val, si return ret; } -int grib_accessor_class_scale_t::pack_long(grib_accessor* a, const long* val, size_t* len){ +int grib_accessor_class_scale_t::pack_long(grib_accessor* a, const long* val, size_t* len) +{ const double dval = (double)*val; return pack_double(a, &dval, len); } -int grib_accessor_class_scale_t::pack_double(grib_accessor* a, const double* val, size_t* len){ +int grib_accessor_class_scale_t::pack_double(grib_accessor* a, const double* val, size_t* len) +{ grib_accessor_scale_t* self = (grib_accessor_scale_t*)a; - int ret = 0; + int ret = 0; long value = 0; long divisor = 0; @@ -115,9 +119,10 @@ int grib_accessor_class_scale_t::pack_double(grib_accessor* a, const double* val return ret; } -int grib_accessor_class_scale_t::is_missing(grib_accessor* a){ +int grib_accessor_class_scale_t::is_missing(grib_accessor* a) +{ grib_accessor_scale_t* self = (grib_accessor_scale_t*)a; - grib_accessor* av = grib_find_accessor(grib_handle_of_accessor(a), self->value); + grib_accessor* av = grib_find_accessor(grib_handle_of_accessor(a), self->value); if (!av) return GRIB_NOT_FOUND; diff --git a/src/accessor/grib_accessor_class_scale_values.cc b/src/accessor/grib_accessor_class_scale_values.cc index 03c5e0de2..03072311d 100644 --- a/src/accessor/grib_accessor_class_scale_values.cc +++ b/src/accessor/grib_accessor_class_scale_values.cc @@ -11,36 +11,39 @@ #include "grib_accessor_class_scale_values.h" -grib_accessor_class_scale_values_t _grib_accessor_class_scale_values{"scale_values"}; +grib_accessor_class_scale_values_t _grib_accessor_class_scale_values{ "scale_values" }; grib_accessor_class* grib_accessor_class_scale_values = &_grib_accessor_class_scale_values; -void grib_accessor_class_scale_values_t::init(grib_accessor* a, const long l, grib_arguments* args){ +void grib_accessor_class_scale_values_t::init(grib_accessor* a, const long l, grib_arguments* args) +{ grib_accessor_class_double_t::init(a, l, args); - int n = 0; + int n = 0; grib_accessor_scale_values_t* self = (grib_accessor_scale_values_t*)a; - self->values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - self->missingValue = 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->missingValue = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; a->length = 0; } -int grib_accessor_class_scale_values_t::unpack_double(grib_accessor* a, double* val, size_t* len){ - int ret = 0; +int grib_accessor_class_scale_values_t::unpack_double(grib_accessor* a, double* val, size_t* len) +{ + int ret = GRIB_SUCCESS; *val = 1; *len = 1; return ret; } -int grib_accessor_class_scale_values_t::pack_double(grib_accessor* a, const double* val, size_t* len){ +int grib_accessor_class_scale_values_t::pack_double(grib_accessor* a, const double* val, size_t* len) +{ double* values = NULL; double missingValue = 0; long missingValuesPresent = 0; size_t size = 0; int ret = 0, i = 0; grib_accessor_scale_values_t* self = (grib_accessor_scale_values_t*)a; - const grib_context* c = a->context; - grib_handle* h = grib_handle_of_accessor(a); + const grib_context* c = a->context; + grib_handle* h = grib_handle_of_accessor(a); if (*val == 1) return GRIB_SUCCESS; diff --git a/src/accessor/grib_accessor_class_signed.cc b/src/accessor/grib_accessor_class_signed.cc index dea029231..36c20bd59 100644 --- a/src/accessor/grib_accessor_class_signed.cc +++ b/src/accessor/grib_accessor_class_signed.cc @@ -11,24 +11,28 @@ #include "grib_accessor_class_signed.h" -grib_accessor_class_signed_t _grib_accessor_class_signed{"signed"}; +grib_accessor_class_signed_t _grib_accessor_class_signed{ "signed" }; grib_accessor_class* grib_accessor_class_signed = &_grib_accessor_class_signed; -void grib_accessor_class_signed_t::init(grib_accessor* a, const long len, grib_arguments* arg){ +void grib_accessor_class_signed_t::init(grib_accessor* a, const long len, grib_arguments* arg) +{ grib_accessor_class_long_t::init(a, len, arg); grib_accessor_signed_t* self = (grib_accessor_signed_t*)a; - long count = 0; + long count = 0; self->arg = arg; - a->value_count(&count); a->length = len * count; + a->value_count(&count); + a->length = len * count; self->nbytes = len; Assert(a->length >= 0); } -void grib_accessor_class_signed_t::dump(grib_accessor* a, grib_dumper* dumper){ +void grib_accessor_class_signed_t::dump(grib_accessor* a, grib_dumper* dumper) +{ long rlen = 0; - a->value_count(&rlen); if (rlen == 1) + a->value_count(&rlen); + if (rlen == 1) grib_dump_long(dumper, a, NULL); else grib_dump_values(dumper, a); @@ -42,17 +46,19 @@ static const long ones[] = { -0x7fffffff, }; -int grib_accessor_class_signed_t::unpack_long(grib_accessor* a, long* val, size_t* len){ +int grib_accessor_class_signed_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ grib_accessor_signed_t* self = (grib_accessor_signed_t*)a; - unsigned long rlen = 0; - int err = 0; - long count = 0; - unsigned long i = 0; - grib_handle* hand = grib_handle_of_accessor(a); - long pos = a->offset; - long missing = 0; + unsigned long rlen = 0; + int err = 0; + long count = 0; + unsigned long i = 0; + grib_handle* hand = grib_handle_of_accessor(a); + long pos = a->offset; + long missing = 0; - err = a->value_count(&count); if (err) + err = a->value_count(&count); + if (err) return err; rlen = count; @@ -79,19 +85,21 @@ int grib_accessor_class_signed_t::unpack_long(grib_accessor* a, long* val, size_ return GRIB_SUCCESS; } -int grib_accessor_class_signed_t::pack_long(grib_accessor* a, const long* val, size_t* len){ +int grib_accessor_class_signed_t::pack_long(grib_accessor* a, const long* val, size_t* len) +{ grib_accessor_signed_t* self = (grib_accessor_signed_t*)a; - int ret = 0; - long off = 0; - unsigned long rlen = 0; - int err = 0; - long count = 0; - size_t buflen = 0; - unsigned char* buf = NULL; - unsigned long i = 0; - long missing = 0; - err = a->value_count(&count); if (err) + int ret = 0; + long off = 0; + unsigned long rlen = 0; + long count = 0; + size_t buflen = 0; + unsigned char* buf = NULL; + unsigned long i = 0; + long missing = 0; + + int err = a->value_count(&count); + if (err) return err; rlen = count; @@ -111,16 +119,17 @@ int grib_accessor_class_signed_t::pack_long(grib_accessor* a, const long* val, s if (missing) { if (v == GRIB_MISSING_LONG) v = missing; - } else { + } + else { // ECC-1605: Check overflow/underflow - const int nbits = self->nbytes * 8; - const long minval = -(1L << (nbits-1)) + 1; - const long maxval = (1L << (nbits-1)) - 1; - //printf(" key=%s: v=%ld (minval=%ld maxval=%ld)\n", a->name, v, minval, maxval); + const int nbits = self->nbytes * 8; + const long minval = -(1L << (nbits - 1)) + 1; + const long maxval = (1L << (nbits - 1)) - 1; + // printf(" key=%s: v=%ld (minval=%ld maxval=%ld)\n", a->name, v, minval, maxval); if (v > maxval || v < minval) { grib_context_log(a->context, GRIB_LOG_ERROR, - "Key \"%s\": Trying to encode value of %ld but the allowable range is %ld to %ld (number of bits=%d)", - a->name, v, minval, maxval, nbits); + "Key \"%s\": Trying to encode value of %ld but the allowable range is %ld to %ld (number of bits=%d)", + a->name, v, minval, maxval, nbits); return GRIB_ENCODING_ERROR; } } @@ -156,13 +165,15 @@ int grib_accessor_class_signed_t::pack_long(grib_accessor* a, const long* val, s return ret; } -long grib_accessor_class_signed_t::byte_count(grib_accessor* a){ +long grib_accessor_class_signed_t::byte_count(grib_accessor* a) +{ return a->length; } -int grib_accessor_class_signed_t::value_count(grib_accessor* a, long* len){ +int grib_accessor_class_signed_t::value_count(grib_accessor* a, long* len) +{ grib_accessor_signed_t* self = (grib_accessor_signed_t*)a; - *len = 0; + *len = 0; if (!self->arg) { *len = 1; return 0; @@ -170,19 +181,24 @@ int grib_accessor_class_signed_t::value_count(grib_accessor* a, long* len){ return grib_get_long_internal(grib_handle_of_accessor(a), grib_arguments_get_name(a->parent->h, self->arg, 0), len); } -long grib_accessor_class_signed_t::byte_offset(grib_accessor* a){ +long grib_accessor_class_signed_t::byte_offset(grib_accessor* a) +{ return a->offset; } -void grib_accessor_class_signed_t::update_size(grib_accessor* a, size_t s){ +void grib_accessor_class_signed_t::update_size(grib_accessor* a, size_t s) +{ a->length = s; Assert(a->length >= 0); } -long grib_accessor_class_signed_t::next_offset(grib_accessor* a){ - return a->byte_offset() + a->byte_count();} +long grib_accessor_class_signed_t::next_offset(grib_accessor* a) +{ + return a->byte_offset() + a->byte_count(); +} -int grib_accessor_class_signed_t::is_missing(grib_accessor* a){ +int grib_accessor_class_signed_t::is_missing(grib_accessor* a) +{ int i = 0; unsigned char ff = 0xff; unsigned long offset = a->offset; diff --git a/src/accessor/grib_accessor_class_size.cc b/src/accessor/grib_accessor_class_size.cc index a9aa37f06..71c0dd947 100644 --- a/src/accessor/grib_accessor_class_size.cc +++ b/src/accessor/grib_accessor_class_size.cc @@ -11,25 +11,27 @@ #include "grib_accessor_class_size.h" -grib_accessor_class_size_t _grib_accessor_class_size{"size"}; +grib_accessor_class_size_t _grib_accessor_class_size{ "size" }; grib_accessor_class* grib_accessor_class_size = &_grib_accessor_class_size; -void grib_accessor_class_size_t::init(grib_accessor* a, const long l, grib_arguments* c){ +void grib_accessor_class_size_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ grib_accessor_class_long_t::init(a, l, c); grib_accessor_size_t* self = (grib_accessor_size_t*)a; - self->accessor = grib_arguments_get_name(grib_handle_of_accessor(a), c, 0); + self->accessor = grib_arguments_get_name(grib_handle_of_accessor(a), c, 0); a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; a->length = 0; } -int grib_accessor_class_size_t::unpack_long(grib_accessor* a, long* val, size_t* len){ - int ret = 0; - size_t size = 0; +int grib_accessor_class_size_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ grib_accessor_size_t* self = (grib_accessor_size_t*)a; - ret = grib_get_size(grib_handle_of_accessor(a), self->accessor, &size); - *val = (long)size; - *len = 1; + + size_t size = 0; + int ret = grib_get_size(grib_handle_of_accessor(a), self->accessor, &size); + *val = (long)size; + *len = 1; return ret; }