2016-10-24 16:34:12 +00:00
|
|
|
/*
|
2020-01-28 14:32:34 +00:00
|
|
|
* (C) Copyright 2005- ECMWF.
|
2016-10-24 16:34:12 +00:00
|
|
|
*
|
|
|
|
* This software is licensed under the terms of the Apache Licence Version 2.0
|
|
|
|
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
|
|
|
|
*
|
|
|
|
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
|
|
|
|
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
|
|
|
|
*/
|
2019-11-07 12:03:45 +00:00
|
|
|
|
2016-10-24 16:34:12 +00:00
|
|
|
#include "eccodes.h"
|
2022-08-01 11:00:29 +00:00
|
|
|
#undef NDEBUG
|
2016-10-24 16:34:12 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
2020-01-29 12:05:02 +00:00
|
|
|
#define ITER_ALL_KEYS 1
|
2017-08-21 17:11:40 +00:00
|
|
|
#define ITER_DATA_KEYS 2
|
|
|
|
|
2020-01-29 12:05:02 +00:00
|
|
|
int main(int argc, char* argv[])
|
2016-10-24 16:34:12 +00:00
|
|
|
{
|
2020-01-29 12:05:02 +00:00
|
|
|
int err = 0;
|
|
|
|
int i = 0;
|
|
|
|
codes_handle* h = NULL;
|
2017-02-03 15:44:03 +00:00
|
|
|
codes_bufr_keys_iterator* kiter = NULL;
|
2020-01-29 12:05:02 +00:00
|
|
|
char* input_filename = NULL;
|
|
|
|
FILE* f = NULL;
|
|
|
|
int iterator_mode = ITER_ALL_KEYS;
|
2018-12-10 16:48:36 +00:00
|
|
|
|
|
|
|
if (argc == 1 || argc > 3)
|
2024-03-04 20:45:39 +00:00
|
|
|
return 1; // usage: prog [-a|-d] infile
|
2018-12-10 16:48:36 +00:00
|
|
|
|
|
|
|
for (i = 1; i < argc; i++) {
|
2020-01-29 12:05:02 +00:00
|
|
|
if (strcmp(argv[i], "-a") == 0) {
|
2018-12-10 16:48:36 +00:00
|
|
|
iterator_mode = ITER_ALL_KEYS;
|
2020-01-29 12:05:02 +00:00
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "-d") == 0) {
|
2018-12-10 16:48:36 +00:00
|
|
|
iterator_mode = ITER_DATA_KEYS;
|
2020-01-29 12:05:02 +00:00
|
|
|
}
|
|
|
|
else {
|
2018-12-10 16:48:36 +00:00
|
|
|
input_filename = argv[i];
|
2020-01-29 12:05:02 +00:00
|
|
|
break; /* Only 1 file allowed */
|
2017-08-21 17:34:27 +00:00
|
|
|
}
|
2017-08-21 17:11:40 +00:00
|
|
|
}
|
2017-08-21 17:34:27 +00:00
|
|
|
|
2018-12-10 16:48:36 +00:00
|
|
|
assert(input_filename);
|
2019-02-28 12:19:28 +00:00
|
|
|
f = fopen(input_filename, "rb");
|
2016-10-24 16:34:12 +00:00
|
|
|
assert(f);
|
|
|
|
h = codes_handle_new_from_file(NULL, f, PRODUCT_BUFR, &err);
|
|
|
|
assert(h);
|
|
|
|
|
2020-01-29 12:05:02 +00:00
|
|
|
CODES_CHECK(codes_set_long(h, "unpack", 1), 0);
|
2018-12-10 16:48:36 +00:00
|
|
|
|
2017-08-21 17:11:40 +00:00
|
|
|
if (iterator_mode == ITER_ALL_KEYS) {
|
|
|
|
/*printf("Dumping ALL keys\n");*/
|
|
|
|
kiter = codes_bufr_keys_iterator_new(h, 0);
|
2020-01-29 12:05:02 +00:00
|
|
|
}
|
|
|
|
else {
|
2017-08-21 17:11:40 +00:00
|
|
|
/*printf("Dumping only DATA SECTION keys\n");*/
|
2017-08-21 17:34:27 +00:00
|
|
|
assert(iterator_mode == ITER_DATA_KEYS);
|
2020-01-29 12:05:02 +00:00
|
|
|
kiter = codes_bufr_data_section_keys_iterator_new(h);
|
2017-08-21 17:11:40 +00:00
|
|
|
}
|
2016-10-24 16:34:12 +00:00
|
|
|
|
2020-01-29 12:05:02 +00:00
|
|
|
while (codes_bufr_keys_iterator_next(kiter)) {
|
2023-12-09 14:50:06 +00:00
|
|
|
const char* kname = codes_bufr_keys_iterator_get_name(kiter);
|
2016-10-24 16:34:12 +00:00
|
|
|
printf("%s\n", kname);
|
|
|
|
}
|
2017-01-26 15:50:09 +00:00
|
|
|
codes_bufr_keys_iterator_delete(kiter);
|
2016-11-29 16:57:51 +00:00
|
|
|
codes_handle_delete(h);
|
2020-12-31 18:10:07 +00:00
|
|
|
codes_context_delete(codes_context_get_default());
|
|
|
|
|
2016-10-24 16:34:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|