Get rid of the NUMBER macro

This commit is contained in:
Shahram Najm 2024-01-30 12:08:46 +00:00
parent c7374ce82c
commit 80b06beee8
10 changed files with 24 additions and 35 deletions

View File

@ -71,8 +71,6 @@ static struct table_entry table[] = {
};
#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)
{
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)
return *(the_class);
table_count = NUMBER(table);
const int table_count = sizeof(table) / sizeof(table[0]);
for (i = 0; i < table_count; i++) {
if (grib_inline_strcmp(type, table[i].type) == 0) {
grib_trie_insert(c->classes, type, table[i].cclass);

View File

@ -275,7 +275,6 @@ static int proj_mercator(grib_handle* h, char* result)
return err;
}
#define NUMBER(a) (sizeof(a) / sizeof(a[0]))
static proj_mapping proj_mappings[] = {
{ "regular_ll", &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);
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];
if (strcmp(grid_type, pm.gridType) == 0) {
found = 1;

View File

@ -26,12 +26,11 @@ static struct table_entry table[] = {
#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)
{
int i;
for (i = 0; i < NUMBER(table); i++)
size_t i = 0;
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) {
grib_dumper_class* c = *(table[i].cclass);
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);
if (!dumper) {
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;
if (strstr(t, "bufr") == NULL && strstr(t, "grib") == NULL) {
fprintf(stderr, "\t%s\n", t);

View File

@ -94,12 +94,11 @@ static const char *errors[] = {
"Assertion failure", /* -79 GRIB_ASSERTION_FAILURE */
};
#define NUMBER(a) sizeof(a)/sizeof(a[0])
const char* grib_get_error_message(int 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];
snprintf(mess, sizeof(mess), "Unknown error %d", code);
return mess;

View File

@ -15,12 +15,11 @@ static const char *errors[] = {
!ERRORS go in here
};
#define NUMBER(a) sizeof(a)/sizeof(a[0])
const char* grib_get_error_message(int 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];
snprintf(mess, sizeof(mess), "Unknown error %d", code);
return mess;

View File

@ -16,7 +16,6 @@
#include <cmath>
#include <algorithm>
#define NUMBER(x) (sizeof(x) / sizeof(x[0]))
#define MAXITER 10
#define RAD2DEG 57.29577951308232087684 /* 180 over pi */
@ -28,7 +27,7 @@
static void gauss_first_guess(long trunc, double* vals)
{
long i = 0, numVals;
long i = 0, numVals;
static double gvals[] = {
2.4048255577E0,
5.5200781103E0,
@ -82,7 +81,7 @@ static void gauss_first_guess(long trunc, double* vals)
156.2950342685E0,
};
numVals = NUMBER(gvals);
numVals = sizeof(gvals) / sizeof(gvals[0]);
for (i = 0; i < trunc; i++) {
if (i < numVals)
vals[i] = gvals[i];

View File

@ -15,8 +15,6 @@
#include "grib_api_internal.h"
#define NUMBER(x) (sizeof(x) / sizeof(x[0]))
/* This file is generated by ./make_class.pl */
#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)
{
size_t i = 0;
size_t i = 0, num_table_entries = 0;
const char* type = (char*)grib_arguments_get_name(h, args, 0);
*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) {
grib_iterator_class* c = *(table[i].cclass);
grib_iterator* it = (grib_iterator*)grib_context_malloc_clear(h->context, c->size);

View File

@ -10,8 +10,6 @@
#include "grib_api_internal.h"
#define NUMBER(x) (sizeof(x) / sizeof(x[0]))
/* This file is generated by ./make_class.pl */
#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)
{
size_t i = 0;
*error = GRIB_NOT_IMPLEMENTED;
size_t i = 0, num_table_entries = 0;
*error = GRIB_NOT_IMPLEMENTED;
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) {
grib_nearest_class* c = *(table[i].cclass);
grib_nearest* it = (grib_nearest*)grib_context_malloc_clear(h->context, c->size);

View File

@ -25,12 +25,10 @@
// size_t size;
// } grib_templates;
// #define NUMBER(x) (sizeof(x) / sizeof(x[0]))
// grib_handle* grib_internal_sample(grib_context* c,const char* name)
// {
// size_t i;
// const size_t num_samples = NUMBER(templates);
// Assert(0);
// const size_t num_samples = sizeof(templates) / sizeof(templates[0]);
// for(i = 0; i < num_samples; i++)
// if(strcmp(name,templates[i].name) == 0)
// return grib_handle_new_from_message_copy(c,templates[i].data,templates[i].size);

View File

@ -1862,13 +1862,11 @@ int parse_keyval_string(const char* grib_tool,
// Return 1 if the productDefinitionTemplateNumber (GRIB2) is for EPS (ensemble) products
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,
49, 54, 56, 58, 59, 60, 61, 63, 68, 71, 73, 77, 79,
81, 83, 84, 85, 92, 94, 96, 98 };
size_t i;
for (i = 0; i < NUMBER(eps_pdtns); ++i) {
size_t i = 0, num_epss = (sizeof(eps_pdtns) / sizeof(eps_pdtns[0]));
for (i = 0; i < num_epss; ++i) {
if (eps_pdtns[i] == pdtn) return 1;
}
return 0;