Skip to content

Commit

Permalink
Testing: grib_util_set_spec cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
shahramn committed Feb 17, 2024
1 parent e89dfad commit 6a41db4
Showing 1 changed file with 53 additions and 39 deletions.
92 changes: 53 additions & 39 deletions tests/grib_util_set_spec2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static void dump_it(grib_handle* h)
}

// Lambert conformal
static void test0()
static grib_handle* test0()
{
int err = 0;
grib_util_grid_spec spec = {0,};
Expand All @@ -27,14 +27,10 @@ static void test0()
int set_spec_flags = 0;
size_t outlen = 4;

grib_handle* handle = grib_handle_new_from_samples(0, "GRIB2");
grib_handle* handle = grib_handle_new_from_samples(0, "GRIB1");
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;
spec.Ni = 2;
spec.Nj = 2;

// packing_spec.packing_type = GRIB_UTIL_PACKING_TYPE_GRID_SIMPLE;
// packing_spec.bitsPerValue = 16;
Expand All @@ -44,13 +40,12 @@ static void test0()
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);
return finalh;
}

// Lambert azimuthal
static void test1()
static grib_handle* test1()
{
int err = 0;
grib_util_grid_spec spec = {0,};
Expand All @@ -66,13 +61,12 @@ static void test1()
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);
return finalh;
}

// HEALPix
static void test2()
static grib_handle* test2()
{
int err = 0;
grib_util_grid_spec spec = {0,};
Expand All @@ -82,20 +76,23 @@ static void test2()
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;

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;

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);
return finalh;
}

// Spherical harmonics
static void test3()
static grib_handle* test3()
{
int err = 0;
grib_util_grid_spec spec = {0,};
Expand All @@ -105,7 +102,6 @@ static void test3()
size_t outlen = 0;

grib_handle* handle = grib_handle_new_from_samples(0, "sh_pl_grib2");
grib_set_long(handle, "tablesVersion", 32);
spec.grid_type = GRIB_UTIL_GRID_SPEC_SH;
spec.truncation = 20;
outlen = 2;
Expand All @@ -118,13 +114,12 @@ static void test3()
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);
return finalh;
}

// Polar stereo
static void test4()
static grib_handle* test4()
{
int err = 0;
grib_util_grid_spec spec = {0,};
Expand All @@ -141,13 +136,12 @@ static void test4()
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);
return finalh;
}

// Regular Gaussian
static void test5()
static grib_handle* test5()
{
int err = 0;
grib_util_grid_spec spec = {0,};
Expand All @@ -157,21 +151,19 @@ static void test5()
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);
return finalh;
}

// Reduced LL
static void test6()
static grib_handle* test6()
{
int err = 0;
grib_util_grid_spec spec = {0,};
Expand All @@ -181,27 +173,49 @@ static void test6()
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);
Assert(err == 0);
dump_it(finalh);
return finalh;
}

// Unstructured
static grib_handle* test7()
{
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 = 4;

grib_handle* handle = grib_handle_new_from_samples(0, "GRIB2");
spec.grid_type = GRIB_UTIL_GRID_SPEC_UNSTRUCTURED;

grib_handle* finalh = grib_util_set_spec(
handle, &spec, &packing_spec, set_spec_flags,
values, outlen, &err);
Assert(err == 0);
return finalh;
}

int main()
{
test0();
test1();
test2();
test3();
test4();
test5();
test6();
typedef grib_handle* (*test_func)(void);
test_func funcs[] = {test0, test1, test2, test3, test4, test5, test6, test7};

//grib_handle* (*p[8]) (void) = {test0, test1, test2, test3, test4, test5, test6, test7};

const size_t num_tests = sizeof(funcs)/sizeof(funcs[0]);
for (size_t i = 0; i < num_tests; i++) {
grib_handle* result = funcs[i]();
Assert(result);
dump_it(result);
}
return 0;
}

0 comments on commit 6a41db4

Please sign in to comment.