From 69841d460b2d262ab453a0d2a59ca5d4b32adb09 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 21 Aug 2017 18:11:40 +0100 Subject: [PATCH] Testing: bufr keys iterator, all vs data keys --- tests/bufr_keys_iter.c | 28 +++++-- tests/bufr_keys_iter.sh | 170 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 192 insertions(+), 6 deletions(-) diff --git a/tests/bufr_keys_iter.c b/tests/bufr_keys_iter.c index fd34ab8fd..874562ec9 100644 --- a/tests/bufr_keys_iter.c +++ b/tests/bufr_keys_iter.c @@ -13,10 +13,13 @@ void usage(const char* prog) { - printf("usage: %s infile\n",prog); + printf("usage: %s [-a|-d] infile\n",prog); exit(1); } +#define ITER_ALL_KEYS 1 +#define ITER_DATA_KEYS 2 + int main(int argc,char* argv[]) { int err = 0; @@ -24,19 +27,34 @@ int main(int argc,char* argv[]) codes_bufr_keys_iterator* kiter = NULL; char* input_filename = NULL; FILE* f = NULL; + int iterator_mode = ITER_ALL_KEYS; /*grib_context* c = grib_context_get_default();*/ - if (argc!=2) usage(argv[0]); - input_filename = argv[1]; + if (argc!=3) usage(argv[0]); + if (strcmp(argv[1], "-a")==0) { + iterator_mode = ITER_ALL_KEYS; + } else if (strcmp(argv[1], "-d")==0) { + iterator_mode = ITER_DATA_KEYS; + } else { + assert(!"Invalid mode"); + } + + input_filename = argv[2]; f = fopen(input_filename, "r"); assert(f); h = codes_handle_new_from_file(NULL, f, PRODUCT_BUFR, &err); assert(h); CODES_CHECK(codes_set_long(h,"unpack",1), 0); + + if (iterator_mode == ITER_ALL_KEYS) { + /*printf("Dumping ALL keys\n");*/ + kiter = codes_bufr_keys_iterator_new(h, 0); + } else { + /*printf("Dumping only DATA SECTION keys\n");*/ + kiter=codes_bufr_data_section_keys_iterator_new(h); + } - /*kiter=codes_bufr_data_section_keys_iterator_new(h);*/ - kiter = codes_bufr_keys_iterator_new(h, 0); while(codes_bufr_keys_iterator_next(kiter)) { char* kname = codes_bufr_keys_iterator_get_name(kiter); diff --git a/tests/bufr_keys_iter.sh b/tests/bufr_keys_iter.sh index 4cfa1a434..18ac7359f 100755 --- a/tests/bufr_keys_iter.sh +++ b/tests/bufr_keys_iter.sh @@ -14,7 +14,10 @@ tempOut=temp.bufr_keys_iter.$$.out tempRef=temp.bufr_keys_iter.$$.ref input=${data_dir}/bufr/aaen_55.bufr -${test_dir}/bufr_keys_iter $input > $tempOut + +## Iterate over ALL keys and skip none +# ------------------------------------ +${test_dir}/bufr_keys_iter -a $input > $tempOut # Check the output of BUFR keys iterator # Note: the two hidden keys 'typicalDate' and 'typicalTime' are NOT in the iterator output @@ -225,4 +228,169 @@ EOF diff $tempRef $tempOut +## Now iterate over Data Section keys and skip all others +# --------------------------------------------------------- +${test_dir}/bufr_keys_iter -d $input > $tempOut +cat > $tempRef<