GRIB-802: Provide mechanism to produce compact constant fields ignoring GRIB_API_LARGE_CONSTANT_FIELDS

This commit is contained in:
Shahram Najm 2015-07-24 18:36:25 +01:00
parent 406129a4c0
commit 79927d0159
2 changed files with 26 additions and 1 deletions

View File

@ -58,6 +58,8 @@ transient unitsBias=0 : hidden;
constant globalDomain = "g";
transient timeRangeIndicatorFromStepRange=-1 : hidden;
# GRIB-802
transient override_large_constant_fields = 0;
meta libraryVersion library_version() : hidden;

View File

@ -436,6 +436,27 @@ static int unpack_double(grib_accessor* a, double* val, size_t *len) {
#undef restrict
#endif
/* Return true(1) if large constant fields are to be created, otherwise false(0) */
static int producing_large_constant_fields(const grib_context* c, grib_handle* h, int edition)
{
/* GRIB-802: If override key is set, ignore env. var and produce compressed fields */
if (c->large_constant_fields) { /* This is set by the environment variable */
/* check the override key */
int err = 0;
long override_large_constant_fields = 0;
err = grib_get_long_internal(h, "override_large_constant_fields", &override_large_constant_fields);
if (err == GRIB_SUCCESS && override_large_constant_fields) {
return 0;
}
return 1;
}
if (c->gribex_mode_on==1 && edition==1) {
return 1;
}
return 0;
}
static int pack_double(grib_accessor* a, const double* val, size_t *len)
{
grib_accessor_data_simple_packing* self = (grib_accessor_data_simple_packing*)a;
@ -498,6 +519,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len)
/* constant field only reference_value is set and bits_per_value=0 */
if(max==min) {
int large_constant_fields = 0;
if (grib_get_nearest_smaller_value(a->parent->h,self->reference_value,val[0],&reference_value)
!=GRIB_SUCCESS) {
grib_context_log(a->parent->h->context,GRIB_LOG_ERROR,
@ -517,7 +539,8 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len)
Assert(ref == reference_value);
}
if (c->large_constant_fields || (c->gribex_mode_on==1 && self->edition==1)) {
large_constant_fields = producing_large_constant_fields(c, a->parent->h, self->edition);
if (large_constant_fields) {
if((err = grib_set_long_internal(a->parent->h,self->binary_scale_factor, 0)) !=
GRIB_SUCCESS)
return err;