mirror of https://github.com/ecmwf/eccodes.git
ECC-1219: packingType conversion from grid_ieee to grid_second_order
This commit is contained in:
parent
861cfc3913
commit
ee4921b909
|
@ -1237,6 +1237,22 @@ static int pack_double_old(grib_accessor* a, const double* val, size_t *len)
|
|||
}
|
||||
#endif
|
||||
|
||||
static int get_bits_per_value(grib_handle* h, const char* bits_per_value_str, long* bits_per_value)
|
||||
{
|
||||
int err = 0;
|
||||
if ((err = grib_get_long_internal(h, bits_per_value_str, bits_per_value)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if (*bits_per_value == 0) {
|
||||
/* Probably grid_ieee input which is a special case. Note: we cannot check the packingType
|
||||
* because it has already been changed to second order!
|
||||
* We have to take precision=1 for IEEE which is 32bits
|
||||
*/
|
||||
*bits_per_value = 32;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
static int pack_double(grib_accessor* a, const double* val, size_t* len)
|
||||
{
|
||||
grib_accessor_data_g1second_order_general_extended_packing* self = (grib_accessor_data_g1second_order_general_extended_packing*)a;
|
||||
|
@ -1294,7 +1310,8 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
|
|||
min = val[i];
|
||||
}
|
||||
|
||||
if ((ret = grib_get_long_internal(handle, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS)
|
||||
/* ECC-1219: packingType conversion from grid_ieee to grid_second_order */
|
||||
if ((ret = get_bits_per_value(handle, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if ((ret = grib_get_long_internal(handle, self->optimize_scaling_factor, &optimize_scaling_factor)) != GRIB_SUCCESS)
|
||||
|
|
|
@ -382,11 +382,21 @@ int grib_set_string(grib_handle* h, const char* name, const char* val, size_t* l
|
|||
size_t numCodedVals = 0;
|
||||
grib_get_long(h, "bitsPerValue", &bitsPerValue);
|
||||
if (bitsPerValue == 0) {
|
||||
/* ECC-1219: packingType conversion from grid_ieee to grid_second_order */
|
||||
/* Normally having a bitsPerValue of 0 means a constant field but this is
|
||||
* not so for IEEE packing which can be non-constant but always has bitsPerValue==0!
|
||||
*/
|
||||
char input_packing_type[100] = {0,};
|
||||
size_t len = sizeof(input_packing_type);
|
||||
grib_get_string(h, "packingType", input_packing_type, &len);
|
||||
if (strcmp(input_packing_type, "grid_ieee") != 0) {
|
||||
/* If it's not IEEE, then bitsPerValue==0 means constant field */
|
||||
if (h->context->debug) {
|
||||
fprintf(stderr, "ECCODES DEBUG grib_set_string packingType: Constant field cannot be encoded in second order. Packing not changed\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* GRIB-883: check if there are enough coded values */
|
||||
ret = grib_get_size(h, "codedValues", &numCodedVals);
|
||||
|
|
|
@ -141,6 +141,14 @@ ${tools_dir}/grib_set -r -s packingType=grid_second_order $temp2 $temp3
|
|||
grib_check_key_equals $temp3 packingType grid_second_order
|
||||
|
||||
|
||||
# ECC-1219: packingType conversion from grid_ieee to grid_second_order
|
||||
# ---------------------------------------------------------------------
|
||||
infile=grid_ieee.grib
|
||||
${tools_dir}/grib_set -r -s packingType=grid_second_order $infile $temp1
|
||||
grib_check_key_equals $temp1 packingType grid_second_order
|
||||
${tools_dir}/grib_compare -cdata:n -R all=3e-06 $infile $temp1
|
||||
|
||||
|
||||
# Clean up
|
||||
rm -f $temp_stat1 $temp_stat2
|
||||
rm -f $temp1 $temp2 $temp3 $sec_ord_bmp
|
||||
|
|
Loading…
Reference in New Issue