Testing: packing tests

This commit is contained in:
Shahram Najm 2022-02-27 14:43:09 +00:00
parent 59b169c4ba
commit 7ae5755547
2 changed files with 39 additions and 9 deletions

View File

@ -24790,6 +24790,9 @@ typedef enum {
VALUES_BEFORE_PACKING_TYPE
} PackingStage;
#define EPSILON 1e-5
int main(int argc, char** argv)
{
size_t values_len = sizeof(values)/sizeof(values[0]);
@ -24799,6 +24802,7 @@ int main(int argc, char** argv)
PackingStage packing_stage;
char* packing_type;
char* outfile_name;
int check = 1;
if (argc != 4) usage(argv[0]);
@ -24816,6 +24820,10 @@ int main(int argc, char** argv)
h = codes_grib_handle_new_from_samples(0, sample_filename);
assert(h);
if (strcmp(packing_type, "grid_second_order")==0 && packing_stage == VALUES_BEFORE_PACKING_TYPE) {
check = 0; /* TDOD */
}
CODES_CHECK(codes_set_long(h, "bitsPerValue", 16), 0);
if (packing_stage == PACKING_TYPE_BEFORE_VALUES) {
printf("Set packingType to %s\n", packing_type);
@ -24831,7 +24839,25 @@ int main(int argc, char** argv)
}
CODES_CHECK(codes_write_message(h, outfile_name, "w"), 0);
codes_handle_delete(h);
printf("%s checks on decoded values '%s' (%s) ...\n",
(check?"Doing":"Skipping"), packing_type, argv[2]);
if (check) {
size_t i = 0;
double* vals = (double*)malloc(sizeof(double) * values_len);
GRIB_CHECK(grib_get_double_array(h, "values", vals, &values_len), 0);
for (i = 0; i < values_len; i++) {
const double diff = fabs(values[i] - vals[i]);
if (diff > EPSILON) {
fprintf(stderr, "Unpacked value different: i=%lu values[i]=%.7f vals[i]=%.7f\n",
i, values[i], vals[i]);
return 1;
}
}
free(vals);
}
codes_handle_delete(h);
printf("All done\n");
return 0;
}

View File

@ -33,14 +33,6 @@ $EXEC ${test_dir}/grib_packing_order grid_simple values_before_packing_type $tem
grib_check_key_equals $temp_simple1 packingType grid_simple
${tools_dir}/grib_compare $temp_simple1 $temp_simple2
# Second order Packing: TODO
# ---------------------------
$EXEC ${test_dir}/grib_packing_order grid_second_order packing_type_before_values $temp_second1
$EXEC ${test_dir}/grib_packing_order grid_second_order values_before_packing_type $temp_second2
grib_check_key_equals $temp_second1 packingType grid_second_order
#${tools_dir}/grib_compare $temp_second1 $temp_second2
${tools_dir}/grib_compare -c data:n $temp_simple1 $temp_second1
# $temp_second2 is still not correct
# PNG Packing
# -------------
@ -90,6 +82,18 @@ ${tools_dir}/grib_ls -n statistics $temp_ieee1 $temp_ieee2
# No point comparing with grid_simple as grid_ieee will be closer to the actual values
# and less lossy
# Second order Packing: TODO
# ---------------------------
$EXEC ${test_dir}/grib_packing_order grid_second_order packing_type_before_values $temp_second1
$EXEC ${test_dir}/grib_packing_order grid_second_order values_before_packing_type $temp_second2
grib_check_key_equals $temp_second1 packingType grid_second_order
#${tools_dir}/grib_compare $temp_second1 $temp_second2
${tools_dir}/grib_compare -c data:n $temp_simple1 $temp_second1
# $temp_second2 is still not correct
# Clean up
rm -f $temp_simple1 $temp_simple2
rm -f $temp_second1 $temp_second2