mirror of https://github.com/ecmwf/eccodes.git
ECC-1345: GRIB: ECCODES_GRIB_IEEE_PACKING environment variable value should be checked
This commit is contained in:
parent
a088b07135
commit
a89e1956f8
|
@ -130,3 +130,13 @@ char* codes_getenv(const char* name)
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int codes_check_grib_ieee_packing_value(int value)
|
||||||
|
{
|
||||||
|
grib_context* c = grib_context_get_default();
|
||||||
|
if (value != 32 && value != 64) {
|
||||||
|
grib_context_log(c, GRIB_LOG_ERROR, "Invalid value for ECCODES_GRIB_IEEE_PACKING: should be 32 or 64");
|
||||||
|
return GRIB_INVALID_ARGUMENT;
|
||||||
|
}
|
||||||
|
return GRIB_SUCCESS;
|
||||||
|
}
|
||||||
|
|
|
@ -236,12 +236,15 @@ static int pack_double(grib_accessor* a, const double* cval, size_t* len)
|
||||||
val[i] += units_bias;
|
val[i] += units_bias;
|
||||||
|
|
||||||
if (c->ieee_packing && self->ieee_packing) {
|
if (c->ieee_packing && self->ieee_packing) {
|
||||||
long precision = c->ieee_packing == 32 ? 1 : 2;
|
long precision = 0; /* Either 1(=32 bits) or 2(=64 bits) */
|
||||||
size_t lenstr = strlen(self->ieee_packing);
|
size_t lenstr = strlen(self->ieee_packing);
|
||||||
|
if ((ret = codes_check_grib_ieee_packing_value(c->ieee_packing)) != GRIB_SUCCESS)
|
||||||
|
return ret;
|
||||||
|
|
||||||
packingType_s = grib_context_strdup(c, self->packingType);
|
packingType_s = grib_context_strdup(c, self->packingType);
|
||||||
ieee_packing_s = grib_context_strdup(c, self->ieee_packing);
|
ieee_packing_s = grib_context_strdup(c, self->ieee_packing);
|
||||||
precision_s = grib_context_strdup(c, self->precision);
|
precision_s = grib_context_strdup(c, self->precision);
|
||||||
|
precision = c->ieee_packing == 32 ? 1 : 2;
|
||||||
|
|
||||||
if ((ret = grib_set_string(h, packingType_s, ieee_packing_s, &lenstr)) != GRIB_SUCCESS)
|
if ((ret = grib_set_string(h, packingType_s, ieee_packing_s, &lenstr)) != GRIB_SUCCESS)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -220,8 +220,11 @@ static int pack_double(grib_accessor* a, const double* cval, size_t* len)
|
||||||
/* IEEE packing */
|
/* IEEE packing */
|
||||||
if (c->ieee_packing) {
|
if (c->ieee_packing) {
|
||||||
grib_handle* h = grib_handle_of_accessor(a);
|
grib_handle* h = grib_handle_of_accessor(a);
|
||||||
long precision = c->ieee_packing == 32 ? 1 : 2;
|
long precision = 0; /* Either 1(=32 bits) or 2(=64 bits) */
|
||||||
size_t lenstr = 10;
|
size_t lenstr = 10;
|
||||||
|
if ((ret = codes_check_grib_ieee_packing_value(c->ieee_packing)) != GRIB_SUCCESS)
|
||||||
|
return ret;
|
||||||
|
precision = c->ieee_packing == 32 ? 1 : 2;
|
||||||
if ((ret = grib_set_string(h, "packingType", "grid_ieee", &lenstr)) != GRIB_SUCCESS)
|
if ((ret = grib_set_string(h, "packingType", "grid_ieee", &lenstr)) != GRIB_SUCCESS)
|
||||||
return ret;
|
return ret;
|
||||||
if ((ret = grib_set_long(h, "precision", precision)) != GRIB_SUCCESS)
|
if ((ret = grib_set_long(h, "precision", precision)) != GRIB_SUCCESS)
|
||||||
|
|
|
@ -1095,7 +1095,7 @@ struct grib_context
|
||||||
grib_hash_array_value* hash_array[MAX_NUM_HASH_ARRAY];
|
grib_hash_array_value* hash_array[MAX_NUM_HASH_ARRAY];
|
||||||
grib_trie* def_files;
|
grib_trie* def_files;
|
||||||
grib_string_list* blocklist;
|
grib_string_list* blocklist;
|
||||||
int ieee_packing;
|
int ieee_packing; /* 32 or 64 */
|
||||||
int bufrdc_mode;
|
int bufrdc_mode;
|
||||||
int bufr_set_to_missing_if_out_of_range;
|
int bufr_set_to_missing_if_out_of_range;
|
||||||
int bufr_multi_element_constant_arrays;
|
int bufr_multi_element_constant_arrays;
|
||||||
|
|
|
@ -1446,6 +1446,7 @@ char get_dir_separator_char(void);
|
||||||
int path_is_regular_file(const char* path);
|
int path_is_regular_file(const char* path);
|
||||||
int path_is_directory(const char* filename);
|
int path_is_directory(const char* filename);
|
||||||
char* codes_getenv(const char* name);
|
char* codes_getenv(const char* name);
|
||||||
|
int codes_check_grib_ieee_packing_value(int value);
|
||||||
|
|
||||||
/* grib_util.c */
|
/* grib_util.c */
|
||||||
grib_handle* grib_util_sections_copy(grib_handle* hfrom, grib_handle* hto, int what, int* err);
|
grib_handle* grib_util_sections_copy(grib_handle* hfrom, grib_handle* hto, int what, int* err);
|
||||||
|
|
|
@ -130,6 +130,19 @@ for edition in $editions; do
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
|
echo "Test ECC-1345: env. var value should be checked..."
|
||||||
|
# -------------------------------------------------------
|
||||||
|
tempErr=temp.grib_ieee.txt
|
||||||
|
set +e
|
||||||
|
# Should fail. Only 32 and 64 are valid
|
||||||
|
infile=${data_dir}/regular_latlon_surface.grib2
|
||||||
|
ECCODES_GRIB_IEEE_PACKING=16 ${tools_dir}/grib_copy -r $infile $temp 2>$tempErr
|
||||||
|
status=$?
|
||||||
|
set -e
|
||||||
|
[ $status -ne 0 ]
|
||||||
|
grep -q "Invalid value for ECCODES_GRIB_IEEE_PACKING: should be 32 or 64" $tempErr
|
||||||
|
rm -f $tempErr
|
||||||
|
|
||||||
echo "Test raw packing on GRIB1 with bitmap..."
|
echo "Test raw packing on GRIB1 with bitmap..."
|
||||||
# ---------------------------------------------
|
# ---------------------------------------------
|
||||||
infile=${data_dir}/reduced_latlon_surface.grib1
|
infile=${data_dir}/reduced_latlon_surface.grib1
|
||||||
|
|
Loading…
Reference in New Issue