ECC-1611: Test non-coordinate keys too

This commit is contained in:
Shahram Najm 2023-06-15 10:48:31 +01:00
parent 815f3dfd4a
commit 30673fd961
1 changed files with 26 additions and 13 deletions

View File

@ -12,15 +12,18 @@
#undef NDEBUG
#include <assert.h>
// Get the X part of a BUFR descriptor (FXY) and determine if it
// is a coordinate.
// See https://confluence.ecmwf.int/display/UDOC/What+are+coordinate+descriptors+-+ecCodes+BUFR+FAQ
static int is_coord_using_Xcode(const char* X)
{
if (strcmp(X, "01")==0) return 1;
if (strcmp(X, "02")==0) return 1;
if (strcmp(X, "04")==0) return 1;
if (strcmp(X, "05")==0) return 1;
if (strcmp(X, "06")==0) return 1;
if (strcmp(X, "07")==0) return 1;
if (strcmp(X, "08")==0) return 1;
if (strcmp(X, "01") == 0) return 1;
if (strcmp(X, "02") == 0) return 1;
if (strcmp(X, "04") == 0) return 1;
if (strcmp(X, "05") == 0) return 1;
if (strcmp(X, "06") == 0) return 1;
if (strcmp(X, "07") == 0) return 1;
if (strcmp(X, "08") == 0) return 1;
return 0;
}
@ -30,6 +33,7 @@ int main(int argc, char* argv[])
codes_handle* h = NULL;
char* filename = NULL;
FILE* fin = NULL;
int is_coord = 0;
assert (argc == 2);
filename = argv[1];
@ -52,12 +56,12 @@ int main(int argc, char* argv[])
snprintf(name1, 256, "%s->code", name);
int error = codes_get_string(h, name1, scode, &slen);
if (!error) {
assert( strlen(scode)==6);
assert(strlen(scode) == 6);
X[0] = scode[1];
X[1] = scode[2];
X[2] = 0;
int is_X_coord = is_coord_using_Xcode(X);
int is_coord = codes_bufr_key_is_coordinate(h, name, &error);
is_coord = codes_bufr_key_is_coordinate(h, name, &error);
assert(!error);
if (is_coord != is_X_coord) {
fprintf(stderr, "ERROR: %s X=%s is_coord=%d is_X_coord=%d\n", name, X, is_coord, is_X_coord);
@ -65,7 +69,16 @@ int main(int argc, char* argv[])
}
}
}
else {
// header keys cannot be coordinate descriptors
is_coord = codes_bufr_key_is_coordinate(h, name, &err);
assert(!is_coord);
}
}
is_coord = codes_bufr_key_is_coordinate(h, "nosuchkey", &err);
assert(err == CODES_NOT_FOUND);
codes_bufr_keys_iterator_delete(kiter);
codes_handle_delete(h);
}