2023-12-07 15:46:03 +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.
|
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "grib_api_internal.h"
|
|
|
|
|
|
|
|
#undef NDEBUG
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2024-12-20 12:58:07 +00:00
|
|
|
ECCODES_ASSERT(argc == 1);
|
2023-12-07 15:46:03 +00:00
|
|
|
grib_handle* h = grib_handle_new_from_samples(0, "GRIB2");
|
|
|
|
|
|
|
|
code_table_entry* entries = NULL;
|
|
|
|
size_t num_entries = 0;
|
|
|
|
int err = codes_codetable_get_contents_malloc(h, "indicatorOfUnitOfTimeRange", &entries, &num_entries);
|
2024-12-20 12:58:07 +00:00
|
|
|
ECCODES_ASSERT(!err);
|
|
|
|
ECCODES_ASSERT(entries != NULL);
|
|
|
|
ECCODES_ASSERT(num_entries == 256);
|
2023-12-07 15:46:03 +00:00
|
|
|
|
|
|
|
for (size_t i=0; i<num_entries;++i) {
|
|
|
|
const char* abbrev = entries[i].abbreviation;
|
|
|
|
const char* title = entries[i].title;
|
|
|
|
if (abbrev) {
|
2024-12-20 12:58:07 +00:00
|
|
|
ECCODES_ASSERT(title != NULL);
|
2023-12-07 15:46:03 +00:00
|
|
|
printf(" i=%zu |%s| |%s|\n", i, abbrev, title);
|
|
|
|
} else {
|
2024-12-20 12:58:07 +00:00
|
|
|
ECCODES_ASSERT(title == NULL);
|
2023-12-07 15:46:03 +00:00
|
|
|
}
|
|
|
|
}
|
2024-12-20 12:58:07 +00:00
|
|
|
ECCODES_ASSERT( STR_EQUAL(entries[13].abbreviation, "s") );
|
|
|
|
ECCODES_ASSERT( STR_EQUAL(entries[13].title, "Second") );
|
2023-12-07 15:46:03 +00:00
|
|
|
free(entries);
|
|
|
|
entries = NULL;
|
|
|
|
|
|
|
|
// Check a given code is in the table
|
|
|
|
err = codes_codetable_check_code_figure(h, "indicatorOfUnitOfTimeRange", 7); //century
|
2024-12-20 12:58:07 +00:00
|
|
|
ECCODES_ASSERT(err == GRIB_SUCCESS);
|
2023-12-07 15:46:03 +00:00
|
|
|
err = codes_codetable_check_code_figure(h, "indicatorOfUnitOfTimeRange", 255); //missing
|
2024-12-20 12:58:07 +00:00
|
|
|
ECCODES_ASSERT(err == GRIB_SUCCESS);
|
2023-12-07 15:46:03 +00:00
|
|
|
err = codes_codetable_check_code_figure(h, "indicatorOfUnitOfTimeRange", -1); //-ve code
|
2024-12-20 12:58:07 +00:00
|
|
|
ECCODES_ASSERT(err == GRIB_OUT_OF_RANGE);
|
2023-12-07 15:46:03 +00:00
|
|
|
err = codes_codetable_check_code_figure(h, "indicatorOfUnitOfTimeRange", 666); //out of bounds
|
2024-12-20 12:58:07 +00:00
|
|
|
ECCODES_ASSERT(err == GRIB_OUT_OF_RANGE);
|
2023-12-07 15:46:03 +00:00
|
|
|
err = codes_codetable_check_code_figure(h, "indicatorOfUnitOfTimeRange", 200); // entry not present
|
2024-12-20 12:58:07 +00:00
|
|
|
ECCODES_ASSERT(err == GRIB_INVALID_KEY_VALUE);
|
2023-12-07 15:46:03 +00:00
|
|
|
err = codes_codetable_check_code_figure(h, "American Pie", 0); // non-existent key
|
2024-12-20 12:58:07 +00:00
|
|
|
ECCODES_ASSERT(err == GRIB_NOT_FOUND);
|
2023-12-07 15:46:03 +00:00
|
|
|
err = codes_codetable_check_code_figure(h, "year", 0); // not a codetable key
|
2024-12-20 12:58:07 +00:00
|
|
|
ECCODES_ASSERT(err == GRIB_INVALID_ARGUMENT);
|
2023-12-07 15:46:03 +00:00
|
|
|
|
|
|
|
// Check a given abbreviation is in the table
|
|
|
|
err = codes_codetable_check_abbreviation(h, "indicatorOfUnitOfTimeRange", "15m"); // entry not present
|
2024-12-20 12:58:07 +00:00
|
|
|
ECCODES_ASSERT(err == GRIB_INVALID_KEY_VALUE);
|
2023-12-07 15:46:03 +00:00
|
|
|
err = codes_codetable_check_abbreviation(h, "indicatorOfUnitOfTimeRange", "D"); // Day
|
2024-12-20 12:58:07 +00:00
|
|
|
ECCODES_ASSERT(err == GRIB_SUCCESS);
|
2023-12-07 15:46:03 +00:00
|
|
|
err = codes_codetable_check_abbreviation(h, "centre", "ecmf");
|
2024-12-20 12:58:07 +00:00
|
|
|
ECCODES_ASSERT(err == GRIB_SUCCESS);
|
2023-12-07 15:46:03 +00:00
|
|
|
err = codes_codetable_check_abbreviation(h, "centre", "Smoke On The Water"); // non-existent key
|
2024-12-20 12:58:07 +00:00
|
|
|
ECCODES_ASSERT(err == GRIB_INVALID_KEY_VALUE);
|
2023-12-07 15:46:03 +00:00
|
|
|
|
|
|
|
// Now try a codetable key with 2 octets
|
|
|
|
err = codes_codetable_get_contents_malloc(h, "gridDefinitionTemplateNumber", &entries, &num_entries);
|
2024-12-20 12:58:07 +00:00
|
|
|
ECCODES_ASSERT(!err);
|
|
|
|
ECCODES_ASSERT(entries != NULL);
|
|
|
|
ECCODES_ASSERT(num_entries == 65536);
|
|
|
|
ECCODES_ASSERT( STR_EQUAL(entries[40].title, "Gaussian latitude/longitude") );
|
2023-12-07 15:46:03 +00:00
|
|
|
free(entries);
|
|
|
|
|
|
|
|
grib_handle_delete(h);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|