eccodes/tools/mars_request.c

60 lines
1.4 KiB
C
Raw Normal View History

2013-03-25 12:04:10 +00:00
/*
2019-04-15 13:44:45 +00:00
* Copyright 2005-2019 ECMWF.
2013-03-25 12:04:10 +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.
*/
#include <stdio.h>
#include <string.h>
#include "grib_api.h"
2020-01-22 13:10:59 +00:00
static void usage(const char* prog)
2013-03-25 12:04:10 +00:00
{
2020-01-22 13:10:59 +00:00
fprintf(stderr, "%s: file\n", prog);
exit(1);
2013-03-25 12:04:10 +00:00
}
2020-01-22 13:10:59 +00:00
int main(int argc, const char* argv[])
2013-03-25 12:04:10 +00:00
{
2020-01-22 13:10:59 +00:00
FILE* in;
int e;
grib_handle* h;
2013-03-25 12:04:10 +00:00
2020-01-22 13:10:59 +00:00
if (argc != 2)
usage(argv[0]);
2013-03-25 12:04:10 +00:00
2020-01-22 13:10:59 +00:00
in = fopen(argv[argc - 1], "r");
if (!in) {
perror(argv[argc - 1]);
exit(1);
}
2013-03-25 12:04:10 +00:00
2020-01-22 13:10:59 +00:00
while ((h = grib_handle_new_from_file(NULL, in, &e)) != NULL) {
grib_keys_iterator* i = grib_keys_iterator_new(h, GRIB_KEYS_ITERATOR_ALL_KEYS, "mars");
2013-03-25 12:04:10 +00:00
2020-01-22 13:10:59 +00:00
while (grib_keys_iterator_next(i)) {
char value[1024];
size_t len = sizeof(value);
const char* name;
2013-03-25 12:04:10 +00:00
2020-01-22 13:10:59 +00:00
name = grib_keys_iterator_get_name(i);
GRIB_CHECK(grib_get_string(h, name, value, &len), 0);
2013-03-25 12:04:10 +00:00
2020-01-22 13:10:59 +00:00
printf("%s = %s\n", name, value);
}
2013-03-25 12:04:10 +00:00
2020-01-22 13:10:59 +00:00
grib_keys_iterator_delete(i);
grib_handle_delete(h);
}
2013-03-25 12:04:10 +00:00
2020-01-22 13:10:59 +00:00
GRIB_CHECK(e, argv[argc - 1]);
2013-03-25 12:04:10 +00:00
2020-01-22 13:10:59 +00:00
return 0;
2013-03-25 12:04:10 +00:00
}