Testing: Checking Gaussian grids

This commit is contained in:
Shahram Najm 2023-03-25 14:25:01 +00:00
parent 25d8879954
commit 07e8affd43
2 changed files with 42 additions and 6 deletions

View File

@ -10,7 +10,8 @@
. ./include.ctest.sh
label="grib_check_gaussian_grids_test"
temp=temp.$label.grib
tempGrib=temp.$label.grib
tempText=temp.$label.txt
# Check all sample GRIBs with a Gaussian grid
@ -20,14 +21,44 @@ for gg in ${samples_dir}/reduced_gg_* ${samples_dir}/regular_gg_*; do
grib_check_key_equals $gg "global" 1
done
for gg in ${samples_dir}/reduced_gg_*tmpl; do
${tools_dir}/grib_set -s global=1 $gg $tempGrib
${tools_dir}/grib_check_gaussian_grid $tempGrib
done
# Set wrong angle and re-test. Should fail
input=$samples_dir/reduced_gg_pl_1280_grib2.tmpl
${tools_dir}/grib_set -s longitudeOfLastGridPoint=359929680 $input $temp
${tools_dir}/grib_set -s longitudeOfLastGridPoint=359929680 $input $tempGrib
set +e
${tools_dir}/grib_check_gaussian_grid -v $temp
${tools_dir}/grib_check_gaussian_grid -v $tempGrib 2> $tempText
status=$?
set -e
[ $status -eq 1 ]
grep -q "Error: longitudeOfLastGridPointInDegrees.*but should be" $tempText
rm -f $temp
# Set wrong numberOfDataPoints and re-test. Should fail
input=$samples_dir/reduced_gg_pl_96_grib2.tmpl
${tools_dir}/grib_set -s numberOfDataPoints=44 $input $tempGrib
set +e
${tools_dir}/grib_check_gaussian_grid -v $tempGrib 2> $tempText
status=$?
set -e
[ $status -eq 1 ]
grep -q "Error: Sum of pl array 50662 does not match numberOfDataPoints 44" $tempText
# Set wrong numberOfValues and re-test. Should fail
input=$samples_dir/reduced_gg_pl_96_grib2.tmpl
${tools_dir}/grib_set -s numberOfValues=44 $input $tempGrib
set +e
${tools_dir}/grib_check_gaussian_grid -v $tempGrib 2> $tempText
status=$?
set -e
[ $status -eq 1 ]
cat $tempText
grep -q "Error: Sum of pl array 50662 does not match numberOfValues 44" $tempText
rm -f $tempGrib $tempText

View File

@ -97,7 +97,7 @@ static int process_file(const char* filename)
while ((h = grib_handle_new_from_file(0, in, &err)) != NULL) {
int is_reduced_gaussian = 0, is_regular_gaussian = 0, grid_ok = 0;
long edition = 0, N = 0, Nj = 0, numberOfDataPoints;
long edition = 0, N = 0, Nj = 0, numberOfDataPoints, numberOfValues;
size_t len = 0, sizeOfValuesArray = 0;
double* lats = NULL;
long* pl = NULL;
@ -128,6 +128,7 @@ static int process_file(const char* filename)
GRIB_CHECK(grib_get_long(h, "N", &N), 0);
GRIB_CHECK(grib_get_long(h, "Nj", &Nj), 0);
GRIB_CHECK(grib_get_long(h, "numberOfDataPoints", &numberOfDataPoints), 0);
GRIB_CHECK(grib_get_long(h, "numberOfValues", &numberOfValues), 0);
GRIB_CHECK(grib_get_double(h, "latitudeOfFirstGridPointInDegrees", &lat1), 0);
GRIB_CHECK(grib_get_double(h, "longitudeOfFirstGridPointInDegrees", &lon1), 0);
GRIB_CHECK(grib_get_double(h, "latitudeOfLastGridPointInDegrees", &lat2), 0);
@ -165,7 +166,8 @@ static int process_file(const char* filename)
}
if (is_reduced_gaussian) {
int pl_sum = 0, max_pl = 0, is_missing_Ni = 0, is_missing_Di = 0;
int is_missing_Ni = 0, is_missing_Di = 0;
long pl_sum = 0, max_pl = 0;
size_t i = 0, pl_len = 0;
long is_octahedral = 0;
long interpretationOfNumberOfPoints = 0;
@ -215,6 +217,9 @@ static int process_file(const char* filename)
if (pl_sum != numberOfDataPoints) {
error(filename, msg_num, "Sum of pl array %ld does not match numberOfDataPoints %ld\n", pl_sum, numberOfDataPoints);
}
if (pl_sum != numberOfValues) {
error(filename, msg_num, "Sum of pl array %ld does not match numberOfValues %ld\n", pl_sum, numberOfValues);
}
GRIB_CHECK(grib_get_long(h, "isOctahedral", &is_octahedral), 0);
if (is_octahedral) {
if (verbose)