mirror of https://github.com/ecmwf/eccodes.git
ECC-1286: GRIB: Cannot set keys 'scaleFactorOfLowerLimit' and 'scaledValueOfLowerLimit' via the 'lowerLimit' key
This commit is contained in:
parent
4ecc87ee02
commit
854a8c178d
|
@ -189,6 +189,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
|
||||||
int64_t value = 0, prev_value = 0;
|
int64_t value = 0, prev_value = 0;
|
||||||
double exact = *val; /*the input*/
|
double exact = *val; /*the input*/
|
||||||
const float epsilon = float_epsilon();
|
const float epsilon = float_epsilon();
|
||||||
|
int is_negative = 0;
|
||||||
unsigned long maxval_value, maxval_factor; /*maximum allowable values*/
|
unsigned long maxval_value, maxval_factor; /*maximum allowable values*/
|
||||||
grib_accessor *accessor_factor, *accessor_value;
|
grib_accessor *accessor_factor, *accessor_value;
|
||||||
|
|
||||||
|
@ -217,9 +218,11 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
|
||||||
maxval_value = (1UL << (accessor_value->length * 8)) - 2; /* exclude missing */
|
maxval_value = (1UL << (accessor_value->length * 8)) - 2; /* exclude missing */
|
||||||
maxval_factor = (1UL << (accessor_factor->length * 8)) - 2; /* exclude missing */
|
maxval_factor = (1UL << (accessor_factor->length * 8)) - 2; /* exclude missing */
|
||||||
|
|
||||||
Assert(exact > 0);
|
|
||||||
|
|
||||||
/* Loop until we find a close enough approximation. Keep the last good values */
|
/* Loop until we find a close enough approximation. Keep the last good values */
|
||||||
|
if (exact < 0) {
|
||||||
|
is_negative = 1;
|
||||||
|
exact *= -1;
|
||||||
|
}
|
||||||
factor = prev_factor = 0;
|
factor = prev_factor = 0;
|
||||||
value = prev_value = round(exact);
|
value = prev_value = round(exact);
|
||||||
while (!is_approximately_equal(exact, eval_value_factor(value, factor), epsilon) &&
|
while (!is_approximately_equal(exact, eval_value_factor(value, factor), epsilon) &&
|
||||||
|
@ -236,6 +239,10 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
|
||||||
prev_value = value;
|
prev_value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_negative) {
|
||||||
|
value *= -1;
|
||||||
|
}
|
||||||
|
|
||||||
if ((ret = grib_set_long_internal(hand, self->scaleFactor, factor)) != GRIB_SUCCESS)
|
if ((ret = grib_set_long_internal(hand, self->scaleFactor, factor)) != GRIB_SUCCESS)
|
||||||
return ret;
|
return ret;
|
||||||
if ((ret = grib_set_long_internal(hand, self->scaledValue, value)) != GRIB_SUCCESS)
|
if ((ret = grib_set_long_internal(hand, self->scaledValue, value)) != GRIB_SUCCESS)
|
||||||
|
|
|
@ -13,6 +13,7 @@ set -u
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
# This is the test for the JIRA issue ECC-1150
|
# This is the test for the JIRA issue ECC-1150
|
||||||
# ECC-1150: keys 'lowerLimit' & 'upperLimit' cannot be MISSING
|
# ECC-1150: keys 'lowerLimit' & 'upperLimit' cannot be MISSING
|
||||||
|
# See also ECC-1286
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
label="grib_ecc-1150-test"
|
label="grib_ecc-1150-test"
|
||||||
tempGrib=temp.${label}.grib
|
tempGrib=temp.${label}.grib
|
||||||
|
@ -60,12 +61,19 @@ ${tools_dir}/grib_filter $tempFilt $tempGrib
|
||||||
# Encoding
|
# Encoding
|
||||||
# ----------
|
# ----------
|
||||||
temp2=temp2.${label}.grib
|
temp2=temp2.${label}.grib
|
||||||
${tools_dir}/grib_set -s upperLimit=missing,lowerLimit=missing $tempGrib $temp2
|
${tools_dir}/grib_set -s lowerLimit=missing,upperLimit=missing $tempGrib $temp2
|
||||||
grib_check_key_equals $temp2 lowerLimit,upperLimit 'MISSING MISSING'
|
grib_check_key_equals $temp2 lowerLimit,upperLimit 'MISSING MISSING'
|
||||||
grib_check_key_equals $temp2 \
|
grib_check_key_equals $temp2 \
|
||||||
scaleFactorOfLowerLimit,scaledValueOfLowerLimit,scaleFactorOfUpperLimit,scaledValueOfUpperLimit \
|
scaleFactorOfLowerLimit,scaledValueOfLowerLimit,scaleFactorOfUpperLimit,scaledValueOfUpperLimit \
|
||||||
'MISSING MISSING MISSING MISSING'
|
'MISSING MISSING MISSING MISSING'
|
||||||
rm -f $temp2
|
|
||||||
|
${tools_dir}/grib_set -s lowerLimit=3.14,upperLimit=missing $tempGrib $temp2
|
||||||
|
grib_check_key_equals $temp2 lowerLimit,upperLimit '3.14 MISSING'
|
||||||
|
|
||||||
|
# Negative values
|
||||||
|
${tools_dir}/grib_set -s lowerLimit=-6.6,upperLimit=-1.02 $tempGrib $temp2
|
||||||
|
grib_check_key_equals $temp2 scaleFactorOfLowerLimit,scaledValueOfLowerLimit,lowerLimit "1 -66 -6.6"
|
||||||
|
grib_check_key_equals $temp2 scaleFactorOfUpperLimit,scaledValueOfUpperLimit,upperLimit "2 -102 -1.02"
|
||||||
|
|
||||||
# Clean up
|
# Clean up
|
||||||
rm -f $tempGrib $tempFilt
|
rm -f $tempGrib $tempFilt $temp2
|
||||||
|
|
Loading…
Reference in New Issue