mirror of https://github.com/ecmwf/eccodes.git
ECC-1560: Cleanup and add further tests
This commit is contained in:
parent
af5d091a08
commit
87327b6bfb
|
@ -251,18 +251,16 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len)
|
|||
static int pack_double(grib_accessor* a, const double* val, size_t* len)
|
||||
{
|
||||
grib_accessor_g2level* self = (grib_accessor_g2level*)a;
|
||||
grib_handle* hand = grib_handle_of_accessor(a);
|
||||
int ret = 0;
|
||||
double value_first = *val;
|
||||
long scale_first = 0;
|
||||
long type_first = 0;
|
||||
char pressure_units[10] = {0,};
|
||||
size_t pressure_units_len = 10;
|
||||
long lval = (long)value_first;
|
||||
grib_handle* hand = grib_handle_of_accessor(a);
|
||||
int ret = 0;
|
||||
double value_first = *val;
|
||||
//long scale_first = 0;
|
||||
long type_first = 0;
|
||||
char pressure_units[10] = {0,};
|
||||
size_t pressure_units_len = 10;
|
||||
const long lval = (long)value_first;
|
||||
|
||||
//printf("pack_double:: received %g\n", *val);
|
||||
if (value_first == lval) {
|
||||
//printf(" .... use pack_long for %g\n", value_first);
|
||||
if (value_first == lval) { // input is a whole number; process it as an integer
|
||||
return pack_long(a, &lval, len);
|
||||
}
|
||||
|
||||
|
@ -284,20 +282,29 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
|
|||
default:
|
||||
break;
|
||||
}
|
||||
//
|
||||
|
||||
// final = scaled_value * 10 ^ -scale_factor
|
||||
// = scaled_value / (10^scale_factor)
|
||||
//
|
||||
// Choose 2 decimal places
|
||||
//
|
||||
scale_first = 2;
|
||||
value_first *= 100;
|
||||
value_first = value_first + 0.5; /* round up */
|
||||
|
||||
//scale_first = 2;
|
||||
//value_first *= 100;
|
||||
//value_first = value_first + 0.5; //round up
|
||||
|
||||
// TODO(masn): These maxima should come from the respective accessors
|
||||
const int64_t scaled_value_max = (1UL << 32) - 1; // scaledValueOf*FixedSurface is 4 octets
|
||||
const int64_t scale_factor_max = (1UL << 8) - 1; // scaleFactorOf*FixedSurface is 1 octet
|
||||
int64_t lscaled_value=0, lscale_factor=0;
|
||||
|
||||
ret = compute_scaled_value_and_scale_factor(value_first, scaled_value_max, scale_factor_max, &lscaled_value, &lscale_factor);
|
||||
if (ret) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "Accessor %s: Failed to compute %s and %s from %g",
|
||||
a->name, self->scale_first, self->value_first, value_first);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (type_first > 9) {
|
||||
if ((ret = grib_set_long_internal(hand, self->scale_first, scale_first)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_set_long_internal(hand, self->scale_first, (long)lscale_factor)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
if ((ret = grib_set_long_internal(hand, self->value_first, (long)value_first)) != GRIB_SUCCESS)
|
||||
if ((ret = grib_set_long_internal(hand, self->value_first, (long)lscaled_value)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -163,14 +163,12 @@ int grib_init_accessor_from_handle(grib_loader* loader, grib_accessor* ga, grib_
|
|||
}
|
||||
|
||||
long ga_type = grib_accessor_get_native_type(ga);
|
||||
if (STR_EQUAL(name,"level")) {
|
||||
//printf("..... loader_from_file: switch type to DOUBLE\n");
|
||||
if (STR_EQUAL(name,"level")) { // See ECC-1560
|
||||
ga_type = GRIB_TYPE_DOUBLE;
|
||||
}
|
||||
|
||||
switch (ga_type) {
|
||||
case GRIB_TYPE_STRING:
|
||||
|
||||
/*ecc__grib_get_string_length(ga,&len); See ECC-490 */
|
||||
grib_get_string_length(h, name, &len);
|
||||
sval = (char*)grib_context_malloc(h->context, len);
|
||||
|
|
|
@ -27,9 +27,11 @@ grib_check_key_equals $temp_PDTN08_Grib level:d 1.5
|
|||
# Now we change to PDTN 11
|
||||
${tools_dir}/grib_set -s productDefinitionTemplateNumber=11 $temp_PDTN08_Grib $temp_PDTN11_Grib
|
||||
grib_check_key_equals $temp_PDTN11_Grib level:d 1.5
|
||||
grib_check_key_equals $temp_PDTN11_Grib scaledValueOfFirstFixedSurface 15
|
||||
grib_check_key_equals $temp_PDTN11_Grib scaleFactorOfFirstFixedSurface 1
|
||||
|
||||
|
||||
# Set integer value using the int/double encoding
|
||||
# Set whole value using the int/double encoding
|
||||
# -----------------------------------------------
|
||||
${tools_dir}/grib_set -s typeOfFirstFixedSurface=105,level:i=34 $sample_grib2 $tempGrib
|
||||
grib_check_key_equals $tempGrib scaleFactorOfFirstFixedSurface 0
|
||||
|
@ -39,6 +41,10 @@ ${tools_dir}/grib_set -s typeOfFirstFixedSurface=105,level:d=34 $sample_grib2 $t
|
|||
grib_check_key_equals $tempGrib scaleFactorOfFirstFixedSurface 0
|
||||
grib_check_key_equals $tempGrib scaledValueOfFirstFixedSurface 34
|
||||
|
||||
${tools_dir}/grib_set -s typeOfFirstFixedSurface=105,level:d=3.456 $sample_grib2 $tempGrib
|
||||
grib_check_key_equals $tempGrib scaleFactorOfFirstFixedSurface 3
|
||||
grib_check_key_equals $tempGrib scaledValueOfFirstFixedSurface 3456
|
||||
|
||||
|
||||
# Clean up
|
||||
rm -f $temp_PDTN08_Grib $temp_PDTN11_Grib $tempGrib
|
||||
|
|
|
@ -64,13 +64,13 @@ diff temp.level.good test.dump
|
|||
${tools_dir}/grib_set -s typeOfFirstFixedSurface=103,level=24 $sample_g2 $temp
|
||||
grib_check_key_equals $temp level,scaledValueOfFirstFixedSurface,scaleFactorOfFirstFixedSurface '24 24 0'
|
||||
${tools_dir}/grib_set -s typeOfFirstFixedSurface=103,level=2.4 $sample_g2 $temp
|
||||
grib_check_key_equals $temp level:d,scaledValueOfFirstFixedSurface,scaleFactorOfFirstFixedSurface '2.4 240 2'
|
||||
grib_check_key_equals $temp level:d,scaledValueOfFirstFixedSurface,scaleFactorOfFirstFixedSurface '2.4 24 1'
|
||||
|
||||
# Use a parameter which has two levels
|
||||
${tools_dir}/grib_set -s paramId=228086,topLevel=1.3,bottomLevel=5.4 $sample_g2 $temp
|
||||
grib_check_key_equals $temp 'topLevel:d,bottomLevel:d' '1.3 5.4'
|
||||
grib_check_key_equals $temp scaleFactorOfFirstFixedSurface,scaledValueOfFirstFixedSurface '2 130'
|
||||
grib_check_key_equals $temp scaleFactorOfSecondFixedSurface,scaledValueOfSecondFixedSurface '2 540'
|
||||
grib_check_key_equals $temp scaleFactorOfFirstFixedSurface,scaledValueOfFirstFixedSurface '1 13'
|
||||
grib_check_key_equals $temp scaleFactorOfSecondFixedSurface,scaledValueOfSecondFixedSurface '1 54'
|
||||
|
||||
# GRIB-492
|
||||
${tools_dir}/grib_set -s indicatorOfTypeOfLevel=110 $sample_g1 $temp
|
||||
|
|
Loading…
Reference in New Issue