From 85e6d58a6abb7f596381ef2e721278264921cc89 Mon Sep 17 00:00:00 2001 From: Eugen Betke Date: Mon, 22 May 2023 03:07:48 +0000 Subject: [PATCH 01/12] Enable single-Precision --- fortran/grib_fortran.c | 53 ++++++++++--------- ...rib_accessor_class_data_complex_packing.cc | 37 ++++++------- 2 files changed, 48 insertions(+), 42 deletions(-) diff --git a/fortran/grib_fortran.c b/fortran/grib_fortran.c index 976eaa2ce..3a2529c21 100644 --- a/fortran/grib_fortran.c +++ b/fortran/grib_fortran.c @@ -2783,38 +2783,41 @@ int grib_f_get_real4(int* gid, char* key, float* val, int len){ int grib_f_get_real4_array_(int* gid, char* key, float *val, int* size, int len) { - /* See ECC-1579: - * Ideally we should be calling: - * err = grib_get_float_array(h, cast_char(buf,key,len), val, &lsize); - * - */ - + /*See ECC-1579:*/ + /*Ideally we should be calling:*/ + + size_t lsize = *size; + char buf[1024]; grib_handle *h = get_handle(*gid); int err = GRIB_SUCCESS; - char buf[1024]; - size_t lsize = *size; - double* val8 = NULL; - size_t i; + err = grib_get_float_array(h, cast_char(buf,key,len), val, &lsize); - if(!h) return GRIB_INVALID_GRIB; + /*grib_handle *h = get_handle(*gid);*/ + /*int err = GRIB_SUCCESS;*/ + /*char buf[1024];*/ + /*size_t lsize = *size;*/ + /*double* val8 = NULL;*/ + /*size_t i;*/ - if(*size) - val8 = (double*)grib_context_malloc(h->context,(*size)*(sizeof(double))); - else - val8 = (double*)grib_context_malloc(h->context,sizeof(double)); + /*if(!h) return GRIB_INVALID_GRIB;*/ - if(!val8) return GRIB_OUT_OF_MEMORY; + /*if(*size)*/ + /* val8 = (double*)grib_context_malloc(h->context,(*size)*(sizeof(double)));*/ + /*else*/ + /* val8 = (double*)grib_context_malloc(h->context,sizeof(double));*/ - err = grib_get_double_array(h, cast_char(buf,key,len), val8, &lsize); - if (err) { - grib_context_free(h->context,val8); - return err; - } + /*if(!val8) return GRIB_OUT_OF_MEMORY;*/ - for(i=0;icontext,val8);*/ + /* return err;*/ + /*}*/ - grib_context_free(h->context,val8); + /*for(i=0;icontext,val8);*/ return err; } @@ -3157,6 +3160,7 @@ int grib_f_get_real8_array_(int* gid, char* key, double*val, int* size, int len) return GRIB_INVALID_GRIB; }else{ err = grib_get_double_array(h, cast_char(buf,key,len), val, &lsize); + printf("%30s - %0.60f\n", __PRETTY_FUNCTION__, val[40]); *size = lsize; return err; } @@ -3166,6 +3170,7 @@ int grib_f_get_real8_array__(int* gid, char* key, double*val, int* size, int len } int grib_f_get_real8_array(int* gid, char* key, double*val, int* size, int len){ return grib_f_get_real8_array_( gid, key, val, size, len); + printf("%s - %0.60f\n", __PRETTY_FUNCTION__, val[40]); } int grib_f_set_force_real8_array__(int* gid, char* key, double *val, int* size, int len){ diff --git a/src/grib_accessor_class_data_complex_packing.cc b/src/grib_accessor_class_data_complex_packing.cc index 6f5122d9b..dd6eec70b 100644 --- a/src/grib_accessor_class_data_complex_packing.cc +++ b/src/grib_accessor_class_data_complex_packing.cc @@ -755,6 +755,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) if ((ret = grib_get_double_internal(gh, self->laplacianOperator, &laplacianOperator)) != GRIB_SUCCESS) return ret; + if ((ret = grib_get_long_internal(gh, self->sub_j, &sub_j)) != GRIB_SUCCESS) return ret; if ((ret = grib_get_long_internal(gh, self->sub_k, &sub_k)) != GRIB_SUCCESS) @@ -905,24 +906,24 @@ static int unpack_float(grib_accessor* a, float* val, size_t* len) // TODO(maee): See ECC-1579 // Investigate why results are not bit-identical - // return unpack(a, val, len); - - int err = 0; - size_t i = 0; - size_t size = *len; - double* val8 = NULL; - val8 = (double*)grib_context_malloc(a->context, size*(sizeof(double))); - if (!val8) - return GRIB_OUT_OF_MEMORY; - err = unpack(a, val8, len); - if (err) { - grib_context_free(a->context,val8); - return err; - } - - for(i=0; icontext,val8); + return unpack(a, val, len); + + //int err = 0; + //size_t i = 0; + //size_t size = *len; + //double* val8 = NULL; + //val8 = (double*)grib_context_malloc(a->context, size*(sizeof(double))); + //if (!val8) + // return GRIB_OUT_OF_MEMORY; + //err = unpack(a, val8, len); + //if (err) { + // grib_context_free(a->context,val8); + // return err; + //} + + //for(i=0; icontext,val8); return GRIB_SUCCESS; } From 60780b41eaebf51024df83cd26e04bbfcd8bdb41 Mon Sep 17 00:00:00 2001 From: Eugen Betke Date: Wed, 24 May 2023 11:17:05 +0000 Subject: [PATCH 02/12] Single-Precision: templatize grib_power() --- fortran/grib_fortran.c | 4 +- src/eccodes_prototypes.h | 2 +- src/functions.cc | 3 +- src/grib_accessor_class_apply_operators.cc | 3 +- src/grib_accessor_class_bufr_data_array.cc | 10 ++--- ...grib_accessor_class_bufr_elements_table.cc | 3 +- ...grib_accessor_class_data_2order_packing.cc | 9 +++-- src/grib_accessor_class_data_ccsds_packing.cc | 16 ++++---- ...rib_accessor_class_data_complex_packing.cc | 30 ++++++++------- ...a_g1second_order_constant_width_packing.cc | 5 ++- ...g1second_order_general_extended_packing.cc | 37 ++++++++++--------- ...ass_data_g1second_order_general_packing.cc | 5 ++- ..._data_g1second_order_row_by_row_packing.cc | 5 ++- ...ib_accessor_class_data_g1simple_packing.cc | 5 ++- ...ib_accessor_class_data_g22order_packing.cc | 5 ++- ...accessor_class_data_g2bifourier_packing.cc | 9 +++-- ...ib_accessor_class_data_g2simple_packing.cc | 5 ++- ...ib_accessor_class_data_jpeg2000_packing.cc | 9 +++-- src/grib_accessor_class_data_png_packing.cc | 9 +++-- ..._accessor_class_data_run_length_packing.cc | 3 +- src/grib_accessor_class_data_sh_packed.cc | 5 ++- src/grib_accessor_class_data_sh_unpacked.cc | 5 ++- ...grib_accessor_class_data_simple_packing.cc | 24 ++++++------ ...rib_accessor_class_expanded_descriptors.cc | 3 +- ...essor_class_second_order_bits_per_value.cc | 5 ++- ...rib_accessor_class_simple_packing_error.cc | 3 +- src/grib_api_cpp.h | 13 +++++++ src/grib_api_internal.h | 2 - src/grib_api_internal_cpp.h | 1 + src/grib_bits_any_endian.cc | 4 +- src/grib_bufr_descriptor.cc | 3 +- src/grib_header_compute.cc | 2 +- src/grib_optimize_decimal_factor.cc | 21 ++++++----- src/grib_scaling.cc | 30 +++------------ src/grib_scaling.h | 23 ++++++++++++ 35 files changed, 182 insertions(+), 139 deletions(-) create mode 100644 src/grib_api_cpp.h create mode 100644 src/grib_scaling.h diff --git a/fortran/grib_fortran.c b/fortran/grib_fortran.c index 3a2529c21..e6fa07439 100644 --- a/fortran/grib_fortran.c +++ b/fortran/grib_fortran.c @@ -3160,7 +3160,7 @@ int grib_f_get_real8_array_(int* gid, char* key, double*val, int* size, int len) return GRIB_INVALID_GRIB; }else{ err = grib_get_double_array(h, cast_char(buf,key,len), val, &lsize); - printf("%30s - %0.60f\n", __PRETTY_FUNCTION__, val[40]); + printf("%30s - %0.60f\n", __func__, val[40]); *size = lsize; return err; } @@ -3170,7 +3170,7 @@ int grib_f_get_real8_array__(int* gid, char* key, double*val, int* size, int len } int grib_f_get_real8_array(int* gid, char* key, double*val, int* size, int len){ return grib_f_get_real8_array_( gid, key, val, size, len); - printf("%s - %0.60f\n", __PRETTY_FUNCTION__, val[40]); + printf("%s - %0.60f\n", __func__, val[40]); } int grib_f_set_force_real8_array__(int* gid, char* key, double *val, int* size, int len){ diff --git a/src/eccodes_prototypes.h b/src/eccodes_prototypes.h index 5d27ec67f..b0842f3d1 100644 --- a/src/eccodes_prototypes.h +++ b/src/eccodes_prototypes.h @@ -1190,7 +1190,7 @@ grib_accessor* grib_find_attribute(grib_handle* h, const char* name, const char* grib_accessor* grib_find_accessor_fast(grib_handle* h, const char* name); /* grib_scaling.cc*/ -double grib_power(long s, long n); +//double grib_power(long s, long n); long grib_get_binary_scale_fact(double max, double min, long bpval, int* ret); long grib_get_bits_per_value(double max, double min, long binary_scale_factor); long grib_get_decimal_scale_fact(double max, double min, long bpval, long binary_scale); diff --git a/src/functions.cc b/src/functions.cc index ed749c159..3c84d1dc1 100644 --- a/src/functions.cc +++ b/src/functions.cc @@ -8,6 +8,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ +#include "grib_api_internal_cpp.h" #include "grib_api_internal.h" long grib_op_eq(long a, long b) @@ -69,7 +70,7 @@ double grib_op_neg_d(double a) long grib_op_pow(long a, long b) { /* Note: This is actually 'a' to the power 'b' */ - return grib_power(b, a); + return grib_power(b, a); } long grib_op_add(long a, long b) diff --git a/src/grib_accessor_class_apply_operators.cc b/src/grib_accessor_class_apply_operators.cc index 57bfb3bf2..5aa497e65 100644 --- a/src/grib_accessor_class_apply_operators.cc +++ b/src/grib_accessor_class_apply_operators.cc @@ -9,6 +9,7 @@ */ +#include "grib_api_internal_cpp.h" #include "grib_api_internal.h" /* This is used by make_class.pl @@ -423,7 +424,7 @@ static int apply_operators(grib_accessor* a) case 7: if (Y) { extraScale = Y; - referenceValueFactor = grib_power(Y, 10); + referenceValueFactor = grib_power(Y, 10); extraWidth = ((10 * Y) + 2) / 3; } else { diff --git a/src/grib_accessor_class_bufr_data_array.cc b/src/grib_accessor_class_bufr_data_array.cc index 64731fa28..b9826b8f9 100644 --- a/src/grib_accessor_class_bufr_data_array.cc +++ b/src/grib_accessor_class_bufr_data_array.cc @@ -7,7 +7,7 @@ * In applying this licence, ECMWF does not waive the privileges and immunities granted to it by * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ - +#include "grib_api_internal_cpp.h" #include "grib_api_internal.h" /* @@ -803,7 +803,7 @@ static int encode_double_array(grib_context* c, grib_buffer* buff, long* pos, bu modifiedReference = bd->reference; modifiedFactor = bd->factor; - inverseFactor = grib_power(bd->scale, 10); + inverseFactor = grib_power(bd->scale, 10); modifiedWidth = bd->width; err = descriptor_get_min_max(bd, modifiedWidth, modifiedReference, modifiedFactor, &minAllowed, &maxAllowed); @@ -945,10 +945,10 @@ static int encode_double_array(grib_context* c, grib_buffer* buff, long* pos, bu localRange = (max - min) * inverseFactor + 1; localWidth = ceil(log(localRange) / log(2.0)); lval = round(max * inverseFactor) - reference; - allone = grib_power(localWidth, 2) - 1; + allone = grib_power(localWidth, 2) - 1; while (allone <= lval) { localWidth++; - allone = grib_power(localWidth, 2) - 1; + allone = grib_power(localWidth, 2) - 1; } if (localWidth == 1) localWidth++; @@ -3227,7 +3227,7 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st return err; } bd = grib_bufr_descriptor_clone(self->expanded->v[index]); - bd->reference = -grib_power(bd->width, 2); + bd->reference = -grib_power(bd->width, 2); bd->width++; err = codec_element(c, self, iss, buffer, data, &pos, index, bd, elementIndex, dval, sval); diff --git a/src/grib_accessor_class_bufr_elements_table.cc b/src/grib_accessor_class_bufr_elements_table.cc index b804ec269..07b765591 100644 --- a/src/grib_accessor_class_bufr_elements_table.cc +++ b/src/grib_accessor_class_bufr_elements_table.cc @@ -12,6 +12,7 @@ * Enrico Fucile ****************************************/ +#include "grib_api_internal_cpp.h" #include "grib_api_internal.h" #if GRIB_PTHREADS @@ -350,7 +351,7 @@ static int bufr_get_from_table(grib_accessor* a, bufr_descriptor* v) /* ECC-985: Scale and reference are often 0 so we can reduce calls to atol */ v->scale = atol_fast(list[5]); - v->factor = grib_power(-v->scale, 10); + v->factor = grib_power(-v->scale, 10); v->reference = atol_fast(list[6]); v->width = atol(list[7]); diff --git a/src/grib_accessor_class_data_2order_packing.cc b/src/grib_accessor_class_data_2order_packing.cc index f57505682..f2edfe246 100644 --- a/src/grib_accessor_class_data_2order_packing.cc +++ b/src/grib_accessor_class_data_2order_packing.cc @@ -8,6 +8,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ +#include "grib_api_internal_cpp.h" #include "grib_api_internal.h" /* @@ -621,8 +622,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) if (boustrophedonic) reverse_rows(sec_val, n_vals, Ni, bitmap, bitmap_len); - s = grib_power(binary_scale_factor, 2); - d = grib_power(-decimal_scale_factor, 10); + s = grib_power(binary_scale_factor, 2); + d = grib_power(-decimal_scale_factor, 10); for (i = 0; i < n_vals; i++) val[i] = (double)((((double)sec_val[i]) * s) + reference_value) * d; @@ -763,7 +764,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) /* calculation of integer array */ sec_val = (unsigned long*)grib_context_malloc(a->context, (n_vals) * sizeof(long)); - d = grib_power(decimal_scale_factor, 10); + d = grib_power(decimal_scale_factor, 10); max = val[0]; min = max; for (i = 0; i < n_vals; i++) { @@ -785,7 +786,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) /* the scale factor in Grib 1 is adjusted in gribex, for "normalization purpose" ... ?*/ binary_scale_factor = grib_get_binary_scale_fact(max, reference_value, bits_per_value, &err); - divisor = grib_power(-binary_scale_factor, 2); + divisor = grib_power(-binary_scale_factor, 2); for (i = 0; i < n_vals; i++) diff --git a/src/grib_accessor_class_data_ccsds_packing.cc b/src/grib_accessor_class_data_ccsds_packing.cc index 07f42539a..bda1a7004 100644 --- a/src/grib_accessor_class_data_ccsds_packing.cc +++ b/src/grib_accessor_class_data_ccsds_packing.cc @@ -297,7 +297,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) return err; if (bits_per_value == 0 || (binary_scale_factor == 0 && decimal_scale_factor != 0)) { - d = grib_power(decimal_scale_factor, 10); + d = grib_power(decimal_scale_factor, 10); min *= d; max *= d; @@ -326,9 +326,9 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) range = (max - min); unscaled_min = min; unscaled_max = max; - f = (grib_power(bits_per_value, 2) - 1); - minrange = grib_power(-last, 2) * f; - maxrange = grib_power(last, 2) * f; + f = (grib_power(bits_per_value, 2) - 1); + minrange = grib_power(-last, 2) * f; + maxrange = grib_power(last, 2) * f; while (range < minrange) { decimal_scale_factor += 1; @@ -349,11 +349,11 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) "data_ccsds_packing %s: unable to find nearest_smaller_value of %g for %s", __func__, min, self->reference_value); return GRIB_INTERNAL_ERROR; } - d = grib_power(decimal_scale_factor, 10); + d = grib_power(decimal_scale_factor, 10); } binary_scale_factor = grib_get_binary_scale_fact(max, reference_value, bits_per_value, &err); - divisor = grib_power(-binary_scale_factor, 2); + divisor = grib_power(-binary_scale_factor, 2); bits8 = (bits_per_value + 7) / 8 * 8; encoded = (unsigned char*)grib_context_buffer_malloc_clear(a->context, bits8 / 8 * n_vals); @@ -513,8 +513,8 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return GRIB_SUCCESS; } - bscale = grib_power(binary_scale_factor, 2); - dscale = grib_power(-decimal_scale_factor, 10); + bscale = grib_power(binary_scale_factor, 2); + dscale = grib_power(-decimal_scale_factor, 10); buflen = grib_byte_count(a); buf = (unsigned char*)hand->buffer->data; diff --git a/src/grib_accessor_class_data_complex_packing.cc b/src/grib_accessor_class_data_complex_packing.cc index dd6eec70b..7bae18ff9 100644 --- a/src/grib_accessor_class_data_complex_packing.cc +++ b/src/grib_accessor_class_data_complex_packing.cc @@ -8,6 +8,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ +#include "grib_api_cpp.h" #include "grib_api_internal_cpp.h" #include /* @@ -446,7 +447,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) if (pen_j == sub_j) { double* values; - d = grib_power(decimal_scale_factor, 10); + d = grib_power(decimal_scale_factor, 10); if (d) { values = (double*)grib_context_malloc_clear(a->context, sizeof(double) * n_vals); for (i = 0; i < n_vals; i++) @@ -546,10 +547,10 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) "unable to find nearest_smaller_value of %g for %s", min, self->reference_value); return GRIB_INTERNAL_ERROR; } - d = grib_power(+decimal_scale_factor, 10); + d = grib_power(+decimal_scale_factor, 10); } else { - d = grib_power(+decimal_scale_factor, 10); + d = grib_power(+decimal_scale_factor, 10); if (grib_get_nearest_smaller_value(gh, self->reference_value, d * min, &reference_value) != GRIB_SUCCESS) { grib_context_log(gh->context, GRIB_LOG_ERROR, "unable to find nearest_smaller_value of %g for %s", d * min, self->reference_value); @@ -569,7 +570,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) } } } - s = grib_power(-binary_scale_factor, 2); + s = grib_power(-binary_scale_factor, 2); i = 0; @@ -693,9 +694,9 @@ static int unpack(grib_accessor* a, T* val, size_t* len) T* scals = NULL; T* pscals = NULL, *pval = NULL; - double s = 0; - double d = 0; - double laplacianOperator = 0; + T s = 0; + T d = 0; + T laplacianOperator = 0; unsigned char* buf = NULL; unsigned char* hres = NULL; unsigned char* lres = NULL; @@ -708,7 +709,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) long offsetdata = 0; long bits_per_value = 0; - double reference_value = 0; + T reference_value = 0; long binary_scale_factor = 0; long decimal_scale_factor = 0; @@ -722,6 +723,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) T operat = 0; int bytes; int err = 0; + double tmp; decode_float_proc decode_float = NULL; @@ -738,8 +740,9 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return ret; if ((ret = grib_get_long_internal(gh, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_double_internal(gh, self->reference_value, &reference_value)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(gh, self->reference_value, &tmp)) != GRIB_SUCCESS) return ret; + reference_value = tmp; if ((ret = grib_get_long_internal(gh, self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS) return ret; @@ -753,8 +756,9 @@ static int unpack(grib_accessor* a, T* val, size_t* len) if ((ret = grib_get_long(gh, self->ieee_floats, &ieee_floats)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_double_internal(gh, self->laplacianOperator, &laplacianOperator)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(gh, self->laplacianOperator, &tmp)) != GRIB_SUCCESS) return ret; + laplacianOperator = tmp; if ((ret = grib_get_long_internal(gh, self->sub_j, &sub_j)) != GRIB_SUCCESS) return ret; @@ -803,7 +807,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) if (pen_j == sub_j) { n_vals = (pen_j + 1) * (pen_j + 2); - d = grib_power(-decimal_scale_factor, 10); + d = grib_power(-decimal_scale_factor, 10); grib_ieee_decode_array(a->context, buf, n_vals, bytes, val); if (d) { @@ -818,8 +822,8 @@ static int unpack(grib_accessor* a, T* val, size_t* len) lpos = 8 * (packed_offset - offsetdata); - s = grib_power(binary_scale_factor, 2); - d = grib_power(-decimal_scale_factor, 10); + s = grib_power(binary_scale_factor, 2); + d = grib_power(-decimal_scale_factor, 10); scals = (T*)grib_context_malloc(a->context, maxv * sizeof(T)); Assert(scals); diff --git a/src/grib_accessor_class_data_g1second_order_constant_width_packing.cc b/src/grib_accessor_class_data_g1second_order_constant_width_packing.cc index 357491283..bba4cd2fa 100644 --- a/src/grib_accessor_class_data_g1second_order_constant_width_packing.cc +++ b/src/grib_accessor_class_data_g1second_order_constant_width_packing.cc @@ -8,6 +8,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ +#include "grib_api_internal_cpp.h" #include "grib_api_internal.h" /* @@ -298,8 +299,8 @@ static int unpack_double(grib_accessor* a, double* values, size_t* len) printf("XXXXXXX extrabits=%ld pos=%ld\n",extrabits,pos); }*/ - s = grib_power(binary_scale_factor, 2); - d = grib_power(-decimal_scale_factor, 10); + s = grib_power(binary_scale_factor, 2); + d = grib_power(-decimal_scale_factor, 10); for (i = 0; i < numberOfSecondOrderPackedValues; i++) { values[i] = (double)(((X[i] * s) + reference_value) * d); } diff --git a/src/grib_accessor_class_data_g1second_order_general_extended_packing.cc b/src/grib_accessor_class_data_g1second_order_general_extended_packing.cc index 41567804a..b3eec7ba1 100644 --- a/src/grib_accessor_class_data_g1second_order_general_extended_packing.cc +++ b/src/grib_accessor_class_data_g1second_order_general_extended_packing.cc @@ -8,6 +8,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ +#include "grib_api_internal_cpp.h" #include "grib_api_internal.h" #include "grib_optimize_decimal_factor.h" @@ -516,8 +517,8 @@ static int unpack_double(grib_accessor* a, double* values, size_t* len) self->values = (double*)grib_context_malloc_clear(a->context, sizeof(double) * numberOfValues); } - s = grib_power(binary_scale_factor, 2); - d = grib_power(-decimal_scale_factor, 10); + s = grib_power(binary_scale_factor, 2); + d = grib_power(-decimal_scale_factor, 10); for (i = 0; i < numberOfValues; i++) { values[i] = (double)(((X[i] * s) + reference_value) * d); self->values[i] = values[i]; @@ -710,7 +711,7 @@ static int pack_double_old(grib_accessor* a, const double* val, size_t *len) if((ret = grib_get_long_internal(handle,self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) return ret; - decimal = grib_power(decimal_scale_factor,10); + decimal = grib_power(decimal_scale_factor,10); max*=decimal; min*=decimal; @@ -744,7 +745,7 @@ static int pack_double_old(grib_accessor* a, const double* val, size_t *len) GRIB_SUCCESS) return ret; - divisor = grib_power(-binary_scale_factor,2); + divisor = grib_power(-binary_scale_factor,2); X=(long*)grib_context_malloc_clear(a->context,sizeof(long)*numberOfValues); for(i=0;i< numberOfValues;i++){ X[i] = (((val[i]*decimal)-reference_value)*divisor)+0.5; @@ -815,7 +816,7 @@ static int pack_double_old(grib_accessor* a, const double* val, size_t *len) } } groupWidthA=number_of_bits(handle, maxA-minA); - range=(long)grib_power(groupWidthA,2)-1; + range=(long)grib_power(groupWidthA,2)-1; offsetC=count+groupLengthA; if (offsetC==numberOfValues) { @@ -903,7 +904,7 @@ static int pack_double_old(grib_accessor* a, const double* val, size_t *len) if (minA>X[count+i]) minA=X[count+i]; } groupWidthA=number_of_bits(maxA-minA); - range=(long)grib_power(groupWidthA,2)-1; + range=(long)grib_power(groupWidthA,2)-1; groupLengths[numberOfGroups]=groupLengthA; groupWidths[numberOfGroups]=groupWidthA; firstOrderValues[numberOfGroups] = maxA-range > 0 ? maxA-range : 0; @@ -967,7 +968,7 @@ static int pack_double_old(grib_accessor* a, const double* val, size_t *len) if (minA>X[count+i]) minA=X[count+i]; } groupWidthA=number_of_bits(maxA-minA); - range=(long)grib_power(groupWidthA,2)-1; + range=(long)grib_power(groupWidthA,2)-1; groupLengths[numberOfGroups]=groupLengthA; groupWidths[numberOfGroups]=groupWidthA; firstOrderValues[numberOfGroups] = maxA-range > 0 ? maxA-range : 0; @@ -1009,7 +1010,7 @@ static int pack_double_old(grib_accessor* a, const double* val, size_t *len) if (min>firstOrderValues[i]) min=firstOrderValues[i]; } widthOfFirstOrderValues=number_of_bits(handle, max-min); - firstOrderValuesMax=(long)grib_power(widthOfFirstOrderValues,2)-1; + firstOrderValuesMax=(long)grib_power(widthOfFirstOrderValues,2)-1; if (numberOfGroups>2) { /* loop through all the groups except the last in reverse order to @@ -1033,7 +1034,7 @@ static int pack_double_old(grib_accessor* a, const double* val, size_t *len) if (min>X[offset+j]) min=X[offset+j]; } groupWidth=number_of_bits(handle, max-min); - range=(long)grib_power(groupWidth,2)-1; + range=(long)grib_power(groupWidth,2)-1; /* width of first order values has to be unchanged.*/ for (j=groupWidth;j(decimal_scale_factor, 10); + divisor = grib_power(-binary_scale_factor, 2); /*min = min * decimal;*/ /*max = max * decimal;*/ @@ -1364,7 +1365,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) if ((ret = grib_get_long_internal(handle, self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) return ret; - decimal = grib_power(decimal_scale_factor, 10); + decimal = grib_power(decimal_scale_factor, 10); min = min * decimal; max = max * decimal; @@ -1375,7 +1376,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) } binary_scale_factor = grib_get_binary_scale_fact(max, reference_value, bits_per_value, &ret); - divisor = grib_power(-binary_scale_factor, 2); + divisor = grib_power(-binary_scale_factor, 2); } if ((ret = grib_set_long_internal(handle, self->binary_scale_factor, binary_scale_factor)) != @@ -1469,7 +1470,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) } } groupWidthA = number_of_bits(handle, maxA - minA); - range = (long)grib_power(groupWidthA, 2) - 1; + range = (long)grib_power(groupWidthA, 2) - 1; offsetC = count + groupLengthA; if (offsetC == numberOfValues) { @@ -1562,7 +1563,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) if (minA>X[count+i]) minA=X[count+i]; } groupWidthA=number_of_bits(maxA-minA); - range=(long)grib_power(groupWidthA,2)-1; + range=(long)grib_power(groupWidthA,2)-1; groupLengths[numberOfGroups]=groupLengthA; groupWidths[numberOfGroups]=groupWidthA; firstOrderValues[numberOfGroups] = maxA-range > 0 ? maxA-range : 0; @@ -1627,7 +1628,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) if (minA>X[count+i]) minA=X[count+i]; } groupWidthA=number_of_bits(maxA-minA); - range=(long)grib_power(groupWidthA,2)-1; + range=(long)grib_power(groupWidthA,2)-1; groupLengths[numberOfGroups]=groupLengthA; groupWidths[numberOfGroups]=groupWidthA; firstOrderValues[numberOfGroups] = maxA-range > 0 ? maxA-range : 0; @@ -1671,7 +1672,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) min = firstOrderValues[i]; } widthOfFirstOrderValues = number_of_bits(handle, max - min); - firstOrderValuesMax = (long)grib_power(widthOfFirstOrderValues, 2) - 1; + firstOrderValuesMax = (long)grib_power(widthOfFirstOrderValues, 2) - 1; if (numberOfGroups > 2) { /* loop through all the groups except the last in reverse order to @@ -1699,7 +1700,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) min = X[offset + j]; } groupWidth = number_of_bits(handle, max - min); - range = (long)grib_power(groupWidth, 2) - 1; + range = (long)grib_power(groupWidth, 2) - 1; /* width of first order values has to be unchanged.*/ for (j = groupWidth; j < groupWidths[i]; j++) { diff --git a/src/grib_accessor_class_data_g1second_order_general_packing.cc b/src/grib_accessor_class_data_g1second_order_general_packing.cc index 856a68930..1c283b972 100644 --- a/src/grib_accessor_class_data_g1second_order_general_packing.cc +++ b/src/grib_accessor_class_data_g1second_order_general_packing.cc @@ -8,6 +8,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ +#include "grib_api_internal_cpp.h" #include "grib_api_internal.h" /* @@ -288,8 +289,8 @@ static int unpack_double(grib_accessor* a, double* values, size_t* len) } } - s = grib_power(binary_scale_factor, 2); - d = grib_power(-decimal_scale_factor, 10); + s = grib_power(binary_scale_factor, 2); + d = grib_power(-decimal_scale_factor, 10); for (i = 0; i < numberOfSecondOrderPackedValues; i++) { values[i] = (double)(((X[i] * s) + reference_value) * d); } diff --git a/src/grib_accessor_class_data_g1second_order_row_by_row_packing.cc b/src/grib_accessor_class_data_g1second_order_row_by_row_packing.cc index 9f51021b7..66a7a6647 100644 --- a/src/grib_accessor_class_data_g1second_order_row_by_row_packing.cc +++ b/src/grib_accessor_class_data_g1second_order_row_by_row_packing.cc @@ -8,6 +8,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ +#include "grib_api_internal_cpp.h" #include "grib_api_internal.h" /* @@ -415,8 +416,8 @@ static int unpack_double(grib_accessor* a, double* values, size_t* len) k++; } - s = grib_power(binary_scale_factor, 2); - d = grib_power(-decimal_scale_factor, 10); + s = grib_power(binary_scale_factor, 2); + d = grib_power(-decimal_scale_factor, 10); for (i = 0; i < n; i++) { values[i] = (double)(((X[i] * s) + reference_value) * d); } diff --git a/src/grib_accessor_class_data_g1simple_packing.cc b/src/grib_accessor_class_data_g1simple_packing.cc index 168c0e869..9526a8b83 100644 --- a/src/grib_accessor_class_data_g1simple_packing.cc +++ b/src/grib_accessor_class_data_g1simple_packing.cc @@ -8,6 +8,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ +#include "grib_api_internal_cpp.h" #include "grib_api_internal.h" /* @@ -290,8 +291,8 @@ static int pack_double(grib_accessor* a, const double* cval, size_t* len) if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetsection, &offsetsection)) != GRIB_SUCCESS) return ret; - decimal = grib_power(decimal_scale_factor, 10); - divisor = grib_power(-binary_scale_factor, 2); + decimal = grib_power(decimal_scale_factor, 10); + divisor = grib_power(-binary_scale_factor, 2); buflen = (((bits_per_value * n_vals) + 7) / 8) * sizeof(unsigned char); if ((buflen + (offsetdata - offsetsection)) % 2) { diff --git a/src/grib_accessor_class_data_g22order_packing.cc b/src/grib_accessor_class_data_g22order_packing.cc index ae030eb9b..f688d759a 100644 --- a/src/grib_accessor_class_data_g22order_packing.cc +++ b/src/grib_accessor_class_data_g22order_packing.cc @@ -9,6 +9,7 @@ */ +#include "grib_api_internal_cpp.h" #include "grib_api_internal.h" #include @@ -751,8 +752,8 @@ static int unpack(grib_accessor* a, T* val, const size_t* len) // de_spatial_difference (a->context, sec_val, n_vals, orderOfSpatialDifferencing, bias); } - binary_s = (T)grib_power(binary_scale_factor, 2); - decimal_s = (T)grib_power(-decimal_scale_factor, 10); + binary_s = (T)grib_power(binary_scale_factor, 2); + decimal_s = (T)grib_power(-decimal_scale_factor, 10); for (i = 0; i < n_vals; i++) { if (sec_val[i] == LONG_MAX) { diff --git a/src/grib_accessor_class_data_g2bifourier_packing.cc b/src/grib_accessor_class_data_g2bifourier_packing.cc index cc4bcfc22..d9c09b95d 100644 --- a/src/grib_accessor_class_data_g2bifourier_packing.cc +++ b/src/grib_accessor_class_data_g2bifourier_packing.cc @@ -12,6 +12,7 @@ * philippe.marguinaud@meteo.fr *******************************/ +#include "grib_api_internal_cpp.h" #include "grib_api_internal.h" #include "grib_optimize_decimal_factor.h" #include @@ -667,8 +668,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) buf = (unsigned char*)gh->buffer->data; buf += grib_byte_offset(a); - s = grib_power(bt->binary_scale_factor, 2); - d = grib_power(-bt->decimal_scale_factor, 10); + s = grib_power(bt->binary_scale_factor, 2); + d = grib_power(-bt->decimal_scale_factor, 10); /* * Decode data @@ -815,8 +816,8 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) if (ret != GRIB_SUCCESS) goto cleanup; - s = grib_power(-bt->binary_scale_factor, 2); - d = grib_power(+bt->decimal_scale_factor, 10); + s = grib_power(-bt->binary_scale_factor, 2); + d = grib_power(+bt->decimal_scale_factor, 10); } else { bt->decimal_scale_factor = 0; diff --git a/src/grib_accessor_class_data_g2simple_packing.cc b/src/grib_accessor_class_data_g2simple_packing.cc index ab96dae61..974c23226 100644 --- a/src/grib_accessor_class_data_g2simple_packing.cc +++ b/src/grib_accessor_class_data_g2simple_packing.cc @@ -8,6 +8,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ +#include "grib_api_internal_cpp.h" #include "grib_api_internal.h" /* @@ -244,8 +245,8 @@ static int pack_double(grib_accessor* a, const double* cval, size_t* len) if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) return ret; - decimal = grib_power(decimal_scale_factor, 10); - divisor = grib_power(-binary_scale_factor, 2); + decimal = grib_power(decimal_scale_factor, 10); + divisor = grib_power(-binary_scale_factor, 2); buflen = (((bits_per_value * n_vals) + 7) / 8) * sizeof(unsigned char); buf = (unsigned char*)grib_context_buffer_malloc_clear(a->context, buflen); diff --git a/src/grib_accessor_class_data_jpeg2000_packing.cc b/src/grib_accessor_class_data_jpeg2000_packing.cc index fa62b303e..78441f478 100644 --- a/src/grib_accessor_class_data_jpeg2000_packing.cc +++ b/src/grib_accessor_class_data_jpeg2000_packing.cc @@ -8,6 +8,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ +#include "grib_api_internal_cpp.h" #include "grib_api_internal.h" /* @@ -271,8 +272,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) self->dirty = 0; - bscale = grib_power(binary_scale_factor, 2); - dscale = grib_power(-decimal_scale_factor, 10); + bscale = grib_power(binary_scale_factor, 2); + dscale = grib_power(-decimal_scale_factor, 10); /* TODO: This should be called upstream */ if (*len < n_vals) @@ -411,8 +412,8 @@ static int pack_double(grib_accessor* a, const double* cval, size_t* len) if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) return ret; - decimal = grib_power(decimal_scale_factor, 10); - divisor = grib_power(-binary_scale_factor, 2); + decimal = grib_power(decimal_scale_factor, 10); + divisor = grib_power(-binary_scale_factor, 2); simple_packing_size = (((bits_per_value * n_vals) + 7) / 8) * sizeof(unsigned char); buf = (unsigned char*)grib_context_malloc_clear(a->context, simple_packing_size + EXTRA_BUFFER_SIZE); diff --git a/src/grib_accessor_class_data_png_packing.cc b/src/grib_accessor_class_data_png_packing.cc index e923d2721..5c8edf76a 100644 --- a/src/grib_accessor_class_data_png_packing.cc +++ b/src/grib_accessor_class_data_png_packing.cc @@ -8,6 +8,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ +#include "grib_api_internal_cpp.h" #include "grib_api_internal.h" #define PNG_ANYBITS @@ -248,8 +249,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) return err; - bscale = grib_power(binary_scale_factor, 2); - dscale = grib_power(-decimal_scale_factor, 10); + bscale = grib_power(binary_scale_factor, 2); + dscale = grib_power(-decimal_scale_factor, 10); /* TODO: This should be called upstream */ if (*len < n_vals) @@ -498,7 +499,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) return GRIB_SUCCESS; } - d = grib_power(decimal_scale_factor, 10); + d = grib_power(decimal_scale_factor, 10); max = val[0]; min = max; @@ -521,7 +522,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) } binary_scale_factor = grib_get_binary_scale_fact(max, reference_value, bits_per_value, &err); - divisor = grib_power(-binary_scale_factor, 2); + divisor = grib_power(-binary_scale_factor, 2); #ifndef PNG_ANYBITS Assert(bits_per_value % 8 == 0); diff --git a/src/grib_accessor_class_data_run_length_packing.cc b/src/grib_accessor_class_data_run_length_packing.cc index 08ec9227f..893cf3a20 100644 --- a/src/grib_accessor_class_data_run_length_packing.cc +++ b/src/grib_accessor_class_data_run_length_packing.cc @@ -8,6 +8,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ +#include "grib_api_internal_cpp.h" #include "grib_api_internal.h" /* @@ -202,7 +203,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) if (decimal_scale_factor > 127) { decimal_scale_factor = -(decimal_scale_factor - 128); } - level_scale_factor = grib_power(-decimal_scale_factor, 10.0); + level_scale_factor = grib_power(-decimal_scale_factor, 10.0); levels = (double*)grib_context_malloc_clear(a->context, sizeof(double) * (number_of_level_values + 1)); levels[0] = missingValue; for (i = 0; i < number_of_level_values; i++) { diff --git a/src/grib_accessor_class_data_sh_packed.cc b/src/grib_accessor_class_data_sh_packed.cc index 986cff981..2741d6b41 100644 --- a/src/grib_accessor_class_data_sh_packed.cc +++ b/src/grib_accessor_class_data_sh_packed.cc @@ -8,6 +8,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ +#include "grib_api_internal_cpp.h" #include "grib_api_internal.h" #include /* @@ -328,8 +329,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) lpos = 8 * (packed_offset - offsetdata); - s = grib_power(binary_scale_factor, 2); - d = grib_power(-decimal_scale_factor, 10); + s = grib_power(binary_scale_factor, 2); + d = grib_power(-decimal_scale_factor, 10); scals = (double*)grib_context_malloc(a->context, maxv * sizeof(double)); Assert(scals); diff --git a/src/grib_accessor_class_data_sh_unpacked.cc b/src/grib_accessor_class_data_sh_unpacked.cc index a72e57ada..8894e8bc2 100644 --- a/src/grib_accessor_class_data_sh_unpacked.cc +++ b/src/grib_accessor_class_data_sh_unpacked.cc @@ -8,6 +8,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ +#include "grib_api_internal_cpp.h" #include "grib_api_internal.h" #include /* @@ -307,8 +308,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) lpos = 8 * (packed_offset - offsetdata); - s = grib_power(binary_scale_factor, 2); - d = grib_power(-decimal_scale_factor, 10); + s = grib_power(binary_scale_factor, 2); + d = grib_power(-decimal_scale_factor, 10); scals = (double*)grib_context_malloc(a->context, maxv * sizeof(double)); Assert(scals); diff --git a/src/grib_accessor_class_data_simple_packing.cc b/src/grib_accessor_class_data_simple_packing.cc index c1cf199a8..a4977b910 100644 --- a/src/grib_accessor_class_data_simple_packing.cc +++ b/src/grib_accessor_class_data_simple_packing.cc @@ -238,8 +238,8 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val) } Assert(idx < n_vals); - s = grib_power(binary_scale_factor, 2); - d = grib_power(-decimal_scale_factor, 10); + s = grib_power(binary_scale_factor, 2); + d = grib_power(-decimal_scale_factor, 10); grib_context_log(a->context, GRIB_LOG_DEBUG, "grib_accessor_data_simple_packing: unpack_double_element: creating %s, %d values (idx=%ld)", @@ -373,8 +373,8 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return GRIB_SUCCESS; } - s = grib_power(binary_scale_factor, 2); - d = grib_power(-decimal_scale_factor, 10); + s = grib_power(binary_scale_factor, 2); + d = grib_power(-decimal_scale_factor, 10); grib_context_log(a->context, GRIB_LOG_DEBUG, "grib_accessor_data_simple_packing: unpack_double : creating %s, %d values", @@ -510,8 +510,8 @@ static int _unpack_double(grib_accessor* a, double* val, size_t* len, unsigned c return GRIB_SUCCESS; } - s = grib_power(binary_scale_factor, 2); - d = grib_power(-decimal_scale_factor, 10); + s = grib_power(binary_scale_factor, 2); + d = grib_power(-decimal_scale_factor, 10); grib_context_log(a->context, GRIB_LOG_DEBUG, "grib_accessor_data_simple_packing: unpack_double : creating %s, %d values", @@ -747,7 +747,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) /* decimal_scale_factor is given, binary_scale_factor=0 and bits_per_value is computed */ binary_scale_factor = 0; decimal_scale_factor = decimal_scale_factor_get; - decimal = grib_power(decimal_scale_factor, 10); + decimal = grib_power(decimal_scale_factor, 10); min *= decimal; max *= decimal; @@ -793,14 +793,14 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) return err; } else { - /* printf("max=%g reference_value=%g grib_power(-last,2)=%g decimal_scale_factor=%ld bits_per_value=%ld\n", - max,reference_value,grib_power(-last,2),decimal_scale_factor,bits_per_value);*/ + /* printf("max=%g reference_value=%g grib_power(-last,2)=%g decimal_scale_factor=%ld bits_per_value=%ld\n", + max,reference_value,grib_power(-last,2),decimal_scale_factor,bits_per_value);*/ range = (max - min); unscaled_min = min; unscaled_max = max; - f = (grib_power(bits_per_value, 2) - 1); - minrange = grib_power(-last, 2) * f; - maxrange = grib_power(last, 2) * f; + f = (grib_power(bits_per_value, 2) - 1); + minrange = grib_power(-last, 2) * f; + maxrange = grib_power(last, 2) * f; while (range < minrange) { decimal_scale_factor += 1; diff --git a/src/grib_accessor_class_expanded_descriptors.cc b/src/grib_accessor_class_expanded_descriptors.cc index 5580dadcf..ee6bd8fbb 100644 --- a/src/grib_accessor_class_expanded_descriptors.cc +++ b/src/grib_accessor_class_expanded_descriptors.cc @@ -15,6 +15,7 @@ can appear */ +#include "grib_api_internal_cpp.h" #include "grib_api_internal.h" /* This is used by make_class.pl @@ -483,7 +484,7 @@ static void __expand(grib_accessor* a, bufr_descriptors_array* unexpanded, bufr_ case 7: if (us->Y) { ccp->extraScale = us->Y; - ccp->referenceFactor = grib_power(us->Y, 10); + ccp->referenceFactor = grib_power(us->Y, 10); ccp->extraWidth = ((10 * us->Y) + 2) / 3; } else { diff --git a/src/grib_accessor_class_second_order_bits_per_value.cc b/src/grib_accessor_class_second_order_bits_per_value.cc index c8fb9f3a3..ae807f7cb 100644 --- a/src/grib_accessor_class_second_order_bits_per_value.cc +++ b/src/grib_accessor_class_second_order_bits_per_value.cc @@ -12,6 +12,7 @@ * Enrico Fucile **********************************/ +#include "grib_api_internal_cpp.h" #include "grib_api_internal.h" /* This is used by make_class.pl @@ -225,8 +226,8 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) min = values[i]; } - d = grib_power(decimalScaleFactor, 10); - b = grib_power(-binaryScaleFactor, 2); + d = grib_power(decimalScaleFactor, 10); + b = grib_power(-binaryScaleFactor, 2); /* self->bitsPerValue=(long)ceil(log((double)((max-min)*d+1))/log(2.0))-binaryScaleFactor; */ /* See GRIB-540 for why we use ceil */ diff --git a/src/grib_accessor_class_simple_packing_error.cc b/src/grib_accessor_class_simple_packing_error.cc index 6ad7a31c3..591c35563 100644 --- a/src/grib_accessor_class_simple_packing_error.cc +++ b/src/grib_accessor_class_simple_packing_error.cc @@ -13,6 +13,7 @@ **************************************/ +#include "grib_api_internal_cpp.h" #include "grib_api_internal.h" /* This is used by make_class.pl @@ -166,7 +167,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) Assert(1 == 0); if (bitsPerValue != 0) - *val = (*val + grib_power(binaryScaleFactor, 2)) * grib_power(-decimalScaleFactor, 10) * 0.5; + *val = (*val + grib_power(binaryScaleFactor, 2)) * grib_power(-decimalScaleFactor, 10) * 0.5; if (ret == GRIB_SUCCESS) *len = 1; diff --git a/src/grib_api_cpp.h b/src/grib_api_cpp.h new file mode 100644 index 000000000..aac0a52f1 --- /dev/null +++ b/src/grib_api_cpp.h @@ -0,0 +1,13 @@ +/* + * (C) Copyright 2005- ECMWF. + * + * This software is licensed under the terms of the Apache Licence Version 2.0 + * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. + * + * In applying this licence, ECMWF does not waive the privileges and immunities granted to it by + * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. + */ + +#pragma once + +//template T grib_power(long s, long n); diff --git a/src/grib_api_internal.h b/src/grib_api_internal.h index 88d8a50f9..c94bd9994 100644 --- a/src/grib_api_internal.h +++ b/src/grib_api_internal.h @@ -1614,8 +1614,6 @@ typedef struct j2k_encode_helper #endif - - /* This part is automatically generated by ./errors.pl, do not edit */ #ifndef grib_errors_internal_H #define grib_errors_internal_H diff --git a/src/grib_api_internal_cpp.h b/src/grib_api_internal_cpp.h index 4724b050c..2c23dcab5 100644 --- a/src/grib_api_internal_cpp.h +++ b/src/grib_api_internal_cpp.h @@ -14,3 +14,4 @@ #include "grib_value.h" #include "grib_bits_any_endian_simple.h" #include "grib_ieeefloat.h" +#include "grib_scaling.h" diff --git a/src/grib_bits_any_endian.cc b/src/grib_bits_any_endian.cc index 2c803f089..5fd706d9f 100644 --- a/src/grib_bits_any_endian.cc +++ b/src/grib_bits_any_endian.cc @@ -392,7 +392,7 @@ int grib_encode_unsigned_longb(unsigned char* p, unsigned long val, long* bitp, } #ifdef DEBUG { - unsigned long maxV = grib_power(nb, 2); + unsigned long maxV = grib_power(nb, 2); if (val > maxV) { fprintf(stderr, "grib_encode_unsigned_longb: Value=%lu, but number of bits=%ld!\n", val, nb); Assert(0); @@ -421,7 +421,7 @@ int grib_encode_size_tb(unsigned char* p, size_t val, long* bitp, long nb) } #ifdef DEBUG { - size_t maxV = grib_power(nb, 2); + size_t maxV = grib_power(nb, 2); if (val > maxV) { fprintf(stderr, "grib_encode_size_tb: Value=%lu, but number of bits=%ld!\n", val, nb); Assert(0); diff --git a/src/grib_bufr_descriptor.cc b/src/grib_bufr_descriptor.cc index 6d1ab0076..99a406783 100644 --- a/src/grib_bufr_descriptor.cc +++ b/src/grib_bufr_descriptor.cc @@ -9,6 +9,7 @@ */ +#include "grib_api_internal_cpp.h" #include "grib_api_internal.h" bufr_descriptor* grib_bufr_descriptor_new(grib_accessor* tables_accessor, int code, int silent, int* err) @@ -109,7 +110,7 @@ void grib_bufr_descriptor_set_scale(bufr_descriptor* v, long scale) v->scale = scale; if (scale != 0) v->type = BUFR_DESCRIPTOR_TYPE_DOUBLE; - v->factor = grib_power(-scale, 10); + v->factor = grib_power(-scale, 10); } int grib_bufr_descriptor_can_be_missing(bufr_descriptor* v) diff --git a/src/grib_header_compute.cc b/src/grib_header_compute.cc index da68f004e..a3987a51c 100644 --- a/src/grib_header_compute.cc +++ b/src/grib_header_compute.cc @@ -71,7 +71,7 @@ static long op_neg(long a) {return -a;} static double op_neg_d(double a) {return -a;} -static long op_pow(long a, long b) {return grib_power(a,b);} +static long op_pow(long a, long b) {return grib_power(a,b);} static long op_add(long a, long b) {return a+b;} static long op_sub(long a, long b) {return a-b;} static long op_div(long a, long b) {return a/b;} diff --git a/src/grib_optimize_decimal_factor.cc b/src/grib_optimize_decimal_factor.cc index f3b5eeaf5..bb4a64ce1 100644 --- a/src/grib_optimize_decimal_factor.cc +++ b/src/grib_optimize_decimal_factor.cc @@ -8,6 +8,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ +#include "grib_api_internal_cpp.h" #include "grib_api_internal.h" #include "grib_optimize_decimal_factor.h" #include @@ -50,9 +51,9 @@ static void factec(int* krep, const double pa, const int knbit, const long kdec, } /* Binary scale factor associated to kdec */ - *ke = floor(log2((pa * grib_power(kdec, 10)) / (grib_power(knbit, 2) - 0.5))) + 1; + *ke = floor(log2((pa * grib_power(kdec, 10)) / (grib_power(knbit, 2) - 0.5))) + 1; /* Encoded value for pa = max - min */ - *knutil = floor(0.5 + pa * grib_power(kdec, 10) * grib_power(-*ke, 2)); + *knutil = floor(0.5 + pa * grib_power(kdec, 10) * grib_power(-*ke, 2)); end: return; @@ -98,14 +99,14 @@ int grib_optimize_decimal_factor(grib_accessor* a, const char* reference_value, xtinyr4 = FLT_MIN; xhuger4 = FLT_MAX; - inbint = grib_power(knbit, 2) - 1; + inbint = grib_power(knbit, 2) - 1; xnbint = (double)inbint; /* Test decimal scale factors; keep the most suitable */ for (jdec = idecmin; jdec <= idecmax; jdec++) { /* Fix a problem in GRIBEX */ if (compat_gribex) - if (pa * grib_power(jdec, 10) <= 1.E-12) + if (pa * grib_power(jdec, 10) <= 1.E-12) continue; /* Check it will be possible to decode reference value with 32bit floats */ @@ -125,7 +126,7 @@ int grib_optimize_decimal_factor(grib_accessor* a, const char* reference_value, /* Check it will be possible to decode the maximum value of the fields using 32bit floats */ if (compat_32bit) - if (pmin * grib_power(jdec, 10) + xnbint * grib_power(ie, 2) >= xhuger4) + if (pmin * grib_power(jdec, 10) + xnbint * grib_power(ie, 2) >= xhuger4) continue; /* GRIB1 demands that the binary scale factor be encoded in a single byte */ @@ -141,8 +142,8 @@ int grib_optimize_decimal_factor(grib_accessor* a, const char* reference_value, } if (inumax > 0) { - double decimal = grib_power(+*kdec, 10); - double divisor = grib_power(-*kbin, 2); + double decimal = grib_power(+*kdec, 10); + double divisor = grib_power(-*kbin, 2); double min = pmin * decimal; long vmin, vmax; if (grib_get_nearest_smaller_value(gh, reference_value, min, ref) != GRIB_SUCCESS) { @@ -164,9 +165,9 @@ int grib_optimize_decimal_factor(grib_accessor* a, const char* reference_value, int last = compat_gribex ? 99 : 127; double min = pmin, max = pmax; double range = max - min; - double f = grib_power(knbit, 2) - 1; - double minrange = grib_power(-last, 2) * f; - double maxrange = grib_power(+last, 2) * f; + double f = grib_power(knbit, 2) - 1; + double minrange = grib_power(-last, 2) * f; + double maxrange = grib_power(+last, 2) * f; double decimal = 1; int err; diff --git a/src/grib_scaling.cc b/src/grib_scaling.cc index d7654889f..2f2d98863 100644 --- a/src/grib_scaling.cc +++ b/src/grib_scaling.cc @@ -12,27 +12,9 @@ * Enrico Fucile **************************************/ +#include "grib_api_internal_cpp.h" #include "grib_api_internal.h" -/* Return n to the power of s */ -double grib_power(long s, long n) -{ - double divisor = 1.0; - if (s == 0) - return 1.0; - if (s == 1) - return n; - while (s < 0) { - divisor /= n; - s++; - } - while (s > 0) { - divisor *= n; - s--; - } - return divisor; -} - long grib_get_binary_scale_fact(double max, double min, long bpval, int* ret) { double range = max - min; @@ -43,14 +25,14 @@ long grib_get_binary_scale_fact(double max, double min, long bpval, int* ret) const size_t ulong_size = sizeof(maxint) * 8; /* See ECC-246 - unsigned long maxint = grib_power(bpval,2) - 1; + unsigned long maxint = grib_power(bpval,2) - 1; double dmaxint=(double)maxint; */ if (bpval >= ulong_size) { *ret = GRIB_OUT_OF_RANGE; /*overflow*/ return 0; } - const double dmaxint = grib_power(bpval, 2) - 1; + const double dmaxint = grib_power(bpval, 2) - 1; maxint = (unsigned long)dmaxint; /* Now it's safe to cast */ *ret = 0; @@ -101,7 +83,7 @@ long grib_get_bits_per_value(double max, double min, long binary_scale_factor) long scale = 0; const long last = 127; /* Depends on edition, should be parameter */ - unsigned long maxint = grib_power(binary_scale_factor, 2) - 1; + unsigned long maxint = grib_power(binary_scale_factor, 2) - 1; double dmaxint = (double)maxint; if (maxint == 0) @@ -145,10 +127,10 @@ long grib_get_decimal_scale_fact(double max, double min, long bpval, long binary long scale = 0; const long last = 127; /* Depends on edition, should be parameter */ - unsigned long maxint = grib_power(bpval, 2) - 1; + unsigned long maxint = grib_power(bpval, 2) - 1; double dmaxint = (double)maxint; - range *= grib_power(-binary_scale, 2); + range *= grib_power(-binary_scale, 2); Assert(bpval >= 1); if (range == 0) diff --git a/src/grib_scaling.h b/src/grib_scaling.h new file mode 100644 index 000000000..4dbd8f6f1 --- /dev/null +++ b/src/grib_scaling.h @@ -0,0 +1,23 @@ +#pragma once + +template T grib_power(long s, long n); + +/* Return n to the power of s */ +template +T grib_power(long s, long n) +{ + T divisor = 1.0; + if (s == 0) + return 1.0; + if (s == 1) + return n; + while (s < 0) { + divisor /= n; + s++; + } + while (s > 0) { + divisor *= n; + s--; + } + return divisor; +} From 4ca1a08fcc9fe75a98c4ae16c9f4fc30a7f9f941 Mon Sep 17 00:00:00 2001 From: Eugen Betke Date: Tue, 13 Jun 2023 12:25:25 +0000 Subject: [PATCH 03/12] Ignore *.analyzerinfo *.snalyzerinfo files --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index a20dc2122..bfdfd9434 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,8 @@ configure grib_api.spec grib_api.pc grib_api_f90.pc +*.analyzerinfo +*.snalyzerinfo # compiled source # ################### From a12e9114a8ce6c7990217ea10db13635cdf7008d Mon Sep 17 00:00:00 2001 From: Eugen Betke Date: Tue, 13 Jun 2023 13:57:49 +0000 Subject: [PATCH 04/12] ECC-1467: Make grib_power() a template function --- src/grib_api_cpp.h | 13 ------------- src/grib_api_internal_cpp.h | 17 ----------------- 2 files changed, 30 deletions(-) delete mode 100644 src/grib_api_cpp.h delete mode 100644 src/grib_api_internal_cpp.h diff --git a/src/grib_api_cpp.h b/src/grib_api_cpp.h deleted file mode 100644 index aac0a52f1..000000000 --- a/src/grib_api_cpp.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - * (C) Copyright 2005- ECMWF. - * - * This software is licensed under the terms of the Apache Licence Version 2.0 - * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. - * - * In applying this licence, ECMWF does not waive the privileges and immunities granted to it by - * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. - */ - -#pragma once - -//template T grib_power(long s, long n); diff --git a/src/grib_api_internal_cpp.h b/src/grib_api_internal_cpp.h deleted file mode 100644 index 2c23dcab5..000000000 --- a/src/grib_api_internal_cpp.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * (C) Copyright 2005- ECMWF. - * - * This software is licensed under the terms of the Apache Licence Version 2.0 - * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. - * - * In applying this licence, ECMWF does not waive the privileges and immunities granted to it by - * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. - */ - -#pragma once - -#include "grib_accessor.h" -#include "grib_value.h" -#include "grib_bits_any_endian_simple.h" -#include "grib_ieeefloat.h" -#include "grib_scaling.h" From e8e4beb5c72cc94d6ec4afb6664da8a32b0df99e Mon Sep 17 00:00:00 2001 From: Eugen Betke Date: Tue, 13 Jun 2023 14:09:52 +0000 Subject: [PATCH 05/12] ECC-1467: Make grib_power() a template function --- src/functions.cc | 2 +- src/grib_accessor_class_apply_operators.cc | 3 +-- src/grib_accessor_class_bufr_data_array.cc | 2 +- src/grib_accessor_class_bufr_elements_table.cc | 2 +- src/grib_accessor_class_data_2order_packing.cc | 2 +- src/grib_accessor_class_data_apply_bitmap.cc | 2 +- src/grib_accessor_class_data_ccsds_packing.cc | 3 ++- src/grib_accessor_class_data_complex_packing.cc | 4 ++-- ...cessor_class_data_g1second_order_constant_width_packing.cc | 2 +- ...ssor_class_data_g1second_order_general_extended_packing.cc | 2 +- ...grib_accessor_class_data_g1second_order_general_packing.cc | 2 +- ...b_accessor_class_data_g1second_order_row_by_row_packing.cc | 2 +- src/grib_accessor_class_data_g1simple_packing.cc | 2 +- src/grib_accessor_class_data_g22order_packing.cc | 2 +- src/grib_accessor_class_data_g2bifourier_packing.cc | 2 +- src/grib_accessor_class_data_g2simple_packing.cc | 2 +- src/grib_accessor_class_data_jpeg2000_packing.cc | 2 +- src/grib_accessor_class_data_png_packing.cc | 2 +- src/grib_accessor_class_data_raw_packing.cc | 2 +- src/grib_accessor_class_data_run_length_packing.cc | 2 +- src/grib_accessor_class_data_sh_packed.cc | 2 +- src/grib_accessor_class_data_sh_unpacked.cc | 2 +- src/grib_accessor_class_data_simple_packing.cc | 3 ++- src/grib_accessor_class_expanded_descriptors.cc | 2 +- src/grib_accessor_class_gen.cc | 2 +- src/grib_accessor_class_second_order_bits_per_value.cc | 2 +- src/grib_accessor_class_simple_packing_error.cc | 2 +- src/grib_bufr_descriptor.cc | 2 +- src/grib_optimize_decimal_factor.cc | 2 +- src/grib_scaling.cc | 2 +- 30 files changed, 33 insertions(+), 32 deletions(-) diff --git a/src/functions.cc b/src/functions.cc index 3c84d1dc1..fdcf9bf8e 100644 --- a/src/functions.cc +++ b/src/functions.cc @@ -8,7 +8,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal_cpp.h" +#include "grib_scaling.h" #include "grib_api_internal.h" long grib_op_eq(long a, long b) diff --git a/src/grib_accessor_class_apply_operators.cc b/src/grib_accessor_class_apply_operators.cc index 5aa497e65..1a40320fe 100644 --- a/src/grib_accessor_class_apply_operators.cc +++ b/src/grib_accessor_class_apply_operators.cc @@ -8,8 +8,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ - -#include "grib_api_internal_cpp.h" +#include "grib_scaling.h" #include "grib_api_internal.h" /* This is used by make_class.pl diff --git a/src/grib_accessor_class_bufr_data_array.cc b/src/grib_accessor_class_bufr_data_array.cc index b9826b8f9..65874b5ca 100644 --- a/src/grib_accessor_class_bufr_data_array.cc +++ b/src/grib_accessor_class_bufr_data_array.cc @@ -7,7 +7,7 @@ * In applying this licence, ECMWF does not waive the privileges and immunities granted to it by * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal_cpp.h" +#include "grib_scaling.h" #include "grib_api_internal.h" /* diff --git a/src/grib_accessor_class_bufr_elements_table.cc b/src/grib_accessor_class_bufr_elements_table.cc index 07b765591..320c86f8e 100644 --- a/src/grib_accessor_class_bufr_elements_table.cc +++ b/src/grib_accessor_class_bufr_elements_table.cc @@ -12,7 +12,7 @@ * Enrico Fucile ****************************************/ -#include "grib_api_internal_cpp.h" +#include "grib_scaling.h" #include "grib_api_internal.h" #if GRIB_PTHREADS diff --git a/src/grib_accessor_class_data_2order_packing.cc b/src/grib_accessor_class_data_2order_packing.cc index f2edfe246..ee8ef5983 100644 --- a/src/grib_accessor_class_data_2order_packing.cc +++ b/src/grib_accessor_class_data_2order_packing.cc @@ -8,7 +8,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal_cpp.h" +#include "grib_scaling.h" #include "grib_api_internal.h" /* diff --git a/src/grib_accessor_class_data_apply_bitmap.cc b/src/grib_accessor_class_data_apply_bitmap.cc index b187dec39..6fad8640a 100644 --- a/src/grib_accessor_class_data_apply_bitmap.cc +++ b/src/grib_accessor_class_data_apply_bitmap.cc @@ -8,7 +8,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal_cpp.h" +#include "grib_value.h" /* This is used by make_class.pl diff --git a/src/grib_accessor_class_data_ccsds_packing.cc b/src/grib_accessor_class_data_ccsds_packing.cc index bda1a7004..0d3858fbd 100644 --- a/src/grib_accessor_class_data_ccsds_packing.cc +++ b/src/grib_accessor_class_data_ccsds_packing.cc @@ -8,7 +8,8 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal_cpp.h" +#include "grib_bits_any_endian_simple.h" +#include "grib_scaling.h" /* This is used by make_class.pl diff --git a/src/grib_accessor_class_data_complex_packing.cc b/src/grib_accessor_class_data_complex_packing.cc index 606131f7a..0f01edfbc 100644 --- a/src/grib_accessor_class_data_complex_packing.cc +++ b/src/grib_accessor_class_data_complex_packing.cc @@ -8,8 +8,8 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_cpp.h" -#include "grib_api_internal_cpp.h" +#include "grib_ieeefloat.h" +#include "grib_scaling.h" #include /* This is used by make_class.pl diff --git a/src/grib_accessor_class_data_g1second_order_constant_width_packing.cc b/src/grib_accessor_class_data_g1second_order_constant_width_packing.cc index bba4cd2fa..fcd19f261 100644 --- a/src/grib_accessor_class_data_g1second_order_constant_width_packing.cc +++ b/src/grib_accessor_class_data_g1second_order_constant_width_packing.cc @@ -8,7 +8,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal_cpp.h" +#include "grib_scaling.h" #include "grib_api_internal.h" /* diff --git a/src/grib_accessor_class_data_g1second_order_general_extended_packing.cc b/src/grib_accessor_class_data_g1second_order_general_extended_packing.cc index 19a997436..f34a3ca4e 100644 --- a/src/grib_accessor_class_data_g1second_order_general_extended_packing.cc +++ b/src/grib_accessor_class_data_g1second_order_general_extended_packing.cc @@ -8,7 +8,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal_cpp.h" +#include "grib_scaling.h" #include "grib_api_internal.h" #include "grib_optimize_decimal_factor.h" diff --git a/src/grib_accessor_class_data_g1second_order_general_packing.cc b/src/grib_accessor_class_data_g1second_order_general_packing.cc index 60d99a237..f0f9f54b3 100644 --- a/src/grib_accessor_class_data_g1second_order_general_packing.cc +++ b/src/grib_accessor_class_data_g1second_order_general_packing.cc @@ -8,7 +8,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal_cpp.h" +#include "grib_scaling.h" #include "grib_api_internal.h" #include diff --git a/src/grib_accessor_class_data_g1second_order_row_by_row_packing.cc b/src/grib_accessor_class_data_g1second_order_row_by_row_packing.cc index b43cbccc1..19a9df467 100644 --- a/src/grib_accessor_class_data_g1second_order_row_by_row_packing.cc +++ b/src/grib_accessor_class_data_g1second_order_row_by_row_packing.cc @@ -8,7 +8,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal_cpp.h" +#include "grib_scaling.h" #include "grib_api_internal.h" /* diff --git a/src/grib_accessor_class_data_g1simple_packing.cc b/src/grib_accessor_class_data_g1simple_packing.cc index 9526a8b83..4b98368cb 100644 --- a/src/grib_accessor_class_data_g1simple_packing.cc +++ b/src/grib_accessor_class_data_g1simple_packing.cc @@ -8,7 +8,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal_cpp.h" +#include "grib_scaling.h" #include "grib_api_internal.h" /* diff --git a/src/grib_accessor_class_data_g22order_packing.cc b/src/grib_accessor_class_data_g22order_packing.cc index b01ba8d59..24d8d687d 100644 --- a/src/grib_accessor_class_data_g22order_packing.cc +++ b/src/grib_accessor_class_data_g22order_packing.cc @@ -9,7 +9,7 @@ */ -#include "grib_api_internal_cpp.h" +#include "grib_scaling.h" #include "grib_api_internal.h" #include diff --git a/src/grib_accessor_class_data_g2bifourier_packing.cc b/src/grib_accessor_class_data_g2bifourier_packing.cc index d9c09b95d..4d60288fa 100644 --- a/src/grib_accessor_class_data_g2bifourier_packing.cc +++ b/src/grib_accessor_class_data_g2bifourier_packing.cc @@ -12,7 +12,7 @@ * philippe.marguinaud@meteo.fr *******************************/ -#include "grib_api_internal_cpp.h" +#include "grib_scaling.h" #include "grib_api_internal.h" #include "grib_optimize_decimal_factor.h" #include diff --git a/src/grib_accessor_class_data_g2simple_packing.cc b/src/grib_accessor_class_data_g2simple_packing.cc index 974c23226..8347a1549 100644 --- a/src/grib_accessor_class_data_g2simple_packing.cc +++ b/src/grib_accessor_class_data_g2simple_packing.cc @@ -8,7 +8,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal_cpp.h" +#include "grib_scaling.h" #include "grib_api_internal.h" /* diff --git a/src/grib_accessor_class_data_jpeg2000_packing.cc b/src/grib_accessor_class_data_jpeg2000_packing.cc index 78441f478..b3fde5e49 100644 --- a/src/grib_accessor_class_data_jpeg2000_packing.cc +++ b/src/grib_accessor_class_data_jpeg2000_packing.cc @@ -8,7 +8,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal_cpp.h" +#include "grib_scaling.h" #include "grib_api_internal.h" /* diff --git a/src/grib_accessor_class_data_png_packing.cc b/src/grib_accessor_class_data_png_packing.cc index 5c8edf76a..0bebb23f8 100644 --- a/src/grib_accessor_class_data_png_packing.cc +++ b/src/grib_accessor_class_data_png_packing.cc @@ -8,7 +8,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal_cpp.h" +#include "grib_scaling.h" #include "grib_api_internal.h" #define PNG_ANYBITS diff --git a/src/grib_accessor_class_data_raw_packing.cc b/src/grib_accessor_class_data_raw_packing.cc index b44094719..2d36ef58a 100644 --- a/src/grib_accessor_class_data_raw_packing.cc +++ b/src/grib_accessor_class_data_raw_packing.cc @@ -11,7 +11,7 @@ * Enrico Fucile ****************************/ -#include "grib_api_internal_cpp.h" +#include "grib_ieeefloat.h" #define PRE_PROCESSING_NONE 0 #define PRE_PROCESSING_DIFFERENCE 1 diff --git a/src/grib_accessor_class_data_run_length_packing.cc b/src/grib_accessor_class_data_run_length_packing.cc index 71c16f495..d20697e1d 100644 --- a/src/grib_accessor_class_data_run_length_packing.cc +++ b/src/grib_accessor_class_data_run_length_packing.cc @@ -8,7 +8,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal_cpp.h" +#include "grib_scaling.h" #include "grib_api_internal.h" /* diff --git a/src/grib_accessor_class_data_sh_packed.cc b/src/grib_accessor_class_data_sh_packed.cc index 2741d6b41..d5cdc5ccb 100644 --- a/src/grib_accessor_class_data_sh_packed.cc +++ b/src/grib_accessor_class_data_sh_packed.cc @@ -8,7 +8,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal_cpp.h" +#include "grib_scaling.h" #include "grib_api_internal.h" #include /* diff --git a/src/grib_accessor_class_data_sh_unpacked.cc b/src/grib_accessor_class_data_sh_unpacked.cc index 8894e8bc2..c0db2fa99 100644 --- a/src/grib_accessor_class_data_sh_unpacked.cc +++ b/src/grib_accessor_class_data_sh_unpacked.cc @@ -8,7 +8,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal_cpp.h" +#include "grib_scaling.h" #include "grib_api_internal.h" #include /* diff --git a/src/grib_accessor_class_data_simple_packing.cc b/src/grib_accessor_class_data_simple_packing.cc index 192adddd5..80b632035 100644 --- a/src/grib_accessor_class_data_simple_packing.cc +++ b/src/grib_accessor_class_data_simple_packing.cc @@ -8,7 +8,8 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal_cpp.h" +#include "grib_scaling.h" +#include "grib_bits_any_endian_simple.h" #include "grib_optimize_decimal_factor.h" #include diff --git a/src/grib_accessor_class_expanded_descriptors.cc b/src/grib_accessor_class_expanded_descriptors.cc index ee6bd8fbb..61e961396 100644 --- a/src/grib_accessor_class_expanded_descriptors.cc +++ b/src/grib_accessor_class_expanded_descriptors.cc @@ -15,7 +15,7 @@ can appear */ -#include "grib_api_internal_cpp.h" +#include "grib_scaling.h" #include "grib_api_internal.h" /* This is used by make_class.pl diff --git a/src/grib_accessor_class_gen.cc b/src/grib_accessor_class_gen.cc index ba85a8855..82064b987 100644 --- a/src/grib_accessor_class_gen.cc +++ b/src/grib_accessor_class_gen.cc @@ -14,9 +14,9 @@ * Shahram Najm * ***************************************************************************/ #include "grib_api_internal.h" +#include "grib_value.h" #include #include -#include "grib_api_internal_cpp.h" /* This is used by make_class.pl diff --git a/src/grib_accessor_class_second_order_bits_per_value.cc b/src/grib_accessor_class_second_order_bits_per_value.cc index ae807f7cb..00d8f9958 100644 --- a/src/grib_accessor_class_second_order_bits_per_value.cc +++ b/src/grib_accessor_class_second_order_bits_per_value.cc @@ -12,7 +12,7 @@ * Enrico Fucile **********************************/ -#include "grib_api_internal_cpp.h" +#include "grib_scaling.h" #include "grib_api_internal.h" /* This is used by make_class.pl diff --git a/src/grib_accessor_class_simple_packing_error.cc b/src/grib_accessor_class_simple_packing_error.cc index 591c35563..50ea5be57 100644 --- a/src/grib_accessor_class_simple_packing_error.cc +++ b/src/grib_accessor_class_simple_packing_error.cc @@ -13,7 +13,7 @@ **************************************/ -#include "grib_api_internal_cpp.h" +#include "grib_scaling.h" #include "grib_api_internal.h" /* This is used by make_class.pl diff --git a/src/grib_bufr_descriptor.cc b/src/grib_bufr_descriptor.cc index 99a406783..9d8516103 100644 --- a/src/grib_bufr_descriptor.cc +++ b/src/grib_bufr_descriptor.cc @@ -9,7 +9,7 @@ */ -#include "grib_api_internal_cpp.h" +#include "grib_scaling.h" #include "grib_api_internal.h" bufr_descriptor* grib_bufr_descriptor_new(grib_accessor* tables_accessor, int code, int silent, int* err) diff --git a/src/grib_optimize_decimal_factor.cc b/src/grib_optimize_decimal_factor.cc index bb4a64ce1..2e31e2c23 100644 --- a/src/grib_optimize_decimal_factor.cc +++ b/src/grib_optimize_decimal_factor.cc @@ -8,7 +8,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal_cpp.h" +#include "grib_scaling.h" #include "grib_api_internal.h" #include "grib_optimize_decimal_factor.h" #include diff --git a/src/grib_scaling.cc b/src/grib_scaling.cc index 2f2d98863..e31e4cfb8 100644 --- a/src/grib_scaling.cc +++ b/src/grib_scaling.cc @@ -12,7 +12,7 @@ * Enrico Fucile **************************************/ -#include "grib_api_internal_cpp.h" +#include "grib_scaling.h" #include "grib_api_internal.h" long grib_get_binary_scale_fact(double max, double min, long bpval, int* ret) From a61073e179a389d4bd7550d3ee064af922bd6c16 Mon Sep 17 00:00:00 2001 From: Eugen Betke Date: Tue, 13 Jun 2023 14:20:58 +0000 Subject: [PATCH 06/12] ECC-1467: Restore grib_fortran.c --- fortran/grib_fortran.c | 53 +++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/fortran/grib_fortran.c b/fortran/grib_fortran.c index e6fa07439..976eaa2ce 100644 --- a/fortran/grib_fortran.c +++ b/fortran/grib_fortran.c @@ -2783,41 +2783,38 @@ int grib_f_get_real4(int* gid, char* key, float* val, int len){ int grib_f_get_real4_array_(int* gid, char* key, float *val, int* size, int len) { - /*See ECC-1579:*/ - /*Ideally we should be calling:*/ - - size_t lsize = *size; - char buf[1024]; + /* See ECC-1579: + * Ideally we should be calling: + * err = grib_get_float_array(h, cast_char(buf,key,len), val, &lsize); + * + */ + grib_handle *h = get_handle(*gid); int err = GRIB_SUCCESS; - err = grib_get_float_array(h, cast_char(buf,key,len), val, &lsize); - - /*grib_handle *h = get_handle(*gid);*/ - /*int err = GRIB_SUCCESS;*/ - /*char buf[1024];*/ - /*size_t lsize = *size;*/ - /*double* val8 = NULL;*/ - /*size_t i;*/ + char buf[1024]; + size_t lsize = *size; + double* val8 = NULL; + size_t i; - /*if(!h) return GRIB_INVALID_GRIB;*/ + if(!h) return GRIB_INVALID_GRIB; - /*if(*size)*/ - /* val8 = (double*)grib_context_malloc(h->context,(*size)*(sizeof(double)));*/ - /*else*/ - /* val8 = (double*)grib_context_malloc(h->context,sizeof(double));*/ + if(*size) + val8 = (double*)grib_context_malloc(h->context,(*size)*(sizeof(double))); + else + val8 = (double*)grib_context_malloc(h->context,sizeof(double)); - /*if(!val8) return GRIB_OUT_OF_MEMORY;*/ + if(!val8) return GRIB_OUT_OF_MEMORY; - /*err = grib_get_double_array(h, cast_char(buf,key,len), val8, &lsize);*/ - /*if (err) {*/ - /* grib_context_free(h->context,val8);*/ - /* return err;*/ - /*}*/ + err = grib_get_double_array(h, cast_char(buf,key,len), val8, &lsize); + if (err) { + grib_context_free(h->context,val8); + return err; + } - /*for(i=0;icontext,val8);*/ + grib_context_free(h->context,val8); return err; } @@ -3160,7 +3157,6 @@ int grib_f_get_real8_array_(int* gid, char* key, double*val, int* size, int len) return GRIB_INVALID_GRIB; }else{ err = grib_get_double_array(h, cast_char(buf,key,len), val, &lsize); - printf("%30s - %0.60f\n", __func__, val[40]); *size = lsize; return err; } @@ -3170,7 +3166,6 @@ int grib_f_get_real8_array__(int* gid, char* key, double*val, int* size, int len } int grib_f_get_real8_array(int* gid, char* key, double*val, int* size, int len){ return grib_f_get_real8_array_( gid, key, val, size, len); - printf("%s - %0.60f\n", __func__, val[40]); } int grib_f_set_force_real8_array__(int* gid, char* key, double *val, int* size, int len){ From e3ea8ecf1ad6d1ac9939b9abb3b8505a5bb58e75 Mon Sep 17 00:00:00 2001 From: Eugen Betke Date: Thu, 22 Jun 2023 12:04:28 +0000 Subject: [PATCH 07/12] ECC-1467: Use grib_power in unpack() --- src/grib_accessor_class_data_ccsds_packing.cc | 4 ++-- src/grib_accessor_class_data_g22order_packing.cc | 4 ++-- src/grib_accessor_class_data_simple_packing.cc | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/grib_accessor_class_data_ccsds_packing.cc b/src/grib_accessor_class_data_ccsds_packing.cc index 0d3858fbd..7b03e3083 100644 --- a/src/grib_accessor_class_data_ccsds_packing.cc +++ b/src/grib_accessor_class_data_ccsds_packing.cc @@ -514,8 +514,8 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return GRIB_SUCCESS; } - bscale = grib_power(binary_scale_factor, 2); - dscale = grib_power(-decimal_scale_factor, 10); + bscale = grib_power(binary_scale_factor, 2); + dscale = grib_power(-decimal_scale_factor, 10); buflen = grib_byte_count(a); buf = (unsigned char*)hand->buffer->data; diff --git a/src/grib_accessor_class_data_g22order_packing.cc b/src/grib_accessor_class_data_g22order_packing.cc index 24d8d687d..f4de10f23 100644 --- a/src/grib_accessor_class_data_g22order_packing.cc +++ b/src/grib_accessor_class_data_g22order_packing.cc @@ -750,8 +750,8 @@ static int unpack(grib_accessor* a, T* val, const size_t* len) // de_spatial_difference (a->context, sec_val, n_vals, orderOfSpatialDifferencing, bias); } - binary_s = (T)grib_power(binary_scale_factor, 2); - decimal_s = (T)grib_power(-decimal_scale_factor, 10); + binary_s = (T)grib_power(binary_scale_factor, 2); + decimal_s = (T)grib_power(-decimal_scale_factor, 10); for (i = 0; i < n_vals; i++) { if (sec_val[i] == LONG_MAX) { diff --git a/src/grib_accessor_class_data_simple_packing.cc b/src/grib_accessor_class_data_simple_packing.cc index 80b632035..9db561ce4 100644 --- a/src/grib_accessor_class_data_simple_packing.cc +++ b/src/grib_accessor_class_data_simple_packing.cc @@ -369,8 +369,8 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return GRIB_SUCCESS; } - s = grib_power(binary_scale_factor, 2); - d = grib_power(-decimal_scale_factor, 10); + s = grib_power(binary_scale_factor, 2); + d = grib_power(-decimal_scale_factor, 10); grib_context_log(a->context, GRIB_LOG_DEBUG, "%s %s: Creating %s, %zu values", cclass_name, __func__, a->name, n_vals); From c3e41cc950df1fc4429b45b7c9209b381573ae9c Mon Sep 17 00:00:00 2001 From: Eugen Betke Date: Thu, 22 Jun 2023 12:12:32 +0000 Subject: [PATCH 08/12] ECC-1467: Use grib_power in unpack() --- ...grib_accessor_class_data_g1second_order_general_packing.cc | 4 ++-- ...b_accessor_class_data_g1second_order_row_by_row_packing.cc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/grib_accessor_class_data_g1second_order_general_packing.cc b/src/grib_accessor_class_data_g1second_order_general_packing.cc index f0f9f54b3..c0a17dccd 100644 --- a/src/grib_accessor_class_data_g1second_order_general_packing.cc +++ b/src/grib_accessor_class_data_g1second_order_general_packing.cc @@ -288,8 +288,8 @@ static int unpack(grib_accessor* a, T* values, size_t* len) } } - s = grib_power(binary_scale_factor, 2); - d = grib_power(-decimal_scale_factor, 10); + s = grib_power(binary_scale_factor, 2); + d = grib_power(-decimal_scale_factor, 10); for (i = 0; i < numberOfSecondOrderPackedValues; i++) { values[i] = (T)(((X[i] * s) + reference_value) * d); } diff --git a/src/grib_accessor_class_data_g1second_order_row_by_row_packing.cc b/src/grib_accessor_class_data_g1second_order_row_by_row_packing.cc index 19a9df467..f98a048c3 100644 --- a/src/grib_accessor_class_data_g1second_order_row_by_row_packing.cc +++ b/src/grib_accessor_class_data_g1second_order_row_by_row_packing.cc @@ -412,8 +412,8 @@ static int unpack(grib_accessor* a, T* values, size_t* len) k++; } - s = grib_power(binary_scale_factor, 2); - d = grib_power(-decimal_scale_factor, 10); + s = grib_power(binary_scale_factor, 2); + d = grib_power(-decimal_scale_factor, 10); for (i = 0; i < n; i++) { values[i] = (T)(((X[i] * s) + reference_value) * d); } From 07f537a02c8b5e379678fe373517509a479cca03 Mon Sep 17 00:00:00 2001 From: Eugen Betke Date: Thu, 22 Jun 2023 12:24:41 +0000 Subject: [PATCH 09/12] ECC-1467: Use grib_power in pack_double() --- src/grib_accessor_class_data_ccsds_packing.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/grib_accessor_class_data_ccsds_packing.cc b/src/grib_accessor_class_data_ccsds_packing.cc index c7f57608c..5acce2a62 100644 --- a/src/grib_accessor_class_data_ccsds_packing.cc +++ b/src/grib_accessor_class_data_ccsds_packing.cc @@ -346,9 +346,9 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) range = (max - min); unscaled_min = min; unscaled_max = max; - f = (grib_power(bits_per_value, 2) - 1); - minrange = grib_power(-last, 2) * f; - maxrange = grib_power(last, 2) * f; + f = (grib_power(bits_per_value, 2) - 1); + minrange = grib_power(-last, 2) * f; + maxrange = grib_power(last, 2) * f; while (range < minrange) { decimal_scale_factor += 1; From 4cba81667f4af698654b81d0710a3be68930e7cd Mon Sep 17 00:00:00 2001 From: Eugen Betke Date: Thu, 22 Jun 2023 14:09:01 +0000 Subject: [PATCH 10/12] ECC-1467: Rename grid_power<>() to codes_power<>() --- src/eccodes_prototypes.h | 2 +- src/functions.cc | 2 +- src/grib_accessor_class_bufr_data_array.cc | 8 ++-- ...grib_accessor_class_bufr_elements_table.cc | 2 +- ...grib_accessor_class_data_2order_packing.cc | 8 ++-- src/grib_accessor_class_data_ccsds_packing.cc | 16 ++++---- ...rib_accessor_class_data_complex_packing.cc | 14 +++---- ...a_g1second_order_constant_width_packing.cc | 4 +- ...g1second_order_general_extended_packing.cc | 40 +++++++++---------- ...ass_data_g1second_order_general_packing.cc | 4 +- ..._data_g1second_order_row_by_row_packing.cc | 4 +- ...ib_accessor_class_data_g1simple_packing.cc | 4 +- ...ib_accessor_class_data_g22order_packing.cc | 4 +- ...accessor_class_data_g2bifourier_packing.cc | 8 ++-- ...ib_accessor_class_data_g2simple_packing.cc | 4 +- ...ib_accessor_class_data_jpeg2000_packing.cc | 8 ++-- src/grib_accessor_class_data_png_packing.cc | 8 ++-- ..._accessor_class_data_run_length_packing.cc | 2 +- src/grib_accessor_class_data_sh_packed.cc | 4 +- src/grib_accessor_class_data_sh_unpacked.cc | 4 +- ...grib_accessor_class_data_simple_packing.cc | 24 +++++------ ...rib_accessor_class_expanded_descriptors.cc | 2 +- ...essor_class_second_order_bits_per_value.cc | 4 +- ...rib_accessor_class_simple_packing_error.cc | 2 +- src/grib_bits_any_endian.cc | 4 +- src/grib_bufr_descriptor.cc | 2 +- src/grib_header_compute.cc | 2 +- src/grib_optimize_decimal_factor.cc | 20 +++++----- src/grib_scaling.cc | 16 +++++--- src/grib_scaling.h | 4 +- 30 files changed, 118 insertions(+), 112 deletions(-) diff --git a/src/eccodes_prototypes.h b/src/eccodes_prototypes.h index 9944f80e4..db932912d 100644 --- a/src/eccodes_prototypes.h +++ b/src/eccodes_prototypes.h @@ -1191,7 +1191,7 @@ grib_accessor* grib_find_attribute(grib_handle* h, const char* name, const char* grib_accessor* grib_find_accessor_fast(grib_handle* h, const char* name); /* grib_scaling.cc*/ -//double grib_power(long s, long n); +double grib_power(long s, long n); long grib_get_binary_scale_fact(double max, double min, long bpval, int* ret); long grib_get_bits_per_value(double max, double min, long binary_scale_factor); long grib_get_decimal_scale_fact(double max, double min, long bpval, long binary_scale); diff --git a/src/functions.cc b/src/functions.cc index 0f74ec41e..9680d07bd 100644 --- a/src/functions.cc +++ b/src/functions.cc @@ -70,7 +70,7 @@ double grib_op_neg_d(double a) long grib_op_pow(long a, long b) { /* Note: This is actually 'a' to the power 'b' */ - return grib_power(b, a); + return codes_power(b, a); } long grib_op_add(long a, long b) diff --git a/src/grib_accessor_class_bufr_data_array.cc b/src/grib_accessor_class_bufr_data_array.cc index c4d64fb43..aef3ceefd 100644 --- a/src/grib_accessor_class_bufr_data_array.cc +++ b/src/grib_accessor_class_bufr_data_array.cc @@ -803,7 +803,7 @@ static int encode_double_array(grib_context* c, grib_buffer* buff, long* pos, bu modifiedReference = bd->reference; modifiedFactor = bd->factor; - inverseFactor = grib_power(bd->scale, 10); + inverseFactor = codes_power(bd->scale, 10); modifiedWidth = bd->width; err = descriptor_get_min_max(bd, modifiedWidth, modifiedReference, modifiedFactor, &minAllowed, &maxAllowed); @@ -945,10 +945,10 @@ static int encode_double_array(grib_context* c, grib_buffer* buff, long* pos, bu localRange = (max - min) * inverseFactor + 1; localWidth = ceil(log(localRange) / log(2.0)); lval = round(max * inverseFactor) - reference; - allone = grib_power(localWidth, 2) - 1; + allone = codes_power(localWidth, 2) - 1; while (allone <= lval) { localWidth++; - allone = grib_power(localWidth, 2) - 1; + allone = codes_power(localWidth, 2) - 1; } if (localWidth == 1) localWidth++; @@ -3236,7 +3236,7 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st return err; } bd = grib_bufr_descriptor_clone(self->expanded->v[index]); - bd->reference = -grib_power(bd->width, 2); + bd->reference = -codes_power(bd->width, 2); bd->width++; err = codec_element(c, self, iss, buffer, data, &pos, index, bd, elementIndex, dval, sval); diff --git a/src/grib_accessor_class_bufr_elements_table.cc b/src/grib_accessor_class_bufr_elements_table.cc index 320c86f8e..a4d0b1d47 100644 --- a/src/grib_accessor_class_bufr_elements_table.cc +++ b/src/grib_accessor_class_bufr_elements_table.cc @@ -351,7 +351,7 @@ static int bufr_get_from_table(grib_accessor* a, bufr_descriptor* v) /* ECC-985: Scale and reference are often 0 so we can reduce calls to atol */ v->scale = atol_fast(list[5]); - v->factor = grib_power(-v->scale, 10); + v->factor = codes_power(-v->scale, 10); v->reference = atol_fast(list[6]); v->width = atol(list[7]); diff --git a/src/grib_accessor_class_data_2order_packing.cc b/src/grib_accessor_class_data_2order_packing.cc index f21d189e8..a501dbdf1 100644 --- a/src/grib_accessor_class_data_2order_packing.cc +++ b/src/grib_accessor_class_data_2order_packing.cc @@ -622,8 +622,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) if (boustrophedonic) reverse_rows(sec_val, n_vals, Ni, bitmap, bitmap_len); - s = grib_power(binary_scale_factor, 2); - d = grib_power(-decimal_scale_factor, 10); + s = codes_power(binary_scale_factor, 2); + d = codes_power(-decimal_scale_factor, 10); for (i = 0; i < n_vals; i++) val[i] = (double)((((double)sec_val[i]) * s) + reference_value) * d; @@ -765,7 +765,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) /* calculation of integer array */ sec_val = (unsigned long*)grib_context_malloc(a->context, (n_vals) * sizeof(long)); - d = grib_power(decimal_scale_factor, 10); + d = codes_power(decimal_scale_factor, 10); max = val[0]; min = max; for (i = 0; i < n_vals; i++) { @@ -787,7 +787,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) /* the scale factor in Grib 1 is adjusted in gribex, for "normalization purpose" ... ?*/ binary_scale_factor = grib_get_binary_scale_fact(max, reference_value, bits_per_value, &err); - divisor = grib_power(-binary_scale_factor, 2); + divisor = codes_power(-binary_scale_factor, 2); for (i = 0; i < n_vals; i++) diff --git a/src/grib_accessor_class_data_ccsds_packing.cc b/src/grib_accessor_class_data_ccsds_packing.cc index 5acce2a62..596a8b263 100644 --- a/src/grib_accessor_class_data_ccsds_packing.cc +++ b/src/grib_accessor_class_data_ccsds_packing.cc @@ -316,7 +316,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) return err; if (bits_per_value == 0 || (binary_scale_factor == 0 && decimal_scale_factor != 0)) { - d = grib_power(decimal_scale_factor, 10); + d = codes_power(decimal_scale_factor, 10); min *= d; max *= d; @@ -346,9 +346,9 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) range = (max - min); unscaled_min = min; unscaled_max = max; - f = (grib_power(bits_per_value, 2) - 1); - minrange = grib_power(-last, 2) * f; - maxrange = grib_power(last, 2) * f; + f = (codes_power(bits_per_value, 2) - 1); + minrange = codes_power(-last, 2) * f; + maxrange = codes_power(last, 2) * f; while (range < minrange) { decimal_scale_factor += 1; @@ -370,11 +370,11 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) "%s %s: unable to find nearest_smaller_value of %g for %s", cclass_name, __func__, min, self->reference_value); return GRIB_INTERNAL_ERROR; } - d = grib_power(decimal_scale_factor, 10); + d = codes_power(decimal_scale_factor, 10); } binary_scale_factor = grib_get_binary_scale_fact(max, reference_value, bits_per_value, &err); - divisor = grib_power(-binary_scale_factor, 2); + divisor = codes_power(-binary_scale_factor, 2); size_t nbytes = (bits_per_value + 7) / 8; // ECC-1602: use native a data type (4 bytes for uint32_t) for values that require only 3 bytes @@ -566,8 +566,8 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return GRIB_SUCCESS; } - bscale = grib_power(binary_scale_factor, 2); - dscale = grib_power(-decimal_scale_factor, 10); + bscale = codes_power(binary_scale_factor, 2); + dscale = codes_power(-decimal_scale_factor, 10); buflen = grib_byte_count(a); buf = (unsigned char*)hand->buffer->data; diff --git a/src/grib_accessor_class_data_complex_packing.cc b/src/grib_accessor_class_data_complex_packing.cc index 8ead31bd0..06b2bcbb8 100644 --- a/src/grib_accessor_class_data_complex_packing.cc +++ b/src/grib_accessor_class_data_complex_packing.cc @@ -447,7 +447,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) if (pen_j == sub_j) { double* values; - d = grib_power(decimal_scale_factor, 10); + d = codes_power(decimal_scale_factor, 10); if (d) { values = (double*)grib_context_malloc_clear(a->context, sizeof(double) * n_vals); for (i = 0; i < n_vals; i++) @@ -547,10 +547,10 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) "%s: unable to find nearest_smaller_value of %g for %s", cclass_name, min, self->reference_value); return GRIB_INTERNAL_ERROR; } - d = grib_power(+decimal_scale_factor, 10); + d = codes_power(+decimal_scale_factor, 10); } else { - d = grib_power(+decimal_scale_factor, 10); + d = codes_power(+decimal_scale_factor, 10); if (grib_get_nearest_smaller_value(gh, self->reference_value, d * min, &reference_value) != GRIB_SUCCESS) { grib_context_log(gh->context, GRIB_LOG_ERROR, "%s: unable to find nearest_smaller_value of %g for %s", cclass_name, d * min, self->reference_value); @@ -570,7 +570,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) } } } - s = grib_power(-binary_scale_factor, 2); + s = codes_power(-binary_scale_factor, 2); i = 0; @@ -812,7 +812,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) if (pen_j == sub_j) { n_vals = (pen_j + 1) * (pen_j + 2); - d = grib_power(-decimal_scale_factor, 10); + d = codes_power(-decimal_scale_factor, 10); grib_ieee_decode_array(a->context, buf, n_vals, bytes, val); if (d) { @@ -826,8 +826,8 @@ static int unpack(grib_accessor* a, T* val, size_t* len) lpos = 8 * (packed_offset - offsetdata); - s = grib_power(binary_scale_factor, 2); - d = grib_power(-decimal_scale_factor, 10); + s = codes_power(binary_scale_factor, 2); + d = codes_power(-decimal_scale_factor, 10); scals = (T*)grib_context_malloc(a->context, maxv * sizeof(T)); if (!scals) return GRIB_OUT_OF_MEMORY; diff --git a/src/grib_accessor_class_data_g1second_order_constant_width_packing.cc b/src/grib_accessor_class_data_g1second_order_constant_width_packing.cc index fcd19f261..74a70b3ac 100644 --- a/src/grib_accessor_class_data_g1second_order_constant_width_packing.cc +++ b/src/grib_accessor_class_data_g1second_order_constant_width_packing.cc @@ -299,8 +299,8 @@ static int unpack_double(grib_accessor* a, double* values, size_t* len) printf("XXXXXXX extrabits=%ld pos=%ld\n",extrabits,pos); }*/ - s = grib_power(binary_scale_factor, 2); - d = grib_power(-decimal_scale_factor, 10); + s = codes_power(binary_scale_factor, 2); + d = codes_power(-decimal_scale_factor, 10); for (i = 0; i < numberOfSecondOrderPackedValues; i++) { values[i] = (double)(((X[i] * s) + reference_value) * d); } diff --git a/src/grib_accessor_class_data_g1second_order_general_extended_packing.cc b/src/grib_accessor_class_data_g1second_order_general_extended_packing.cc index f34a3ca4e..7161bdecf 100644 --- a/src/grib_accessor_class_data_g1second_order_general_extended_packing.cc +++ b/src/grib_accessor_class_data_g1second_order_general_extended_packing.cc @@ -532,8 +532,8 @@ static int unpack(grib_accessor* a, double* dvalues, float* fvalues, size_t* len self->dvalues = (double*)grib_context_malloc_clear(a->context, sizeof(double) * numberOfValues); } - double s = grib_power(binary_scale_factor, 2); - double d = grib_power(-decimal_scale_factor, 10); + double s = codes_power(binary_scale_factor, 2); + double d = codes_power(-decimal_scale_factor, 10); for (i = 0; i < numberOfValues; i++) { dvalues[i] = (double)(((X[i] * s) + reference_value) * d); self->dvalues[i] = dvalues[i]; @@ -551,8 +551,8 @@ static int unpack(grib_accessor* a, double* dvalues, float* fvalues, size_t* len self->fvalues = (float*)grib_context_malloc_clear(a->context, sizeof(float) * numberOfValues); } - float s = grib_power(binary_scale_factor, 2); - float d = grib_power(-decimal_scale_factor, 10); + float s = codes_power(binary_scale_factor, 2); + float d = codes_power(-decimal_scale_factor, 10); for (i = 0; i < numberOfValues; i++) { fvalues[i] = (float)(((X[i] * s) + reference_value) * d); self->fvalues[i] = fvalues[i]; @@ -756,7 +756,7 @@ static int pack_double_old(grib_accessor* a, const double* val, size_t *len) if((ret = grib_get_long_internal(handle,self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) return ret; - decimal = grib_power(decimal_scale_factor,10); + decimal = codes_power(decimal_scale_factor,10); max*=decimal; min*=decimal; @@ -790,7 +790,7 @@ static int pack_double_old(grib_accessor* a, const double* val, size_t *len) GRIB_SUCCESS) return ret; - divisor = grib_power(-binary_scale_factor,2); + divisor = codes_power(-binary_scale_factor,2); X=(long*)grib_context_malloc_clear(a->context,sizeof(long)*numberOfValues); for(i=0;i< numberOfValues;i++){ X[i] = (((val[i]*decimal)-reference_value)*divisor)+0.5; @@ -861,7 +861,7 @@ static int pack_double_old(grib_accessor* a, const double* val, size_t *len) } } groupWidthA=number_of_bits(handle, maxA-minA); - range=(long)grib_power(groupWidthA,2)-1; + range=(long)codes_power(groupWidthA,2)-1; offsetC=count+groupLengthA; if (offsetC==numberOfValues) { @@ -949,7 +949,7 @@ static int pack_double_old(grib_accessor* a, const double* val, size_t *len) if (minA>X[count+i]) minA=X[count+i]; } groupWidthA=number_of_bits(maxA-minA); - range=(long)grib_power(groupWidthA,2)-1; + range=(long)codes_power(groupWidthA,2)-1; groupLengths[numberOfGroups]=groupLengthA; groupWidths[numberOfGroups]=groupWidthA; firstOrderValues[numberOfGroups] = maxA-range > 0 ? maxA-range : 0; @@ -1013,7 +1013,7 @@ static int pack_double_old(grib_accessor* a, const double* val, size_t *len) if (minA>X[count+i]) minA=X[count+i]; } groupWidthA=number_of_bits(maxA-minA); - range=(long)grib_power(groupWidthA,2)-1; + range=(long)codes_power(groupWidthA,2)-1; groupLengths[numberOfGroups]=groupLengthA; groupWidths[numberOfGroups]=groupWidthA; firstOrderValues[numberOfGroups] = maxA-range > 0 ? maxA-range : 0; @@ -1055,7 +1055,7 @@ static int pack_double_old(grib_accessor* a, const double* val, size_t *len) if (min>firstOrderValues[i]) min=firstOrderValues[i]; } widthOfFirstOrderValues=number_of_bits(handle, max-min); - firstOrderValuesMax=(long)grib_power(widthOfFirstOrderValues,2)-1; + firstOrderValuesMax=(long)codes_power(widthOfFirstOrderValues,2)-1; if (numberOfGroups>2) { /* loop through all the groups except the last in reverse order to @@ -1079,7 +1079,7 @@ static int pack_double_old(grib_accessor* a, const double* val, size_t *len) if (min>X[offset+j]) min=X[offset+j]; } groupWidth=number_of_bits(handle, max-min); - range=(long)grib_power(groupWidth,2)-1; + range=(long)codes_power(groupWidth,2)-1; /* width of first order values has to be unchanged.*/ for (j=groupWidth;j(decimal_scale_factor, 10); - divisor = grib_power(-binary_scale_factor, 2); + decimal = codes_power(decimal_scale_factor, 10); + divisor = codes_power(-binary_scale_factor, 2); /*min = min * decimal;*/ /*max = max * decimal;*/ @@ -1410,7 +1410,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) if ((ret = grib_get_long_internal(handle, self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) return ret; - decimal = grib_power(decimal_scale_factor, 10); + decimal = codes_power(decimal_scale_factor, 10); min = min * decimal; max = max * decimal; @@ -1421,7 +1421,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) } binary_scale_factor = grib_get_binary_scale_fact(max, reference_value, bits_per_value, &ret); - divisor = grib_power(-binary_scale_factor, 2); + divisor = codes_power(-binary_scale_factor, 2); } if ((ret = grib_set_long_internal(handle, self->binary_scale_factor, binary_scale_factor)) != @@ -1515,7 +1515,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) } } groupWidthA = number_of_bits(handle, maxA - minA); - range = (long)grib_power(groupWidthA, 2) - 1; + range = (long)codes_power(groupWidthA, 2) - 1; offsetC = count + groupLengthA; if (offsetC == numberOfValues) { @@ -1608,7 +1608,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) if (minA>X[count+i]) minA=X[count+i]; } groupWidthA=number_of_bits(maxA-minA); - range=(long)grib_power(groupWidthA,2)-1; + range=(long)codes_power(groupWidthA,2)-1; groupLengths[numberOfGroups]=groupLengthA; groupWidths[numberOfGroups]=groupWidthA; firstOrderValues[numberOfGroups] = maxA-range > 0 ? maxA-range : 0; @@ -1673,7 +1673,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) if (minA>X[count+i]) minA=X[count+i]; } groupWidthA=number_of_bits(maxA-minA); - range=(long)grib_power(groupWidthA,2)-1; + range=(long)codes_power(groupWidthA,2)-1; groupLengths[numberOfGroups]=groupLengthA; groupWidths[numberOfGroups]=groupWidthA; firstOrderValues[numberOfGroups] = maxA-range > 0 ? maxA-range : 0; @@ -1717,7 +1717,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) min = firstOrderValues[i]; } widthOfFirstOrderValues = number_of_bits(handle, max - min); - firstOrderValuesMax = (long)grib_power(widthOfFirstOrderValues, 2) - 1; + firstOrderValuesMax = (long)codes_power(widthOfFirstOrderValues, 2) - 1; if (numberOfGroups > 2) { /* loop through all the groups except the last in reverse order to @@ -1745,7 +1745,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) min = X[offset + j]; } groupWidth = number_of_bits(handle, max - min); - range = (long)grib_power(groupWidth, 2) - 1; + range = (long)codes_power(groupWidth, 2) - 1; /* width of first order values has to be unchanged.*/ for (j = groupWidth; j < groupWidths[i]; j++) { diff --git a/src/grib_accessor_class_data_g1second_order_general_packing.cc b/src/grib_accessor_class_data_g1second_order_general_packing.cc index c0a17dccd..190220be5 100644 --- a/src/grib_accessor_class_data_g1second_order_general_packing.cc +++ b/src/grib_accessor_class_data_g1second_order_general_packing.cc @@ -288,8 +288,8 @@ static int unpack(grib_accessor* a, T* values, size_t* len) } } - s = grib_power(binary_scale_factor, 2); - d = grib_power(-decimal_scale_factor, 10); + s = codes_power(binary_scale_factor, 2); + d = codes_power(-decimal_scale_factor, 10); for (i = 0; i < numberOfSecondOrderPackedValues; i++) { values[i] = (T)(((X[i] * s) + reference_value) * d); } diff --git a/src/grib_accessor_class_data_g1second_order_row_by_row_packing.cc b/src/grib_accessor_class_data_g1second_order_row_by_row_packing.cc index f98a048c3..55e699aac 100644 --- a/src/grib_accessor_class_data_g1second_order_row_by_row_packing.cc +++ b/src/grib_accessor_class_data_g1second_order_row_by_row_packing.cc @@ -412,8 +412,8 @@ static int unpack(grib_accessor* a, T* values, size_t* len) k++; } - s = grib_power(binary_scale_factor, 2); - d = grib_power(-decimal_scale_factor, 10); + s = codes_power(binary_scale_factor, 2); + d = codes_power(-decimal_scale_factor, 10); for (i = 0; i < n; i++) { values[i] = (T)(((X[i] * s) + reference_value) * d); } diff --git a/src/grib_accessor_class_data_g1simple_packing.cc b/src/grib_accessor_class_data_g1simple_packing.cc index 4b98368cb..aeaf5f5c8 100644 --- a/src/grib_accessor_class_data_g1simple_packing.cc +++ b/src/grib_accessor_class_data_g1simple_packing.cc @@ -291,8 +291,8 @@ static int pack_double(grib_accessor* a, const double* cval, size_t* len) if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetsection, &offsetsection)) != GRIB_SUCCESS) return ret; - decimal = grib_power(decimal_scale_factor, 10); - divisor = grib_power(-binary_scale_factor, 2); + decimal = codes_power(decimal_scale_factor, 10); + divisor = codes_power(-binary_scale_factor, 2); buflen = (((bits_per_value * n_vals) + 7) / 8) * sizeof(unsigned char); if ((buflen + (offsetdata - offsetsection)) % 2) { diff --git a/src/grib_accessor_class_data_g22order_packing.cc b/src/grib_accessor_class_data_g22order_packing.cc index f4de10f23..806197d9a 100644 --- a/src/grib_accessor_class_data_g22order_packing.cc +++ b/src/grib_accessor_class_data_g22order_packing.cc @@ -750,8 +750,8 @@ static int unpack(grib_accessor* a, T* val, const size_t* len) // de_spatial_difference (a->context, sec_val, n_vals, orderOfSpatialDifferencing, bias); } - binary_s = (T)grib_power(binary_scale_factor, 2); - decimal_s = (T)grib_power(-decimal_scale_factor, 10); + binary_s = (T)codes_power(binary_scale_factor, 2); + decimal_s = (T)codes_power(-decimal_scale_factor, 10); for (i = 0; i < n_vals; i++) { if (sec_val[i] == LONG_MAX) { diff --git a/src/grib_accessor_class_data_g2bifourier_packing.cc b/src/grib_accessor_class_data_g2bifourier_packing.cc index 46545dfe6..76980612e 100644 --- a/src/grib_accessor_class_data_g2bifourier_packing.cc +++ b/src/grib_accessor_class_data_g2bifourier_packing.cc @@ -666,8 +666,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) buf = (unsigned char*)gh->buffer->data; buf += grib_byte_offset(a); - s = grib_power(bt->binary_scale_factor, 2); - d = grib_power(-bt->decimal_scale_factor, 10); + s = codes_power(bt->binary_scale_factor, 2); + d = codes_power(-bt->decimal_scale_factor, 10); /* * Decode data @@ -816,8 +816,8 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) if (ret != GRIB_SUCCESS) goto cleanup; - s = grib_power(-bt->binary_scale_factor, 2); - d = grib_power(+bt->decimal_scale_factor, 10); + s = codes_power(-bt->binary_scale_factor, 2); + d = codes_power(+bt->decimal_scale_factor, 10); } else { bt->decimal_scale_factor = 0; diff --git a/src/grib_accessor_class_data_g2simple_packing.cc b/src/grib_accessor_class_data_g2simple_packing.cc index 8347a1549..d3323bbdf 100644 --- a/src/grib_accessor_class_data_g2simple_packing.cc +++ b/src/grib_accessor_class_data_g2simple_packing.cc @@ -245,8 +245,8 @@ static int pack_double(grib_accessor* a, const double* cval, size_t* len) if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) return ret; - decimal = grib_power(decimal_scale_factor, 10); - divisor = grib_power(-binary_scale_factor, 2); + decimal = codes_power(decimal_scale_factor, 10); + divisor = codes_power(-binary_scale_factor, 2); buflen = (((bits_per_value * n_vals) + 7) / 8) * sizeof(unsigned char); buf = (unsigned char*)grib_context_buffer_malloc_clear(a->context, buflen); diff --git a/src/grib_accessor_class_data_jpeg2000_packing.cc b/src/grib_accessor_class_data_jpeg2000_packing.cc index b3fde5e49..a9d8c4410 100644 --- a/src/grib_accessor_class_data_jpeg2000_packing.cc +++ b/src/grib_accessor_class_data_jpeg2000_packing.cc @@ -272,8 +272,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) self->dirty = 0; - bscale = grib_power(binary_scale_factor, 2); - dscale = grib_power(-decimal_scale_factor, 10); + bscale = codes_power(binary_scale_factor, 2); + dscale = codes_power(-decimal_scale_factor, 10); /* TODO: This should be called upstream */ if (*len < n_vals) @@ -412,8 +412,8 @@ static int pack_double(grib_accessor* a, const double* cval, size_t* len) if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) return ret; - decimal = grib_power(decimal_scale_factor, 10); - divisor = grib_power(-binary_scale_factor, 2); + decimal = codes_power(decimal_scale_factor, 10); + divisor = codes_power(-binary_scale_factor, 2); simple_packing_size = (((bits_per_value * n_vals) + 7) / 8) * sizeof(unsigned char); buf = (unsigned char*)grib_context_malloc_clear(a->context, simple_packing_size + EXTRA_BUFFER_SIZE); diff --git a/src/grib_accessor_class_data_png_packing.cc b/src/grib_accessor_class_data_png_packing.cc index 29ddcfe88..f8890c237 100644 --- a/src/grib_accessor_class_data_png_packing.cc +++ b/src/grib_accessor_class_data_png_packing.cc @@ -249,8 +249,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) return err; - bscale = grib_power(binary_scale_factor, 2); - dscale = grib_power(-decimal_scale_factor, 10); + bscale = codes_power(binary_scale_factor, 2); + dscale = codes_power(-decimal_scale_factor, 10); /* TODO: This should be called upstream */ if (*len < n_vals) @@ -503,7 +503,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) return GRIB_SUCCESS; } - d = grib_power(decimal_scale_factor, 10); + d = codes_power(decimal_scale_factor, 10); max = val[0]; min = max; @@ -527,7 +527,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) } binary_scale_factor = grib_get_binary_scale_fact(max, reference_value, bits_per_value, &err); - divisor = grib_power(-binary_scale_factor, 2); + divisor = codes_power(-binary_scale_factor, 2); #ifndef PNG_ANYBITS Assert(bits_per_value % 8 == 0); diff --git a/src/grib_accessor_class_data_run_length_packing.cc b/src/grib_accessor_class_data_run_length_packing.cc index d20697e1d..422675438 100644 --- a/src/grib_accessor_class_data_run_length_packing.cc +++ b/src/grib_accessor_class_data_run_length_packing.cc @@ -204,7 +204,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) if (decimal_scale_factor > 127) { decimal_scale_factor = -(decimal_scale_factor - 128); } - level_scale_factor = grib_power(-decimal_scale_factor, 10.0); + level_scale_factor = codes_power(-decimal_scale_factor, 10.0); levels = (double*)grib_context_malloc_clear(a->context, sizeof(double) * (number_of_level_values + 1)); levels[0] = missingValue; for (i = 0; i < number_of_level_values; i++) { diff --git a/src/grib_accessor_class_data_sh_packed.cc b/src/grib_accessor_class_data_sh_packed.cc index d5cdc5ccb..db2f63ce8 100644 --- a/src/grib_accessor_class_data_sh_packed.cc +++ b/src/grib_accessor_class_data_sh_packed.cc @@ -329,8 +329,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) lpos = 8 * (packed_offset - offsetdata); - s = grib_power(binary_scale_factor, 2); - d = grib_power(-decimal_scale_factor, 10); + s = codes_power(binary_scale_factor, 2); + d = codes_power(-decimal_scale_factor, 10); scals = (double*)grib_context_malloc(a->context, maxv * sizeof(double)); Assert(scals); diff --git a/src/grib_accessor_class_data_sh_unpacked.cc b/src/grib_accessor_class_data_sh_unpacked.cc index c0db2fa99..604c3947f 100644 --- a/src/grib_accessor_class_data_sh_unpacked.cc +++ b/src/grib_accessor_class_data_sh_unpacked.cc @@ -308,8 +308,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) lpos = 8 * (packed_offset - offsetdata); - s = grib_power(binary_scale_factor, 2); - d = grib_power(-decimal_scale_factor, 10); + s = codes_power(binary_scale_factor, 2); + d = codes_power(-decimal_scale_factor, 10); scals = (double*)grib_context_malloc(a->context, maxv * sizeof(double)); Assert(scals); diff --git a/src/grib_accessor_class_data_simple_packing.cc b/src/grib_accessor_class_data_simple_packing.cc index 2eaa5a96a..ba5d66131 100644 --- a/src/grib_accessor_class_data_simple_packing.cc +++ b/src/grib_accessor_class_data_simple_packing.cc @@ -236,8 +236,8 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val) } Assert(idx < n_vals); - s = grib_power(binary_scale_factor, 2); - d = grib_power(-decimal_scale_factor, 10); + s = codes_power(binary_scale_factor, 2); + d = codes_power(-decimal_scale_factor, 10); grib_context_log(a->context, GRIB_LOG_DEBUG, "%s: %s: creating %s, %ld values (idx=%zu)", @@ -369,8 +369,8 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return GRIB_SUCCESS; } - s = grib_power(binary_scale_factor, 2); - d = grib_power(-decimal_scale_factor, 10); + s = codes_power(binary_scale_factor, 2); + d = codes_power(-decimal_scale_factor, 10); grib_context_log(a->context, GRIB_LOG_DEBUG, "%s %s: Creating %s, %zu values", cclass_name, __func__, a->name, n_vals); @@ -507,8 +507,8 @@ static int _unpack_double(grib_accessor* a, double* val, size_t* len, unsigned c return GRIB_SUCCESS; } - s = grib_power(binary_scale_factor, 2); - d = grib_power(-decimal_scale_factor, 10); + s = codes_power(binary_scale_factor, 2); + d = codes_power(-decimal_scale_factor, 10); grib_context_log(a->context, GRIB_LOG_DEBUG, "%s %s: Creating %s, %zu values", cclass_name, __func__, a->name, n_vals); @@ -744,7 +744,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) /* decimal_scale_factor is given, binary_scale_factor=0 and bits_per_value is computed */ binary_scale_factor = 0; decimal_scale_factor = decimal_scale_factor_get; - decimal = grib_power(decimal_scale_factor, 10); + decimal = codes_power(decimal_scale_factor, 10); min *= decimal; max *= decimal; @@ -790,14 +790,14 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) return err; } else { - /* printf("max=%g reference_value=%g grib_power(-last,2)=%g decimal_scale_factor=%ld bits_per_value=%ld\n", - max,reference_value,grib_power(-last,2),decimal_scale_factor,bits_per_value);*/ + /* printf("max=%g reference_value=%g codes_power(-last,2)=%g decimal_scale_factor=%ld bits_per_value=%ld\n", + max,reference_value,codes_power(-last,2),decimal_scale_factor,bits_per_value);*/ range = (max - min); unscaled_min = min; unscaled_max = max; - f = (grib_power(bits_per_value, 2) - 1); - minrange = grib_power(-last, 2) * f; - maxrange = grib_power(last, 2) * f; + f = (codes_power(bits_per_value, 2) - 1); + minrange = codes_power(-last, 2) * f; + maxrange = codes_power(last, 2) * f; while (range < minrange) { decimal_scale_factor += 1; diff --git a/src/grib_accessor_class_expanded_descriptors.cc b/src/grib_accessor_class_expanded_descriptors.cc index 61e961396..b9fd65e3b 100644 --- a/src/grib_accessor_class_expanded_descriptors.cc +++ b/src/grib_accessor_class_expanded_descriptors.cc @@ -484,7 +484,7 @@ static void __expand(grib_accessor* a, bufr_descriptors_array* unexpanded, bufr_ case 7: if (us->Y) { ccp->extraScale = us->Y; - ccp->referenceFactor = grib_power(us->Y, 10); + ccp->referenceFactor = codes_power(us->Y, 10); ccp->extraWidth = ((10 * us->Y) + 2) / 3; } else { diff --git a/src/grib_accessor_class_second_order_bits_per_value.cc b/src/grib_accessor_class_second_order_bits_per_value.cc index 00d8f9958..5eb4cc27a 100644 --- a/src/grib_accessor_class_second_order_bits_per_value.cc +++ b/src/grib_accessor_class_second_order_bits_per_value.cc @@ -226,8 +226,8 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) min = values[i]; } - d = grib_power(decimalScaleFactor, 10); - b = grib_power(-binaryScaleFactor, 2); + d = codes_power(decimalScaleFactor, 10); + b = codes_power(-binaryScaleFactor, 2); /* self->bitsPerValue=(long)ceil(log((double)((max-min)*d+1))/log(2.0))-binaryScaleFactor; */ /* See GRIB-540 for why we use ceil */ diff --git a/src/grib_accessor_class_simple_packing_error.cc b/src/grib_accessor_class_simple_packing_error.cc index 50ea5be57..9118b4e59 100644 --- a/src/grib_accessor_class_simple_packing_error.cc +++ b/src/grib_accessor_class_simple_packing_error.cc @@ -167,7 +167,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) Assert(1 == 0); if (bitsPerValue != 0) - *val = (*val + grib_power(binaryScaleFactor, 2)) * grib_power(-decimalScaleFactor, 10) * 0.5; + *val = (*val + codes_power(binaryScaleFactor, 2)) * codes_power(-decimalScaleFactor, 10) * 0.5; if (ret == GRIB_SUCCESS) *len = 1; diff --git a/src/grib_bits_any_endian.cc b/src/grib_bits_any_endian.cc index 5fd706d9f..45992f26a 100644 --- a/src/grib_bits_any_endian.cc +++ b/src/grib_bits_any_endian.cc @@ -392,7 +392,7 @@ int grib_encode_unsigned_longb(unsigned char* p, unsigned long val, long* bitp, } #ifdef DEBUG { - unsigned long maxV = grib_power(nb, 2); + unsigned long maxV = codes_power(nb, 2); if (val > maxV) { fprintf(stderr, "grib_encode_unsigned_longb: Value=%lu, but number of bits=%ld!\n", val, nb); Assert(0); @@ -421,7 +421,7 @@ int grib_encode_size_tb(unsigned char* p, size_t val, long* bitp, long nb) } #ifdef DEBUG { - size_t maxV = grib_power(nb, 2); + size_t maxV = codes_power(nb, 2); if (val > maxV) { fprintf(stderr, "grib_encode_size_tb: Value=%lu, but number of bits=%ld!\n", val, nb); Assert(0); diff --git a/src/grib_bufr_descriptor.cc b/src/grib_bufr_descriptor.cc index 9d8516103..68aa7e290 100644 --- a/src/grib_bufr_descriptor.cc +++ b/src/grib_bufr_descriptor.cc @@ -110,7 +110,7 @@ void grib_bufr_descriptor_set_scale(bufr_descriptor* v, long scale) v->scale = scale; if (scale != 0) v->type = BUFR_DESCRIPTOR_TYPE_DOUBLE; - v->factor = grib_power(-scale, 10); + v->factor = codes_power(-scale, 10); } int grib_bufr_descriptor_can_be_missing(bufr_descriptor* v) diff --git a/src/grib_header_compute.cc b/src/grib_header_compute.cc index 45323fb1c..fab399e43 100644 --- a/src/grib_header_compute.cc +++ b/src/grib_header_compute.cc @@ -48,7 +48,7 @@ static long op_neg(long a) {return -a;} static double op_neg_d(double a) {return -a;} -static long op_pow(long a, long b) {return grib_power(a,b);} +static long op_pow(long a, long b) {return codes_power(a,b);} static long op_add(long a, long b) {return a+b;} static long op_sub(long a, long b) {return a-b;} static long op_div(long a, long b) {return a/b;} diff --git a/src/grib_optimize_decimal_factor.cc b/src/grib_optimize_decimal_factor.cc index 2e31e2c23..342bb974a 100644 --- a/src/grib_optimize_decimal_factor.cc +++ b/src/grib_optimize_decimal_factor.cc @@ -51,9 +51,9 @@ static void factec(int* krep, const double pa, const int knbit, const long kdec, } /* Binary scale factor associated to kdec */ - *ke = floor(log2((pa * grib_power(kdec, 10)) / (grib_power(knbit, 2) - 0.5))) + 1; + *ke = floor(log2((pa * codes_power(kdec, 10)) / (codes_power(knbit, 2) - 0.5))) + 1; /* Encoded value for pa = max - min */ - *knutil = floor(0.5 + pa * grib_power(kdec, 10) * grib_power(-*ke, 2)); + *knutil = floor(0.5 + pa * codes_power(kdec, 10) * codes_power(-*ke, 2)); end: return; @@ -99,14 +99,14 @@ int grib_optimize_decimal_factor(grib_accessor* a, const char* reference_value, xtinyr4 = FLT_MIN; xhuger4 = FLT_MAX; - inbint = grib_power(knbit, 2) - 1; + inbint = codes_power(knbit, 2) - 1; xnbint = (double)inbint; /* Test decimal scale factors; keep the most suitable */ for (jdec = idecmin; jdec <= idecmax; jdec++) { /* Fix a problem in GRIBEX */ if (compat_gribex) - if (pa * grib_power(jdec, 10) <= 1.E-12) + if (pa * codes_power(jdec, 10) <= 1.E-12) continue; /* Check it will be possible to decode reference value with 32bit floats */ @@ -126,7 +126,7 @@ int grib_optimize_decimal_factor(grib_accessor* a, const char* reference_value, /* Check it will be possible to decode the maximum value of the fields using 32bit floats */ if (compat_32bit) - if (pmin * grib_power(jdec, 10) + xnbint * grib_power(ie, 2) >= xhuger4) + if (pmin * codes_power(jdec, 10) + xnbint * codes_power(ie, 2) >= xhuger4) continue; /* GRIB1 demands that the binary scale factor be encoded in a single byte */ @@ -142,8 +142,8 @@ int grib_optimize_decimal_factor(grib_accessor* a, const char* reference_value, } if (inumax > 0) { - double decimal = grib_power(+*kdec, 10); - double divisor = grib_power(-*kbin, 2); + double decimal = codes_power(+*kdec, 10); + double divisor = codes_power(-*kbin, 2); double min = pmin * decimal; long vmin, vmax; if (grib_get_nearest_smaller_value(gh, reference_value, min, ref) != GRIB_SUCCESS) { @@ -165,9 +165,9 @@ int grib_optimize_decimal_factor(grib_accessor* a, const char* reference_value, int last = compat_gribex ? 99 : 127; double min = pmin, max = pmax; double range = max - min; - double f = grib_power(knbit, 2) - 1; - double minrange = grib_power(-last, 2) * f; - double maxrange = grib_power(+last, 2) * f; + double f = codes_power(knbit, 2) - 1; + double minrange = codes_power(-last, 2) * f; + double maxrange = codes_power(+last, 2) * f; double decimal = 1; int err; diff --git a/src/grib_scaling.cc b/src/grib_scaling.cc index e31e4cfb8..29143395d 100644 --- a/src/grib_scaling.cc +++ b/src/grib_scaling.cc @@ -15,6 +15,12 @@ #include "grib_scaling.h" #include "grib_api_internal.h" +// Unfortunately, metkit uses grib_power() (illegal usage of private API) +// As soon as it is fixed, the wrapper below can be deleted +double grib_power(long s, long n) { + codes_power(s, n); +} + long grib_get_binary_scale_fact(double max, double min, long bpval, int* ret) { double range = max - min; @@ -25,14 +31,14 @@ long grib_get_binary_scale_fact(double max, double min, long bpval, int* ret) const size_t ulong_size = sizeof(maxint) * 8; /* See ECC-246 - unsigned long maxint = grib_power(bpval,2) - 1; + unsigned long maxint = codes_power(bpval,2) - 1; double dmaxint=(double)maxint; */ if (bpval >= ulong_size) { *ret = GRIB_OUT_OF_RANGE; /*overflow*/ return 0; } - const double dmaxint = grib_power(bpval, 2) - 1; + const double dmaxint = codes_power(bpval, 2) - 1; maxint = (unsigned long)dmaxint; /* Now it's safe to cast */ *ret = 0; @@ -83,7 +89,7 @@ long grib_get_bits_per_value(double max, double min, long binary_scale_factor) long scale = 0; const long last = 127; /* Depends on edition, should be parameter */ - unsigned long maxint = grib_power(binary_scale_factor, 2) - 1; + unsigned long maxint = codes_power(binary_scale_factor, 2) - 1; double dmaxint = (double)maxint; if (maxint == 0) @@ -127,10 +133,10 @@ long grib_get_decimal_scale_fact(double max, double min, long bpval, long binary long scale = 0; const long last = 127; /* Depends on edition, should be parameter */ - unsigned long maxint = grib_power(bpval, 2) - 1; + unsigned long maxint = codes_power(bpval, 2) - 1; double dmaxint = (double)maxint; - range *= grib_power(-binary_scale, 2); + range *= codes_power(-binary_scale, 2); Assert(bpval >= 1); if (range == 0) diff --git a/src/grib_scaling.h b/src/grib_scaling.h index 4dbd8f6f1..53e3b1d4d 100644 --- a/src/grib_scaling.h +++ b/src/grib_scaling.h @@ -1,10 +1,10 @@ #pragma once -template T grib_power(long s, long n); +template T codes_power(long s, long n); /* Return n to the power of s */ template -T grib_power(long s, long n) +T codes_power(long s, long n) { T divisor = 1.0; if (s == 0) From f224e51136eef5a175e52573ad6fe32b28cb1c25 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 22 Jun 2023 15:36:04 +0100 Subject: [PATCH 11/12] Fix broken build --- src/grib_bits_any_endian.cc | 2 ++ src/grib_scaling.cc | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/grib_bits_any_endian.cc b/src/grib_bits_any_endian.cc index 45992f26a..5f01b4106 100644 --- a/src/grib_bits_any_endian.cc +++ b/src/grib_bits_any_endian.cc @@ -17,6 +17,8 @@ #include #endif +#include "grib_scaling.h" + #if GRIB_PTHREADS static pthread_once_t once = PTHREAD_ONCE_INIT; static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; diff --git a/src/grib_scaling.cc b/src/grib_scaling.cc index 29143395d..41e77e28e 100644 --- a/src/grib_scaling.cc +++ b/src/grib_scaling.cc @@ -18,7 +18,7 @@ // Unfortunately, metkit uses grib_power() (illegal usage of private API) // As soon as it is fixed, the wrapper below can be deleted double grib_power(long s, long n) { - codes_power(s, n); + return codes_power(s, n); } long grib_get_binary_scale_fact(double max, double min, long bpval, int* ret) From fbc16be5312ecc6ebbcae32de89f6320a04aa55e Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 22 Jun 2023 16:10:12 +0100 Subject: [PATCH 12/12] Fix broken Windows build --- src/grib_accessor_class_data_simple_packing.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/grib_accessor_class_data_simple_packing.cc b/src/grib_accessor_class_data_simple_packing.cc index ba5d66131..7ef410546 100644 --- a/src/grib_accessor_class_data_simple_packing.cc +++ b/src/grib_accessor_class_data_simple_packing.cc @@ -12,6 +12,7 @@ #include "grib_bits_any_endian_simple.h" #include "grib_optimize_decimal_factor.h" #include +#include /* This is used by make_class.pl