mirror of https://github.com/ecmwf/eccodes.git
Get rid of the NUMBER macro
This commit is contained in:
parent
c7374ce82c
commit
80b06beee8
|
@ -71,8 +71,6 @@ static struct table_entry table[] = {
|
||||||
};
|
};
|
||||||
#endif /* ACCESSOR_FACTORY_USE_TRIE */
|
#endif /* ACCESSOR_FACTORY_USE_TRIE */
|
||||||
|
|
||||||
#define NUMBER(x) (sizeof(x) / sizeof(x[0]))
|
|
||||||
|
|
||||||
grib_section* grib_create_root_section(const grib_context* context, grib_handle* h)
|
grib_section* grib_create_root_section(const grib_context* context, grib_handle* h)
|
||||||
{
|
{
|
||||||
char* fpath = 0;
|
char* fpath = 0;
|
||||||
|
@ -113,7 +111,7 @@ static GRIB_INLINE grib_accessor_class* get_class(grib_context* c, char* type)
|
||||||
if ((the_class = (grib_accessor_class**)grib_trie_get(c->classes, type)) != NULL)
|
if ((the_class = (grib_accessor_class**)grib_trie_get(c->classes, type)) != NULL)
|
||||||
return *(the_class);
|
return *(the_class);
|
||||||
|
|
||||||
table_count = NUMBER(table);
|
const int table_count = sizeof(table) / sizeof(table[0]);
|
||||||
for (i = 0; i < table_count; i++) {
|
for (i = 0; i < table_count; i++) {
|
||||||
if (grib_inline_strcmp(type, table[i].type) == 0) {
|
if (grib_inline_strcmp(type, table[i].type) == 0) {
|
||||||
grib_trie_insert(c->classes, type, table[i].cclass);
|
grib_trie_insert(c->classes, type, table[i].cclass);
|
||||||
|
|
|
@ -275,7 +275,6 @@ static int proj_mercator(grib_handle* h, char* result)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define NUMBER(a) (sizeof(a) / sizeof(a[0]))
|
|
||||||
static proj_mapping proj_mappings[] = {
|
static proj_mapping proj_mappings[] = {
|
||||||
{ "regular_ll", &proj_unprojected },
|
{ "regular_ll", &proj_unprojected },
|
||||||
{ "regular_gg", &proj_unprojected },
|
{ "regular_gg", &proj_unprojected },
|
||||||
|
@ -308,7 +307,8 @@ static int unpack_string(grib_accessor* a, char* v, size_t* len)
|
||||||
err = grib_get_string(h, self->grid_type, grid_type, &size);
|
err = grib_get_string(h, self->grid_type, grid_type, &size);
|
||||||
if (err) return err;
|
if (err) return err;
|
||||||
|
|
||||||
for (i = 0; !found && i < NUMBER(proj_mappings); ++i) {
|
const size_t num_proj_mappings = sizeof(proj_mappings) / sizeof(proj_mappings[0]);
|
||||||
|
for (i = 0; !found && i < num_proj_mappings; ++i) {
|
||||||
proj_mapping pm = proj_mappings[i];
|
proj_mapping pm = proj_mappings[i];
|
||||||
if (strcmp(grid_type, pm.gridType) == 0) {
|
if (strcmp(grid_type, pm.gridType) == 0) {
|
||||||
found = 1;
|
found = 1;
|
||||||
|
|
|
@ -26,12 +26,11 @@ static struct table_entry table[] = {
|
||||||
#include "grib_dumper_factory.h"
|
#include "grib_dumper_factory.h"
|
||||||
};
|
};
|
||||||
|
|
||||||
#define NUMBER(x) (sizeof(x) / sizeof(x[0]))
|
|
||||||
|
|
||||||
grib_dumper* grib_dumper_factory(const char* op, const grib_handle* h, FILE* out, unsigned long option_flags, void* arg)
|
grib_dumper* grib_dumper_factory(const char* op, const grib_handle* h, FILE* out, unsigned long option_flags, void* arg)
|
||||||
{
|
{
|
||||||
int i;
|
size_t i = 0;
|
||||||
for (i = 0; i < NUMBER(table); i++)
|
const size_t num_table_entries = sizeof(table) / sizeof(table[0]);
|
||||||
|
for (i = 0; i < num_table_entries; i++)
|
||||||
if (strcmp(op, table[i].type) == 0) {
|
if (strcmp(op, table[i].type) == 0) {
|
||||||
grib_dumper_class* c = *(table[i].cclass);
|
grib_dumper_class* c = *(table[i].cclass);
|
||||||
grib_dumper* d = (grib_dumper*)grib_context_malloc_clear(h->context, c->size);
|
grib_dumper* d = (grib_dumper*)grib_context_malloc_clear(h->context, c->size);
|
||||||
|
@ -83,7 +82,8 @@ void grib_dump_content(const grib_handle* h, FILE* f, const char* mode, unsigned
|
||||||
dumper = grib_dumper_factory(mode ? mode : "serialize", h, f, flags, data);
|
dumper = grib_dumper_factory(mode ? mode : "serialize", h, f, flags, data);
|
||||||
if (!dumper) {
|
if (!dumper) {
|
||||||
fprintf(stderr, "Here are some possible values for the dumper mode:\n");
|
fprintf(stderr, "Here are some possible values for the dumper mode:\n");
|
||||||
for (size_t i = 0; i < NUMBER(table); i++) {
|
const size_t num_table_entries = sizeof(table) / sizeof(table[0]);
|
||||||
|
for (size_t i = 0; i < num_table_entries; i++) {
|
||||||
const char* t = table[i].type;
|
const char* t = table[i].type;
|
||||||
if (strstr(t, "bufr") == NULL && strstr(t, "grib") == NULL) {
|
if (strstr(t, "bufr") == NULL && strstr(t, "grib") == NULL) {
|
||||||
fprintf(stderr, "\t%s\n", t);
|
fprintf(stderr, "\t%s\n", t);
|
||||||
|
|
|
@ -94,12 +94,11 @@ static const char *errors[] = {
|
||||||
"Assertion failure", /* -79 GRIB_ASSERTION_FAILURE */
|
"Assertion failure", /* -79 GRIB_ASSERTION_FAILURE */
|
||||||
};
|
};
|
||||||
|
|
||||||
#define NUMBER(a) sizeof(a)/sizeof(a[0])
|
|
||||||
|
|
||||||
const char* grib_get_error_message(int code)
|
const char* grib_get_error_message(int code)
|
||||||
{
|
{
|
||||||
code = -code;
|
code = -code;
|
||||||
if (code < 0 || code >= NUMBER(errors)) {
|
const int num_errors = int( sizeof(errors)/sizeof(errors[0]) );
|
||||||
|
if (code < 0 || code >= num_errors) {
|
||||||
static char mess[64];
|
static char mess[64];
|
||||||
snprintf(mess, sizeof(mess), "Unknown error %d", code);
|
snprintf(mess, sizeof(mess), "Unknown error %d", code);
|
||||||
return mess;
|
return mess;
|
||||||
|
|
|
@ -15,12 +15,11 @@ static const char *errors[] = {
|
||||||
!ERRORS go in here
|
!ERRORS go in here
|
||||||
};
|
};
|
||||||
|
|
||||||
#define NUMBER(a) sizeof(a)/sizeof(a[0])
|
|
||||||
|
|
||||||
const char* grib_get_error_message(int code)
|
const char* grib_get_error_message(int code)
|
||||||
{
|
{
|
||||||
code = -code;
|
code = -code;
|
||||||
if (code < 0 || code >= NUMBER(errors)) {
|
const int num_errors = int( sizeof(errors)/sizeof(errors[0]) );
|
||||||
|
if (code < 0 || code >= num_errors) {
|
||||||
static char mess[64];
|
static char mess[64];
|
||||||
snprintf(mess, sizeof(mess), "Unknown error %d", code);
|
snprintf(mess, sizeof(mess), "Unknown error %d", code);
|
||||||
return mess;
|
return mess;
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#define NUMBER(x) (sizeof(x) / sizeof(x[0]))
|
|
||||||
#define MAXITER 10
|
#define MAXITER 10
|
||||||
|
|
||||||
#define RAD2DEG 57.29577951308232087684 /* 180 over pi */
|
#define RAD2DEG 57.29577951308232087684 /* 180 over pi */
|
||||||
|
@ -28,7 +27,7 @@
|
||||||
|
|
||||||
static void gauss_first_guess(long trunc, double* vals)
|
static void gauss_first_guess(long trunc, double* vals)
|
||||||
{
|
{
|
||||||
long i = 0, numVals;
|
long i = 0, numVals;
|
||||||
static double gvals[] = {
|
static double gvals[] = {
|
||||||
2.4048255577E0,
|
2.4048255577E0,
|
||||||
5.5200781103E0,
|
5.5200781103E0,
|
||||||
|
@ -82,7 +81,7 @@ static void gauss_first_guess(long trunc, double* vals)
|
||||||
156.2950342685E0,
|
156.2950342685E0,
|
||||||
};
|
};
|
||||||
|
|
||||||
numVals = NUMBER(gvals);
|
numVals = sizeof(gvals) / sizeof(gvals[0]);
|
||||||
for (i = 0; i < trunc; i++) {
|
for (i = 0; i < trunc; i++) {
|
||||||
if (i < numVals)
|
if (i < numVals)
|
||||||
vals[i] = gvals[i];
|
vals[i] = gvals[i];
|
||||||
|
|
|
@ -15,8 +15,6 @@
|
||||||
|
|
||||||
#include "grib_api_internal.h"
|
#include "grib_api_internal.h"
|
||||||
|
|
||||||
#define NUMBER(x) (sizeof(x) / sizeof(x[0]))
|
|
||||||
|
|
||||||
/* This file is generated by ./make_class.pl */
|
/* This file is generated by ./make_class.pl */
|
||||||
#include "grib_iterator_class.h"
|
#include "grib_iterator_class.h"
|
||||||
|
|
||||||
|
@ -33,11 +31,12 @@ static const struct table_entry table[] = {
|
||||||
|
|
||||||
grib_iterator* grib_iterator_factory(grib_handle* h, grib_arguments* args, unsigned long flags, int* error)
|
grib_iterator* grib_iterator_factory(grib_handle* h, grib_arguments* args, unsigned long flags, int* error)
|
||||||
{
|
{
|
||||||
size_t i = 0;
|
size_t i = 0, num_table_entries = 0;
|
||||||
const char* type = (char*)grib_arguments_get_name(h, args, 0);
|
const char* type = (char*)grib_arguments_get_name(h, args, 0);
|
||||||
*error = GRIB_NOT_IMPLEMENTED;
|
*error = GRIB_NOT_IMPLEMENTED;
|
||||||
|
|
||||||
for (i = 0; i < NUMBER(table); i++) {
|
num_table_entries = sizeof(table) / sizeof(table[0]);
|
||||||
|
for (i = 0; i < num_table_entries; i++) {
|
||||||
if (strcmp(type, table[i].type) == 0) {
|
if (strcmp(type, table[i].type) == 0) {
|
||||||
grib_iterator_class* c = *(table[i].cclass);
|
grib_iterator_class* c = *(table[i].cclass);
|
||||||
grib_iterator* it = (grib_iterator*)grib_context_malloc_clear(h->context, c->size);
|
grib_iterator* it = (grib_iterator*)grib_context_malloc_clear(h->context, c->size);
|
||||||
|
|
|
@ -10,8 +10,6 @@
|
||||||
|
|
||||||
#include "grib_api_internal.h"
|
#include "grib_api_internal.h"
|
||||||
|
|
||||||
#define NUMBER(x) (sizeof(x) / sizeof(x[0]))
|
|
||||||
|
|
||||||
/* This file is generated by ./make_class.pl */
|
/* This file is generated by ./make_class.pl */
|
||||||
#include "grib_nearest_class.h"
|
#include "grib_nearest_class.h"
|
||||||
|
|
||||||
|
@ -28,11 +26,12 @@ static const struct table_entry table[] = {
|
||||||
|
|
||||||
grib_nearest* grib_nearest_factory(grib_handle* h, grib_arguments* args, int* error)
|
grib_nearest* grib_nearest_factory(grib_handle* h, grib_arguments* args, int* error)
|
||||||
{
|
{
|
||||||
size_t i = 0;
|
size_t i = 0, num_table_entries = 0;
|
||||||
*error = GRIB_NOT_IMPLEMENTED;
|
*error = GRIB_NOT_IMPLEMENTED;
|
||||||
char* type = (char*)grib_arguments_get_name(h, args, 0);
|
char* type = (char*)grib_arguments_get_name(h, args, 0);
|
||||||
|
|
||||||
for (i = 0; i < NUMBER(table); i++) {
|
num_table_entries = sizeof(table) / sizeof(table[0]);
|
||||||
|
for (i = 0; i < num_table_entries; i++) {
|
||||||
if (strcmp(type, table[i].type) == 0) {
|
if (strcmp(type, table[i].type) == 0) {
|
||||||
grib_nearest_class* c = *(table[i].cclass);
|
grib_nearest_class* c = *(table[i].cclass);
|
||||||
grib_nearest* it = (grib_nearest*)grib_context_malloc_clear(h->context, c->size);
|
grib_nearest* it = (grib_nearest*)grib_context_malloc_clear(h->context, c->size);
|
||||||
|
|
|
@ -25,12 +25,10 @@
|
||||||
// size_t size;
|
// size_t size;
|
||||||
// } grib_templates;
|
// } grib_templates;
|
||||||
|
|
||||||
// #define NUMBER(x) (sizeof(x) / sizeof(x[0]))
|
|
||||||
// grib_handle* grib_internal_sample(grib_context* c,const char* name)
|
// grib_handle* grib_internal_sample(grib_context* c,const char* name)
|
||||||
// {
|
// {
|
||||||
// size_t i;
|
// size_t i;
|
||||||
// const size_t num_samples = NUMBER(templates);
|
// const size_t num_samples = sizeof(templates) / sizeof(templates[0]);
|
||||||
// Assert(0);
|
|
||||||
// for(i = 0; i < num_samples; i++)
|
// for(i = 0; i < num_samples; i++)
|
||||||
// if(strcmp(name,templates[i].name) == 0)
|
// if(strcmp(name,templates[i].name) == 0)
|
||||||
// return grib_handle_new_from_message_copy(c,templates[i].data,templates[i].size);
|
// return grib_handle_new_from_message_copy(c,templates[i].data,templates[i].size);
|
||||||
|
|
|
@ -1862,13 +1862,11 @@ int parse_keyval_string(const char* grib_tool,
|
||||||
// Return 1 if the productDefinitionTemplateNumber (GRIB2) is for EPS (ensemble) products
|
// Return 1 if the productDefinitionTemplateNumber (GRIB2) is for EPS (ensemble) products
|
||||||
int grib2_is_PDTN_EPS(long pdtn)
|
int grib2_is_PDTN_EPS(long pdtn)
|
||||||
{
|
{
|
||||||
#define NUMBER(x) (sizeof(x) / sizeof(x[0]))
|
|
||||||
|
|
||||||
static int eps_pdtns[] = { 1, 11, 33, 34, 41, 43, 45, 47,
|
static int eps_pdtns[] = { 1, 11, 33, 34, 41, 43, 45, 47,
|
||||||
49, 54, 56, 58, 59, 60, 61, 63, 68, 71, 73, 77, 79,
|
49, 54, 56, 58, 59, 60, 61, 63, 68, 71, 73, 77, 79,
|
||||||
81, 83, 84, 85, 92, 94, 96, 98 };
|
81, 83, 84, 85, 92, 94, 96, 98 };
|
||||||
size_t i;
|
size_t i = 0, num_epss = (sizeof(eps_pdtns) / sizeof(eps_pdtns[0]));
|
||||||
for (i = 0; i < NUMBER(eps_pdtns); ++i) {
|
for (i = 0; i < num_epss; ++i) {
|
||||||
if (eps_pdtns[i] == pdtn) return 1;
|
if (eps_pdtns[i] == pdtn) return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue