mirror of https://github.com/ecmwf/eccodes.git
Refactoring
This commit is contained in:
parent
3b2ed365d9
commit
d0caf0e4cf
|
@ -194,16 +194,22 @@ static int pack_double(grib_accessor* a, const double* cval, size_t* len)
|
|||
}
|
||||
|
||||
if (units_factor != 1.0) {
|
||||
if (units_bias != 0.0)
|
||||
for (i = 0; i < n_vals; i++)
|
||||
if (units_bias != 0.0) {
|
||||
for (i = 0; i < n_vals; i++) {
|
||||
val[i] = val[i] * units_factor + units_bias;
|
||||
else
|
||||
for (i = 0; i < n_vals; i++)
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (i = 0; i < n_vals; i++) {
|
||||
val[i] *= units_factor;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (units_bias != 0.0)
|
||||
for (i = 0; i < n_vals; i++)
|
||||
else if (units_bias != 0.0) {
|
||||
for (i = 0; i < n_vals; i++) {
|
||||
val[i] += units_bias;
|
||||
}
|
||||
}
|
||||
|
||||
if (c->ieee_packing && self->ieee_packing) {
|
||||
long precision = 0; /* Either 1(=32 bits) or 2(=64 bits) */
|
||||
|
|
|
@ -177,16 +177,21 @@ static int pack_double(grib_accessor* a, const double* cval, size_t* len)
|
|||
}
|
||||
|
||||
if (units_factor != 1.0) {
|
||||
if (units_bias != 0.0)
|
||||
for (i = 0; i < n_vals; i++)
|
||||
if (units_bias != 0.0) {
|
||||
for (i = 0; i < n_vals; i++) {
|
||||
val[i] = val[i] * units_factor + units_bias;
|
||||
else
|
||||
for (i = 0; i < n_vals; i++)
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < n_vals; i++) {
|
||||
val[i] *= units_factor;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (units_bias != 0.0)
|
||||
for (i = 0; i < n_vals; i++)
|
||||
else if (units_bias != 0.0) {
|
||||
for (i = 0; i < n_vals; i++) {
|
||||
val[i] += units_bias;
|
||||
}
|
||||
}
|
||||
|
||||
/* IEEE packing */
|
||||
if (c->ieee_packing) {
|
||||
|
|
|
@ -225,7 +225,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
|
|||
grib_accessor_data_jpeg2000_packing* self = (grib_accessor_data_jpeg2000_packing*)a;
|
||||
|
||||
int err = GRIB_SUCCESS;
|
||||
int i;
|
||||
size_t i = 0;
|
||||
size_t buflen = grib_byte_count(a);
|
||||
|
||||
double bscale = 0;
|
||||
|
@ -304,16 +304,21 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
|
|||
val[i] = (val[i] * bscale + reference_value) * dscale;
|
||||
}
|
||||
if (units_factor != 1.0) {
|
||||
if (units_bias != 0.0)
|
||||
for (i = 0; i < n_vals; i++)
|
||||
if (units_bias != 0.0) {
|
||||
for (i = 0; i < n_vals; i++) {
|
||||
val[i] = val[i] * units_factor + units_bias;
|
||||
else
|
||||
for (i = 0; i < n_vals; i++)
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < n_vals; i++) {
|
||||
val[i] *= units_factor;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (units_bias != 0.0)
|
||||
for (i = 0; i < n_vals; i++)
|
||||
else if (units_bias != 0.0) {
|
||||
for (i = 0; i < n_vals; i++) {
|
||||
val[i] += units_bias;
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
|
|
@ -406,16 +406,21 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
|
|||
*len = (long)n_vals;
|
||||
|
||||
if (units_factor != 1.0) {
|
||||
if (units_bias != 0.0)
|
||||
for (i = 0; i < n_vals; i++)
|
||||
if (units_bias != 0.0) {
|
||||
for (i = 0; i < n_vals; i++) {
|
||||
val[i] = val[i] * units_factor + units_bias;
|
||||
else
|
||||
for (i = 0; i < n_vals; i++)
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < n_vals; i++) {
|
||||
val[i] *= units_factor;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (units_bias != 0.0)
|
||||
for (i = 0; i < n_vals; i++)
|
||||
else if (units_bias != 0.0) {
|
||||
for (i = 0; i < n_vals; i++) {
|
||||
val[i] += units_bias;
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,22 +13,31 @@
|
|||
label="grib_units_bias_factor_test"
|
||||
outfile=temp.$label.grib
|
||||
|
||||
infile=${data_dir}/sample.grib2
|
||||
max=`${tools_dir}/grib_get -F%.3f -p max $infile`
|
||||
[ "$max" = "311.099" ]
|
||||
infiles="${data_dir}/sample.grib2 ${data_dir}/regular_latlon_surface.grib1"
|
||||
for infile in $infiles; do
|
||||
#infile=${data_dir}/sample.grib2
|
||||
max=`${tools_dir}/grib_get -F%.3f -p max $infile`
|
||||
[ "$max" = "311.099" ]
|
||||
|
||||
${tools_dir}/grib_set -rs unitsFactor=1.1,unitsBias=4 $infile $outfile
|
||||
max=`${tools_dir}/grib_get -F%.3f -p max $outfile`
|
||||
[ "$max" = "346.209" ]
|
||||
${tools_dir}/grib_set -rs unitsFactor=1.1,unitsBias=4 $infile $outfile
|
||||
max=`${tools_dir}/grib_get -F%.3f -p max $outfile`
|
||||
[ "$max" = "346.209" ]
|
||||
|
||||
${tools_dir}/grib_set -rs unitsFactor=2 $infile $outfile
|
||||
max=`${tools_dir}/grib_get -F%.3f -p max $outfile`
|
||||
[ "$max" = "622.197" ]
|
||||
${tools_dir}/grib_set -rs unitsFactor=2 $infile $outfile
|
||||
max=`${tools_dir}/grib_get -F%.3f -p max $outfile`
|
||||
[ "$max" = "622.197" ]
|
||||
|
||||
${tools_dir}/grib_set -rs unitsBias=4 $infile $outfile
|
||||
max=`${tools_dir}/grib_get -F%.3f -p max $outfile`
|
||||
[ "$max" = "315.099" ]
|
||||
${tools_dir}/grib_set -rs unitsBias=4 $infile $outfile
|
||||
max=`${tools_dir}/grib_get -F%.3f -p max $outfile`
|
||||
[ "$max" = "315.099" ]
|
||||
done
|
||||
|
||||
if [ $HAVE_JPEG -eq 1 ]; then
|
||||
infile=${data_dir}/jpeg.grib2
|
||||
${tools_dir}/grib_get -p max -s unitsBias=1.5 $infile $outfile
|
||||
${tools_dir}/grib_get -p min -s unitsFactor=2 $infile $outfile
|
||||
${tools_dir}/grib_get -p avg -s unitsFactor=1.1,unitsBias=100 $infile $outfile
|
||||
fi
|
||||
|
||||
# Clean up
|
||||
rm -f $outfile
|
||||
|
|
Loading…
Reference in New Issue