eccodes/src/grib_nearest_class.c

57 lines
1.7 KiB
C
Raw Normal View History

2013-03-25 12:04:10 +00:00
/*
2020-01-28 14:32:34 +00:00
* (C) Copyright 2005- ECMWF.
2013-03-25 12:04:10 +00:00
*
* 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 "grib_api_internal.h"
2020-01-22 13:10:59 +00:00
#define NUMBER(x) (sizeof(x) / sizeof(x[0]))
2013-03-25 12:04:10 +00:00
2016-08-31 08:59:21 +00:00
/* This file is generated by ./make_class.pl */
2013-03-25 12:04:10 +00:00
#include "grib_nearest_class.h"
struct table_entry
{
2022-04-08 14:10:53 +00:00
const char* type;
2020-01-22 13:10:59 +00:00
grib_nearest_class** cclass;
2013-03-25 12:04:10 +00:00
};
2020-01-22 13:10:59 +00:00
static const struct table_entry table[] = {
/* This file is generated by ./make_class.pl */
2013-03-25 12:04:10 +00:00
#include "grib_nearest_factory.h"
};
2020-01-22 13:10:59 +00:00
grib_nearest* grib_nearest_factory(grib_handle* h, grib_arguments* args)
2013-03-25 12:04:10 +00:00
{
2020-01-22 13:10:59 +00:00
int i;
int ret = GRIB_SUCCESS;
char* type = (char*)grib_arguments_get_name(h, args, 0);
for (i = 0; i < NUMBER(table); 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);
it->cclass = c;
ret = grib_nearest_init(it, h, args);
if (ret == GRIB_SUCCESS)
return it;
grib_context_log(h->context, GRIB_LOG_ERROR, "grib_nearest_factory: error %d instantiating nearest %s", ret, table[i].type);
grib_nearest_delete(it);
return NULL;
}
grib_context_log(h->context, GRIB_LOG_ERROR, "grib_nearest_factory : Unknown type : %s for nearest", type);
return NULL;
2013-03-25 12:04:10 +00:00
}