Testing: grib_util_set_spec for reduced ll

This commit is contained in:
Shahram Najm 2024-02-17 20:39:03 +00:00
parent 5cdd9d17cb
commit e89dfad0ba
2 changed files with 63 additions and 71 deletions

View File

@ -21,7 +21,6 @@ static void dump_it(grib_handle* h)
static void test0()
{
int err = 0;
grib_handle* finalh = 0;
grib_util_grid_spec spec = {0,};
grib_util_packing_spec packing_spec = {0,};
double values[4] = {1.1, 2.2, 3.3, 0.4};
@ -29,16 +28,20 @@ static void test0()
size_t outlen = 4;
grib_handle* handle = grib_handle_new_from_samples(0, "GRIB2");
grib_set_long(handle, "tablesVersion", 32);
spec.grid_type = GRIB_UTIL_GRID_SPEC_LAMBERT_CONFORMAL;
spec.N = 2;
packing_spec.extra_settings_count = 1;
packing_spec.extra_settings[0].type = GRIB_TYPE_LONG;
packing_spec.extra_settings[0].name = "tablesVersion";
packing_spec.extra_settings[0].long_value = 32;
// packing_spec.packing_type = GRIB_UTIL_PACKING_TYPE_GRID_SIMPLE;
// packing_spec.bitsPerValue = 16;
// packing_spec.accuracy = GRIB_UTIL_ACCURACY_USE_PROVIDED_BITS_PER_VALUES;
// packing_spec.accuracy = GRIB_UTIL_ACCURACY_USE_PROVIDED_BITS_PER_VALUES;
// packing_spec.packing = GRIB_UTIL_PACKING_USE_PROVIDED;
finalh = grib_util_set_spec(
grib_handle* finalh = grib_util_set_spec(
handle, &spec, &packing_spec, set_spec_flags,
values, outlen, &err);
Assert(finalh);
@ -50,7 +53,6 @@ static void test0()
static void test1()
{
int err = 0;
grib_handle* finalh = 0;
grib_util_grid_spec spec = {0,};
grib_util_packing_spec packing_spec = {0,};
double values[4] = {1.1, 2.2, 3.3, 0.4};
@ -61,7 +63,7 @@ static void test1()
grib_set_long(handle, "tablesVersion", 32);
spec.grid_type = GRIB_UTIL_GRID_SPEC_LAMBERT_AZIMUTHAL_EQUAL_AREA;
finalh = grib_util_set_spec(
grib_handle* finalh = grib_util_set_spec(
handle, &spec, &packing_spec, set_spec_flags,
values, outlen, &err);
Assert(finalh);
@ -73,25 +75,18 @@ static void test1()
static void test2()
{
int err = 0;
grib_handle* finalh = 0;
grib_util_grid_spec spec = {0,};
grib_util_packing_spec packing_spec = {0,};
double values[4] = {1.1, 2.2, 3.3, 0.4};
int set_spec_flags = 0;
size_t outlen = 0;
size_t outlen = 4;
grib_handle* handle = grib_handle_new_from_samples(0, "GRIB2");
grib_set_long(handle, "tablesVersion", 32);
spec.grid_type = GRIB_UTIL_GRID_SPEC_HEALPIX;
spec.N = 2;
outlen = 4;
packing_spec.packing_type = GRIB_UTIL_PACKING_TYPE_GRID_SIMPLE;
packing_spec.bitsPerValue = 16;
packing_spec.accuracy = GRIB_UTIL_ACCURACY_USE_PROVIDED_BITS_PER_VALUES;
packing_spec.packing = GRIB_UTIL_PACKING_USE_PROVIDED;
finalh = grib_util_set_spec(
grib_handle* finalh = grib_util_set_spec(
handle, &spec, &packing_spec, set_spec_flags,
values, outlen, &err);
Assert(finalh);
@ -103,7 +98,6 @@ static void test2()
static void test3()
{
int err = 0;
grib_handle* finalh = 0;
grib_util_grid_spec spec = {0,};
grib_util_packing_spec packing_spec = {0,};
double values[4] = {1.1, 2.2};
@ -121,7 +115,7 @@ static void test3()
packing_spec.accuracy = GRIB_UTIL_ACCURACY_USE_PROVIDED_BITS_PER_VALUES;
packing_spec.packing = GRIB_UTIL_PACKING_USE_PROVIDED;
finalh = grib_util_set_spec(
grib_handle* finalh = grib_util_set_spec(
handle, &spec, &packing_spec, set_spec_flags,
values, outlen, &err);
Assert(finalh);
@ -133,7 +127,6 @@ static void test3()
static void test4()
{
int err = 0;
grib_handle* finalh = 0;
grib_util_grid_spec spec = {0,};
grib_util_packing_spec packing_spec = {0,};
double values[4] = {1.1, 2.2, 3.3, 0.4};
@ -145,7 +138,55 @@ static void test4()
spec.grid_type = GRIB_UTIL_GRID_SPEC_POLAR_STEREOGRAPHIC;
outlen = 4;
finalh = grib_util_set_spec(
grib_handle* finalh = grib_util_set_spec(
handle, &spec, &packing_spec, set_spec_flags,
values, outlen, &err);
Assert(finalh);
Assert(err == 0);
dump_it(finalh);
}
// Regular Gaussian
static void test5()
{
int err = 0;
grib_util_grid_spec spec = {0,};
grib_util_packing_spec packing_spec = {0,};
double values[4] = {1.1, 2.2, 3.3, 0.4};
int set_spec_flags = 0;
size_t outlen = 0;
grib_handle* handle = grib_handle_new_from_samples(0, "GRIB2");
grib_set_long(handle, "tablesVersion", 32);
spec.grid_type = GRIB_UTIL_GRID_SPEC_REGULAR_GG;
spec.Ni = spec.Nj = 2;
outlen = 4;
grib_handle* finalh = grib_util_set_spec(
handle, &spec, &packing_spec, set_spec_flags,
values, outlen, &err);
Assert(finalh);
Assert(err == 0);
dump_it(finalh);
}
// Reduced LL
static void test6()
{
int err = 0;
grib_util_grid_spec spec = {0,};
grib_util_packing_spec packing_spec = {0,};
double values[4] = {1.1, 2.2, 3.3, 0.4};
int set_spec_flags = 0;
size_t outlen = 0;
grib_handle* handle = grib_handle_new_from_samples(0, "GRIB2");
grib_set_long(handle, "tablesVersion", 32);
spec.grid_type = GRIB_UTIL_GRID_SPEC_REDUCED_LL;
spec.Nj = 2;
outlen = 4;
grib_handle* finalh = grib_util_set_spec(
handle, &spec, &packing_spec, set_spec_flags,
values, outlen, &err);
Assert(finalh);
@ -160,51 +201,7 @@ int main()
test2();
test3();
test4();
test5();
test6();
return 0;
}
#if 0
int main(int argc, char* argv[])
{
int i = 0, remove_local_def = 0;
int edition = 0;
char* packingType = NULL;
const char* prog = argv[0];
char* infile_name = NULL;
char* outfile_name = NULL;
if (argc == 1 || argc > 8) usage(prog);
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-p") == 0) {
packingType = argv[i + 1];
++i;
}
else if (strcmp(argv[i], "-e") == 0) {
edition = atoi(argv[i + 1]);
++i;
}
else if (strcmp(argv[i], "-r") == 0) {
remove_local_def = 1;
}
else {
/* Expect 2 filenames */
infile_name = argv[i];
outfile_name = argv[i + 1];
break;
}
}
#if 0
printf("DEBUG remove_local_def = %d\n", remove_local_def);
printf("DEBUG edition = %d\n", edition);
printf("DEBUG packingType = %s\n", packingType);
printf("DEBUG infile_name = %s\n", infile_name);
printf("DEBUG outfile_name = %s\n", outfile_name);
#endif
test_regular_ll(remove_local_def, edition, packingType, infile_name, outfile_name);
test_reduced_gg(remove_local_def, edition, packingType, infile_name, outfile_name);
/*test_grid_complex_spatial_differencing(remove_local_def, edition, packingType, infile_name, outfile_name);*/
return 0;
}
#endif

View File

@ -10,9 +10,4 @@
. ./include.ctest.sh
grib_util_set_spec=${test_dir}/grib_util_set_spec2
$EXEC $grib_util_set_spec
### Clean up
$EXEC ${test_dir}/grib_util_set_spec2