ECC-924: Test code clean up

This commit is contained in:
Shahram Najm 2019-05-15 13:58:02 +01:00
parent d2d50cdf66
commit d444d18678
2 changed files with 1757 additions and 1775 deletions

View File

@ -652,14 +652,16 @@ static void rectfromellipse (double * vr, const double * ve, int nsmax, int nmsm
{
double xi = (double) i / (double) nsmax;
double xj = (double) j / (double) nmsmax;
if (xi * xi + xj * xj < 1) {
if (xi * xi + xj * xj < 1)
{
vr[kr + 0] = ve[ke + 0];
vr[kr + 1] = ve[ke + 1];
vr[kr + 2] = ve[ke + 2];
vr[kr + 3] = ve[ke + 3];
ke += 4;
}
else {
else
{
vr[kr + 0] = 0.;
vr[kr + 1] = 0.;
vr[kr + 2] = 0.;
@ -702,11 +704,10 @@ int main (int argc, char * argv[])
rectfromellipse (trunc[1].values, trunc[0].values, NSMAX, NMSMAX);
for (itrunc = 0; itrunc < 2; itrunc++)
for (igrid = 0; igrid < 3; igrid++)
{
for (itrunc = 0; itrunc < 2; itrunc++) {
for (igrid = 0; igrid < 3; igrid++) {
GRIB_CHECK (((h = grib_handle_new_from_samples (NULL, "lambert_bf_grib2")) == NULL), 0);
//GRIB_CHECK (((h = grib_handle_new_from_samples (NULL, "sh_ml_grib2")) == NULL), 0);
GRIB_CHECK (grib_set_long (h, "centre", 85), 0);
GRIB_CHECK (grib_set_long (h, "tablesVersion", 23), 0);
len = strlen (grids[igrid]);
@ -715,7 +716,6 @@ int main (int argc, char * argv[])
GRIB_CHECK (grib_set_long (h, "biFourierResolutionParameterM", NMSMAX), 0);
GRIB_CHECK (grib_set_long (h, "biFourierTruncationType", trunc[itrunc].trunc), 0);
GRIB_CHECK (grib_set_long (h, "LxInMetres", 2000), 0);
GRIB_CHECK (grib_set_long (h, "LyInMetres", 2000), 0);
@ -725,8 +725,7 @@ int main (int argc, char * argv[])
GRIB_CHECK (grib_set_long (h, "LcxInMetres", 100), 0);
GRIB_CHECK (grib_set_long (h, "LcyInMetres", 100), 0);
if (igrid == 0)
{
if (igrid == 0) {
GRIB_CHECK (grib_set_double (h, "latitudeOfFirstGridPointInDegrees", 67.9372009520603), 0);
GRIB_CHECK (grib_set_double (h, "longitudeOfFirstGridPointInDegrees", 25.1580207144963), 0);
GRIB_CHECK (grib_set_long (h, "latitudeOfSouthernPoleInDegrees", 0), 0);
@ -737,8 +736,7 @@ int main (int argc, char * argv[])
GRIB_CHECK (grib_set_long (h, "projectionCentreFlag", 0), 0);
GRIB_CHECK (grib_set_long (h, "bitsPerValue", 16), 0);
}
else if (igrid == 1)
{
else if (igrid == 1) {
GRIB_CHECK (grib_set_double (h, "latitudeOfFirstGridPointInDegrees", 67.9372009520603), 0);
GRIB_CHECK (grib_set_double (h, "longitudeOfFirstGridPointInDegrees", 25.1580207144963), 0);
GRIB_CHECK (grib_set_double (h, "LaDInDegrees", 0.), 0);
@ -746,9 +744,7 @@ int main (int argc, char * argv[])
GRIB_CHECK (grib_set_double (h, "longitudeOfLastGridPointInDegrees", 29.1580207144963), 0);
GRIB_CHECK (grib_set_double (h, "orientationOfTheGridInDegrees", 0.), 0);
}
else if (igrid == 2)
{
else if (igrid == 2) {
GRIB_CHECK (grib_set_double (h, "latitudeOfFirstGridPointInDegrees", 67.9372009520603), 0);
GRIB_CHECK (grib_set_double (h, "longitudeOfFirstGridPointInDegrees", 25.1580207144963), 0);
GRIB_CHECK (grib_set_double (h, "LaDInDegrees", 0.), 0);
@ -766,8 +762,7 @@ int main (int argc, char * argv[])
len = trunc[itrunc].len;
GRIB_CHECK (grib_set_double_array (h, "values", trunc[itrunc].values, len), 0);
if (1)
{
if (1) {
char f[128];
FILE *fp;
size_t size;
@ -808,10 +803,9 @@ int main (int argc, char * argv[])
norm = sqrt (norm / trunc[itrunc].len);
free (vals);
if (norm > 0.0001)
{
printf ("Error too large !\n");
abort ();
if (norm > 0.0001) {
fprintf (stderr, "Error too large !\n");
return 1;
}
fclose (fp);
@ -827,27 +821,25 @@ int main (int argc, char * argv[])
GRIB_CHECK (grib_get_long (h, "LcxInMetres", &LcxInMetres), 0);
GRIB_CHECK (grib_get_long (h, "LcyInMetres", &LcyInMetres), 0);
if (LxInMetres != 2000 || LyInMetres != 2000 || LuxInMetres != 1800 ||
LuyInMetres != 1800 || LcxInMetres != 100 || LcyInMetres != 100 ||
if (LxInMetres != 2000 || LyInMetres != 2000 ||
LuxInMetres != 1800 || LuyInMetres != 1800 ||
LcxInMetres != 100 || LcyInMetres != 100 ||
NSMAX != nsmax || NMSMAX != nmsmax)
{
printf ("Geometry is incorrect\n");
abort ();
fprintf (stderr, "Geometry is incorrect\n");
return 1;
}
geometry_len = 128;
GRIB_CHECK (grib_get_string (h, "gridType", geometry, &geometry_len), 0);
if (strcmp (geometry, grids[igrid]))
{
if (strcmp (geometry, grids[igrid])) {
printf ("Geometry is incorrect\n");
abort ();
return 1;
}
GRIB_CHECK (grib_handle_delete (h), 0);
}
}
}
free (trunc[1].values);
return 0;

View File

@ -860,8 +860,7 @@ int main (int argc, char * argv[])
GRIB_CHECK (grib_set_long (h, "Ncx", 8), 0);
GRIB_CHECK (grib_set_long (h, "Ncy", 8), 0);
if (igrid == 0)
{
if (igrid == 0) {
GRIB_CHECK (grib_set_double (h, "DxInMetres", 2500.00000000000), 0);
GRIB_CHECK (grib_set_double (h, "DyInMetres", 2500.00000000000), 0);
GRIB_CHECK (grib_set_double (h, "latitudeOfFirstGridPointInDegrees", 66.7684949529709), 0);
@ -875,8 +874,7 @@ int main (int argc, char * argv[])
GRIB_CHECK (grib_set_long (h, "projectionCentreFlag", 0), 0);
GRIB_CHECK (grib_set_long (h, "uvRelativeToGrid", 1), 0);
}
else if (igrid == 1)
{
else if (igrid == 1) {
GRIB_CHECK (grib_set_double (h, "latitudeOfFirstGridPointInDegrees", 67.9372009520603), 0);
GRIB_CHECK (grib_set_double (h, "longitudeOfFirstGridPointInDegrees", 25.1580207144963), 0);
GRIB_CHECK (grib_set_double (h, "LaDInDegrees", 0.), 0);
@ -885,8 +883,7 @@ int main (int argc, char * argv[])
GRIB_CHECK (grib_set_double (h, "orientationOfTheGridInDegrees", 0.), 0);
GRIB_CHECK (grib_set_long (h, "uvRelativeToGrid", 1), 0);
}
else if (igrid == 2)
{
else if (igrid == 2) {
GRIB_CHECK (grib_set_double (h, "DxInMetres", 2500.00000000000), 0);
GRIB_CHECK (grib_set_double (h, "DyInMetres", 2500.00000000000), 0);
GRIB_CHECK (grib_set_double (h, "latitudeOfFirstGridPointInDegrees", 67.9372009520603), 0);
@ -895,7 +892,6 @@ int main (int argc, char * argv[])
GRIB_CHECK (grib_set_double (h, "orientationOfTheGridInDegrees", 0.), 0);
}
GRIB_CHECK (grib_set_long (h, "NV", 0), 0);
GRIB_CHECK (grib_set_long (h, "year", 2009), 0);
GRIB_CHECK (grib_set_long (h, "month", 5), 0);
@ -915,8 +911,7 @@ int main (int argc, char * argv[])
len = 4096;
GRIB_CHECK (grib_set_double_array (h, "values", values, len), 0);
if (1)
{
if (1) {
char f[128];
FILE *fp;
size_t size;
@ -924,7 +919,8 @@ int main (int argc, char * argv[])
sprintf (f, "lam_gp_%s.grib", grids[igrid]);
fp = fopen (f, "w");
GRIB_CHECK (grib_get_message (h, &buffer, &size), 0);
if (fwrite (buffer, 1, size, fp) != size) {
if (fwrite (buffer, 1, size, fp) != size)
{
perror (f);
return 1;
}
@ -957,36 +953,30 @@ int main (int argc, char * argv[])
printf ("%s : %lf\n", grids[igrid], norm);
if (norm > 0.0001)
{
printf ("Error too large !\n");
abort ();
fprintf(stderr, "Error too large !\n");
return 1;
}
fclose (fp);
GRIB_CHECK (grib_get_long (h, "Nux", &Nux), 0);
GRIB_CHECK (grib_get_long (h, "Nuy", &Nuy), 0);
GRIB_CHECK (grib_get_long (h, "Ncx", &Ncx), 0);
GRIB_CHECK (grib_get_long (h, "Ncy", &Ncy), 0);
if (Nux != 53 || Nuy != 53 || Ncx != 8 || Ncy != 8)
{
printf ("Geometry is incorrect\n");
abort ();
if (Nux != 53 || Nuy != 53 || Ncx != 8 || Ncy != 8) {
fprintf(stderr, "Geometry is incorrect\n");
return 1;
}
geometry_len = 128;
GRIB_CHECK (grib_get_string (h, "gridType", geometry, &geometry_len), 0);
if (strcmp (geometry, grids[igrid]))
{
printf ("Geometry is incorrect\n");
abort ();
if (strcmp (geometry, grids[igrid])) {
fprintf(stderr, "Geometry is incorrect\n");
return 1;
}
GRIB_CHECK (grib_handle_delete (h), 0);
}
}
return 0;
}