ECC-261: 2nd order: make the optimised routines the same as original contrib

This commit is contained in:
Shahram Najm 2017-01-04 16:46:14 +00:00
parent caee5e1189
commit 886d90af91
1 changed files with 30 additions and 6 deletions

View File

@ -1278,12 +1278,36 @@ static int pack_double_optimised(grib_accessor* a, const double* val, size_t *le
!= GRIB_SUCCESS)
return ret;
Assert(optimize_scaling_factor);
if ((ret=grib_optimize_decimal_factor (a, self->reference_value,
max, min, bits_per_value,
compat_gribex, 1,
&decimal_scale_factor, &binary_scale_factor, &reference_value)) != GRIB_SUCCESS)
return ret;
if (optimize_scaling_factor)
{
if((ret=grib_optimize_decimal_factor (a, self->reference_value,
max, min, bits_per_value,
compat_gribex, 1,
&decimal_scale_factor, &binary_scale_factor, &reference_value)) != GRIB_SUCCESS)
return ret;
}
else
{
/* For constant fields set decimal scale factor to 0 (See GRIB-165) */
if (min==max) {
grib_set_long_internal(handle,self->decimal_scale_factor, 0);
}
if((ret = grib_get_long_internal(handle,self->decimal_scale_factor, &decimal_scale_factor))
!= GRIB_SUCCESS)
return ret;
if (grib_get_nearest_smaller_value(handle,self->reference_value,min,&reference_value)
!=GRIB_SUCCESS) {
grib_context_log(handle->context,GRIB_LOG_ERROR,
"unable to find nearest_smaller_value of %g for %s",min,self->reference_value);
exit(GRIB_INTERNAL_ERROR);
}
binary_scale_factor = grib_get_binary_scale_fact(max,reference_value,bits_per_value,&ret);
if((ret = grib_set_long_internal(handle,self->binary_scale_factor, binary_scale_factor)) !=
GRIB_SUCCESS)
return ret;
}
decimal = grib_power(decimal_scale_factor,10);
divisor = grib_power(-binary_scale_factor,2);