ECC-1467: Rename grid_power<>() to codes_power<>()

This commit is contained in:
Eugen Betke 2023-06-22 14:09:01 +00:00
parent 07f537a02c
commit 4cba81667f
30 changed files with 118 additions and 112 deletions

View File

@ -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);

View File

@ -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<double>(b, a);
return codes_power<double>(b, a);
}
long grib_op_add(long a, long b)

View File

@ -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<double>(bd->scale, 10);
inverseFactor = codes_power<double>(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<double>(localWidth, 2) - 1;
allone = codes_power<double>(localWidth, 2) - 1;
while (allone <= lval) {
localWidth++;
allone = grib_power<double>(localWidth, 2) - 1;
allone = codes_power<double>(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<double>(bd->width, 2);
bd->reference = -codes_power<double>(bd->width, 2);
bd->width++;
err = codec_element(c, self, iss, buffer, data, &pos, index, bd, elementIndex, dval, sval);

View File

@ -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<double>(-v->scale, 10);
v->factor = codes_power<double>(-v->scale, 10);
v->reference = atol_fast(list[6]);
v->width = atol(list[7]);

View File

@ -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<double>(binary_scale_factor, 2);
d = grib_power<double>(-decimal_scale_factor, 10);
s = codes_power<double>(binary_scale_factor, 2);
d = codes_power<double>(-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<double>(decimal_scale_factor, 10);
d = codes_power<double>(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<double>(-binary_scale_factor, 2);
divisor = codes_power<double>(-binary_scale_factor, 2);
for (i = 0; i < n_vals; i++)

View File

@ -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<double>(decimal_scale_factor, 10);
d = codes_power<double>(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<double>(bits_per_value, 2) - 1);
minrange = grib_power<double>(-last, 2) * f;
maxrange = grib_power<double>(last, 2) * f;
f = (codes_power<double>(bits_per_value, 2) - 1);
minrange = codes_power<double>(-last, 2) * f;
maxrange = codes_power<double>(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<double>(decimal_scale_factor, 10);
d = codes_power<double>(decimal_scale_factor, 10);
}
binary_scale_factor = grib_get_binary_scale_fact(max, reference_value, bits_per_value, &err);
divisor = grib_power<double>(-binary_scale_factor, 2);
divisor = codes_power<double>(-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<T>(binary_scale_factor, 2);
dscale = grib_power<T>(-decimal_scale_factor, 10);
bscale = codes_power<T>(binary_scale_factor, 2);
dscale = codes_power<T>(-decimal_scale_factor, 10);
buflen = grib_byte_count(a);
buf = (unsigned char*)hand->buffer->data;

View File

@ -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<double>(decimal_scale_factor, 10);
d = codes_power<double>(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<double>(+decimal_scale_factor, 10);
d = codes_power<double>(+decimal_scale_factor, 10);
}
else {
d = grib_power<double>(+decimal_scale_factor, 10);
d = codes_power<double>(+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<double>(-binary_scale_factor, 2);
s = codes_power<double>(-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<T>(-decimal_scale_factor, 10);
d = codes_power<T>(-decimal_scale_factor, 10);
grib_ieee_decode_array<T>(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<T>(binary_scale_factor, 2);
d = grib_power<T>(-decimal_scale_factor, 10);
s = codes_power<T>(binary_scale_factor, 2);
d = codes_power<T>(-decimal_scale_factor, 10);
scals = (T*)grib_context_malloc(a->context, maxv * sizeof(T));
if (!scals) return GRIB_OUT_OF_MEMORY;

View File

@ -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<double>(binary_scale_factor, 2);
d = grib_power<double>(-decimal_scale_factor, 10);
s = codes_power<double>(binary_scale_factor, 2);
d = codes_power<double>(-decimal_scale_factor, 10);
for (i = 0; i < numberOfSecondOrderPackedValues; i++) {
values[i] = (double)(((X[i] * s) + reference_value) * d);
}

View File

@ -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<double>(binary_scale_factor, 2);
double d = grib_power<double>(-decimal_scale_factor, 10);
double s = codes_power<double>(binary_scale_factor, 2);
double d = codes_power<double>(-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<float>(binary_scale_factor, 2);
float d = grib_power<float>(-decimal_scale_factor, 10);
float s = codes_power<float>(binary_scale_factor, 2);
float d = codes_power<float>(-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<double>(decimal_scale_factor,10);
decimal = codes_power<double>(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<double>(-binary_scale_factor,2);
divisor = codes_power<double>(-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<double>(groupWidthA,2)-1;
range=(long)codes_power<double>(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<double>(groupWidthA,2)-1;
range=(long)codes_power<double>(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<double>(groupWidthA,2)-1;
range=(long)codes_power<double>(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<double>(widthOfFirstOrderValues,2)-1;
firstOrderValuesMax=(long)codes_power<double>(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<double>(groupWidth,2)-1;
range=(long)codes_power<double>(groupWidth,2)-1;
/* width of first order values has to be unchanged.*/
for (j=groupWidth;j<groupWidths[i];j++) {
@ -1392,8 +1392,8 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
&decimal_scale_factor, &binary_scale_factor, &reference_value)) != GRIB_SUCCESS)
return ret;
decimal = grib_power<double>(decimal_scale_factor, 10);
divisor = grib_power<double>(-binary_scale_factor, 2);
decimal = codes_power<double>(decimal_scale_factor, 10);
divisor = codes_power<double>(-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<double>(decimal_scale_factor, 10);
decimal = codes_power<double>(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<double>(-binary_scale_factor, 2);
divisor = codes_power<double>(-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<double>(groupWidthA, 2) - 1;
range = (long)codes_power<double>(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<double>(groupWidthA,2)-1;
range=(long)codes_power<double>(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<double>(groupWidthA,2)-1;
range=(long)codes_power<double>(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<double>(widthOfFirstOrderValues, 2) - 1;
firstOrderValuesMax = (long)codes_power<double>(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<double>(groupWidth, 2) - 1;
range = (long)codes_power<double>(groupWidth, 2) - 1;
/* width of first order values has to be unchanged.*/
for (j = groupWidth; j < groupWidths[i]; j++) {

View File

@ -288,8 +288,8 @@ static int unpack(grib_accessor* a, T* values, size_t* len)
}
}
s = grib_power<T>(binary_scale_factor, 2);
d = grib_power<T>(-decimal_scale_factor, 10);
s = codes_power<T>(binary_scale_factor, 2);
d = codes_power<T>(-decimal_scale_factor, 10);
for (i = 0; i < numberOfSecondOrderPackedValues; i++) {
values[i] = (T)(((X[i] * s) + reference_value) * d);
}

View File

@ -412,8 +412,8 @@ static int unpack(grib_accessor* a, T* values, size_t* len)
k++;
}
s = grib_power<T>(binary_scale_factor, 2);
d = grib_power<T>(-decimal_scale_factor, 10);
s = codes_power<T>(binary_scale_factor, 2);
d = codes_power<T>(-decimal_scale_factor, 10);
for (i = 0; i < n; i++) {
values[i] = (T)(((X[i] * s) + reference_value) * d);
}

View File

@ -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<double>(decimal_scale_factor, 10);
divisor = grib_power<double>(-binary_scale_factor, 2);
decimal = codes_power<double>(decimal_scale_factor, 10);
divisor = codes_power<double>(-binary_scale_factor, 2);
buflen = (((bits_per_value * n_vals) + 7) / 8) * sizeof(unsigned char);
if ((buflen + (offsetdata - offsetsection)) % 2) {

View File

@ -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<T>(binary_scale_factor, 2);
decimal_s = (T)grib_power<T>(-decimal_scale_factor, 10);
binary_s = (T)codes_power<T>(binary_scale_factor, 2);
decimal_s = (T)codes_power<T>(-decimal_scale_factor, 10);
for (i = 0; i < n_vals; i++) {
if (sec_val[i] == LONG_MAX) {

View File

@ -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<double>(bt->binary_scale_factor, 2);
d = grib_power<double>(-bt->decimal_scale_factor, 10);
s = codes_power<double>(bt->binary_scale_factor, 2);
d = codes_power<double>(-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<double>(-bt->binary_scale_factor, 2);
d = grib_power<double>(+bt->decimal_scale_factor, 10);
s = codes_power<double>(-bt->binary_scale_factor, 2);
d = codes_power<double>(+bt->decimal_scale_factor, 10);
}
else {
bt->decimal_scale_factor = 0;

View File

@ -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<double>(decimal_scale_factor, 10);
divisor = grib_power<double>(-binary_scale_factor, 2);
decimal = codes_power<double>(decimal_scale_factor, 10);
divisor = codes_power<double>(-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);

View File

@ -272,8 +272,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
self->dirty = 0;
bscale = grib_power<double>(binary_scale_factor, 2);
dscale = grib_power<double>(-decimal_scale_factor, 10);
bscale = codes_power<double>(binary_scale_factor, 2);
dscale = codes_power<double>(-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<double>(decimal_scale_factor, 10);
divisor = grib_power<double>(-binary_scale_factor, 2);
decimal = codes_power<double>(decimal_scale_factor, 10);
divisor = codes_power<double>(-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);

View File

@ -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<double>(binary_scale_factor, 2);
dscale = grib_power<double>(-decimal_scale_factor, 10);
bscale = codes_power<double>(binary_scale_factor, 2);
dscale = codes_power<double>(-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<double>(decimal_scale_factor, 10);
d = codes_power<double>(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<double>(-binary_scale_factor, 2);
divisor = codes_power<double>(-binary_scale_factor, 2);
#ifndef PNG_ANYBITS
Assert(bits_per_value % 8 == 0);

View File

@ -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<double>(-decimal_scale_factor, 10.0);
level_scale_factor = codes_power<double>(-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++) {

View File

@ -329,8 +329,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
lpos = 8 * (packed_offset - offsetdata);
s = grib_power<double>(binary_scale_factor, 2);
d = grib_power<double>(-decimal_scale_factor, 10);
s = codes_power<double>(binary_scale_factor, 2);
d = codes_power<double>(-decimal_scale_factor, 10);
scals = (double*)grib_context_malloc(a->context, maxv * sizeof(double));
Assert(scals);

View File

@ -308,8 +308,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
lpos = 8 * (packed_offset - offsetdata);
s = grib_power<double>(binary_scale_factor, 2);
d = grib_power<double>(-decimal_scale_factor, 10);
s = codes_power<double>(binary_scale_factor, 2);
d = codes_power<double>(-decimal_scale_factor, 10);
scals = (double*)grib_context_malloc(a->context, maxv * sizeof(double));
Assert(scals);

View File

@ -236,8 +236,8 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val)
}
Assert(idx < n_vals);
s = grib_power<double>(binary_scale_factor, 2);
d = grib_power<double>(-decimal_scale_factor, 10);
s = codes_power<double>(binary_scale_factor, 2);
d = codes_power<double>(-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<T>(binary_scale_factor, 2);
d = grib_power<T>(-decimal_scale_factor, 10);
s = codes_power<T>(binary_scale_factor, 2);
d = codes_power<T>(-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<double>(binary_scale_factor, 2);
d = grib_power<double>(-decimal_scale_factor, 10);
s = codes_power<double>(binary_scale_factor, 2);
d = codes_power<double>(-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<double>(decimal_scale_factor, 10);
decimal = codes_power<double>(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<double>(-last,2)=%g decimal_scale_factor=%ld bits_per_value=%ld\n",
max,reference_value,grib_power<double>(-last,2),decimal_scale_factor,bits_per_value);*/
/* printf("max=%g reference_value=%g codes_power<double>(-last,2)=%g decimal_scale_factor=%ld bits_per_value=%ld\n",
max,reference_value,codes_power<double>(-last,2),decimal_scale_factor,bits_per_value);*/
range = (max - min);
unscaled_min = min;
unscaled_max = max;
f = (grib_power<double>(bits_per_value, 2) - 1);
minrange = grib_power<double>(-last, 2) * f;
maxrange = grib_power<double>(last, 2) * f;
f = (codes_power<double>(bits_per_value, 2) - 1);
minrange = codes_power<double>(-last, 2) * f;
maxrange = codes_power<double>(last, 2) * f;
while (range < minrange) {
decimal_scale_factor += 1;

View File

@ -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<double>(us->Y, 10);
ccp->referenceFactor = codes_power<double>(us->Y, 10);
ccp->extraWidth = ((10 * us->Y) + 2) / 3;
}
else {

View File

@ -226,8 +226,8 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len)
min = values[i];
}
d = grib_power<double>(decimalScaleFactor, 10);
b = grib_power<double>(-binaryScaleFactor, 2);
d = codes_power<double>(decimalScaleFactor, 10);
b = codes_power<double>(-binaryScaleFactor, 2);
/* self->bitsPerValue=(long)ceil(log((double)((max-min)*d+1))/log(2.0))-binaryScaleFactor; */
/* See GRIB-540 for why we use ceil */

View File

@ -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<double>(binaryScaleFactor, 2)) * grib_power<double>(-decimalScaleFactor, 10) * 0.5;
*val = (*val + codes_power<double>(binaryScaleFactor, 2)) * codes_power<double>(-decimalScaleFactor, 10) * 0.5;
if (ret == GRIB_SUCCESS)
*len = 1;

View File

@ -392,7 +392,7 @@ int grib_encode_unsigned_longb(unsigned char* p, unsigned long val, long* bitp,
}
#ifdef DEBUG
{
unsigned long maxV = grib_power<double>(nb, 2);
unsigned long maxV = codes_power<double>(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<double>(nb, 2);
size_t maxV = codes_power<double>(nb, 2);
if (val > maxV) {
fprintf(stderr, "grib_encode_size_tb: Value=%lu, but number of bits=%ld!\n", val, nb);
Assert(0);

View File

@ -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<double>(-scale, 10);
v->factor = codes_power<double>(-scale, 10);
}
int grib_bufr_descriptor_can_be_missing(bufr_descriptor* v)

View File

@ -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<double>(a,b);}
static long op_pow(long a, long b) {return codes_power<double>(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;}

View File

@ -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<double>(kdec, 10)) / (grib_power<double>(knbit, 2) - 0.5))) + 1;
*ke = floor(log2((pa * codes_power<double>(kdec, 10)) / (codes_power<double>(knbit, 2) - 0.5))) + 1;
/* Encoded value for pa = max - min */
*knutil = floor(0.5 + pa * grib_power<double>(kdec, 10) * grib_power<double>(-*ke, 2));
*knutil = floor(0.5 + pa * codes_power<double>(kdec, 10) * codes_power<double>(-*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<double>(knbit, 2) - 1;
inbint = codes_power<double>(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<double>(jdec, 10) <= 1.E-12)
if (pa * codes_power<double>(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<double>(jdec, 10) + xnbint * grib_power<double>(ie, 2) >= xhuger4)
if (pmin * codes_power<double>(jdec, 10) + xnbint * codes_power<double>(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<double>(+*kdec, 10);
double divisor = grib_power<double>(-*kbin, 2);
double decimal = codes_power<double>(+*kdec, 10);
double divisor = codes_power<double>(-*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<double>(knbit, 2) - 1;
double minrange = grib_power<double>(-last, 2) * f;
double maxrange = grib_power<double>(+last, 2) * f;
double f = codes_power<double>(knbit, 2) - 1;
double minrange = codes_power<double>(-last, 2) * f;
double maxrange = codes_power<double>(+last, 2) * f;
double decimal = 1;
int err;

View File

@ -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<double>(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<double>(bpval,2) - 1;
unsigned long maxint = codes_power<double>(bpval,2) - 1;
double dmaxint=(double)maxint;
*/
if (bpval >= ulong_size) {
*ret = GRIB_OUT_OF_RANGE; /*overflow*/
return 0;
}
const double dmaxint = grib_power<double>(bpval, 2) - 1;
const double dmaxint = codes_power<double>(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<double>(binary_scale_factor, 2) - 1;
unsigned long maxint = codes_power<double>(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<double>(bpval, 2) - 1;
unsigned long maxint = codes_power<double>(bpval, 2) - 1;
double dmaxint = (double)maxint;
range *= grib_power<double>(-binary_scale, 2);
range *= codes_power<double>(-binary_scale, 2);
Assert(bpval >= 1);
if (range == 0)

View File

@ -1,10 +1,10 @@
#pragma once
template <typename T> T grib_power(long s, long n);
template <typename T> T codes_power(long s, long n);
/* Return n to the power of s */
template <typename T>
T grib_power(long s, long n)
T codes_power(long s, long n)
{
T divisor = 1.0;
if (s == 0)