|
| 1 | +/* |
| 2 | + * (C) Copyright 2005- ECMWF. |
| 3 | + * |
| 4 | + * This software is licensed under the terms of the Apache Licence Version 2.0 |
| 5 | + * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. |
| 6 | + * |
| 7 | + * In applying this licence, ECMWF does not waive the privileges and immunities granted to it by |
| 8 | + * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. |
| 9 | + */ |
| 10 | + |
| 11 | +#undef NDEBUG |
| 12 | +#include <assert.h> |
| 13 | +#include "eccodes.h" |
| 14 | + |
| 15 | +#define MAX_VAL_LEN 1024 |
| 16 | + |
| 17 | +static void check_for_levelist(codes_handle* h, bool should_exist) |
| 18 | +{ |
| 19 | + codes_keys_iterator* kiter = codes_keys_iterator_new(h, 0, "mars"); |
| 20 | + bool mars_levelist_found = false; |
| 21 | + char value[MAX_VAL_LEN]; |
| 22 | + |
| 23 | + while (codes_keys_iterator_next(kiter)) { |
| 24 | + const char* name = codes_keys_iterator_get_name(kiter); |
| 25 | + size_t vlen = MAX_VAL_LEN; |
| 26 | + memset(value, 0, vlen); |
| 27 | + CODES_CHECK(codes_get_string(h, name, value, &vlen), name); |
| 28 | + // printf(" name=%s val=%s\n", name, value); |
| 29 | + if (strcmp(name, "levelist")) { |
| 30 | + mars_levelist_found = true; |
| 31 | + assert( strcmp(value, "42") ); |
| 32 | + } |
| 33 | + } |
| 34 | + assert( mars_levelist_found == should_exist ); |
| 35 | + codes_keys_iterator_delete(kiter); |
| 36 | +} |
| 37 | + |
| 38 | +int main(int argc, char* argv[]) |
| 39 | +{ |
| 40 | + codes_handle* h = grib_handle_new_from_samples(0, "GRIB2"); |
| 41 | + size_t alen = 1000; |
| 42 | + CODES_CHECK(codes_set_string(h, "typeOfLevel", "isobaricInhPa", &alen), 0); |
| 43 | + CODES_CHECK(codes_set_long(h, "level", 42), 0); |
| 44 | + //codes_dump_content(h, stdout, "wmo", GRIB_DUMP_FLAG_CODED | GRIB_DUMP_FLAG_OCTET | GRIB_DUMP_FLAG_VALUES | GRIB_DUMP_FLAG_READ_ONLY, 0); |
| 45 | + check_for_levelist(h, true); |
| 46 | + |
| 47 | + // TODO(maee): This is related to |
| 48 | + // ECC-1898: GRIB: Key 'levelist' persists despite being taken out of the mars namespace |
| 49 | + // Once the bug is fixed we should remove the comments |
| 50 | + // alen = 1000; |
| 51 | + // CODES_CHECK(codes_set_string(h, "typeOfLevel", "surface", &alen), 0); |
| 52 | + // CODES_CHECK(codes_set_missing(h, "scaleFactorOfFirstFixedSurface"), 0); |
| 53 | + // CODES_CHECK(codes_set_missing(h, "scaledValueOfFirstFixedSurface"), 0); |
| 54 | + // check_for_levelist(h, false); |
| 55 | + |
| 56 | + codes_handle_delete(h); |
| 57 | + |
| 58 | + return 0; |
| 59 | +} |
0 commit comments