2022-11-04 16:55:18 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2005- ECMWF.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2022-06-17 17:58:21 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2022-07-29 12:21:04 +00:00
|
|
|
#include "grib_api_internal.h"
|
2022-06-17 17:58:21 +00:00
|
|
|
|
2024-01-18 12:39:37 +00:00
|
|
|
#define MAX_VAL_LEN 1024
|
|
|
|
|
2022-06-17 17:58:21 +00:00
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2022-07-29 12:21:04 +00:00
|
|
|
grib_handle* h = NULL;
|
2024-11-01 18:32:20 +00:00
|
|
|
int err = 0;
|
2022-06-17 17:58:21 +00:00
|
|
|
|
2022-07-29 12:21:04 +00:00
|
|
|
Assert(argc == 2);
|
2024-11-01 18:32:20 +00:00
|
|
|
FILE* f = fopen(argv[1], "rb");
|
2022-07-29 12:21:04 +00:00
|
|
|
Assert(f);
|
2022-06-17 17:58:21 +00:00
|
|
|
|
2022-07-29 12:21:04 +00:00
|
|
|
while ((h = grib_handle_new_from_file(0, f, &err)) != NULL) {
|
|
|
|
grib_keys_iterator* kiter = NULL;
|
2022-06-17 17:58:21 +00:00
|
|
|
|
|
|
|
/* Use namespace of NULL to get ALL keys */
|
2022-06-17 18:40:01 +00:00
|
|
|
/* Set flags to 0 to not filter any keys */
|
2022-07-29 12:21:04 +00:00
|
|
|
kiter = grib_keys_iterator_new(h, /*flags=*/0, /*namespace=*/NULL);
|
|
|
|
Assert(kiter);
|
2022-06-17 17:58:21 +00:00
|
|
|
|
2022-07-29 12:21:04 +00:00
|
|
|
while (grib_keys_iterator_next(kiter)) {
|
|
|
|
const char* name = grib_keys_iterator_get_name(kiter);
|
|
|
|
Assert(name);
|
2024-01-18 11:57:27 +00:00
|
|
|
int type = 0;
|
|
|
|
GRIB_CHECK(grib_get_native_type(h, name, &type), 0);
|
|
|
|
Assert( type > 0 && type < 7 );
|
2024-11-01 18:32:20 +00:00
|
|
|
int ktype = grib_keys_iterator_get_native_type(kiter);
|
|
|
|
Assert(type == ktype);
|
2024-01-18 11:57:27 +00:00
|
|
|
const char* type_name = grib_get_type_name(type);
|
|
|
|
Assert( !STR_EQUAL(type_name, "unknown") );
|
|
|
|
printf("%s = %s (%d)\n", name, type_name, type);
|
2024-01-18 12:39:37 +00:00
|
|
|
|
|
|
|
if (STR_EQUAL(type_name, "label")) {
|
|
|
|
char value[MAX_VAL_LEN] = {0,};
|
|
|
|
size_t vlen = MAX_VAL_LEN;
|
|
|
|
GRIB_CHECK(grib_get_string(h, name, value, &vlen), name);
|
|
|
|
Assert( strlen(value) > 0 );
|
2024-11-01 18:32:20 +00:00
|
|
|
int e = grib_keys_iterator_get_string(kiter, value, &vlen);
|
|
|
|
Assert(!e);
|
|
|
|
Assert( STR_EQUAL(name, value) );
|
|
|
|
}
|
|
|
|
if (STR_EQUAL(name, "editionNumber")) {
|
|
|
|
long lVal = 0;
|
|
|
|
size_t llen = 1;
|
|
|
|
int e = grib_keys_iterator_get_long(kiter, &lVal, &llen);
|
|
|
|
Assert(!e);
|
|
|
|
Assert(lVal == 1 || lVal == 2);
|
2024-01-18 12:39:37 +00:00
|
|
|
}
|
2022-06-17 17:58:21 +00:00
|
|
|
}
|
|
|
|
|
2022-07-29 12:21:04 +00:00
|
|
|
grib_keys_iterator_delete(kiter);
|
|
|
|
grib_handle_delete(h);
|
2022-06-17 17:58:21 +00:00
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
return 0;
|
|
|
|
}
|