Refactoring

This commit is contained in:
shahramn 2024-03-01 15:24:56 +00:00
parent 3b2ed365d9
commit d0caf0e4cf
5 changed files with 67 additions and 37 deletions

View File

@ -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) */

View File

@ -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) {

View File

@ -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;
}

View File

@ -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;
}

View File

@ -13,7 +13,9 @@
label="grib_units_bias_factor_test"
outfile=temp.$label.grib
infile=${data_dir}/sample.grib2
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" ]
@ -28,7 +30,14 @@ max=`${tools_dir}/grib_get -F%.3f -p max $outfile`
${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