mirror of https://github.com/ecmwf/eccodes.git
ECC-144: Performance: ecCodes should be as fast as grib api
This commit is contained in:
parent
4502d11d63
commit
273451ff7c
|
@ -53,6 +53,9 @@ CODES_PRODUCT_METAR=3
|
|||
""" METAR product kind """
|
||||
CODES_PRODUCT_GTS=4
|
||||
""" GTS product kind """
|
||||
CODES_PRODUCT_TAF=5
|
||||
""" TAF product kind """
|
||||
|
||||
|
||||
# GRIB-51 Skip function arguments type checking if the
|
||||
# environment variable is defined
|
||||
|
|
|
@ -39,7 +39,7 @@ extern "C" {
|
|||
#define ECCODES_DEPRECATED
|
||||
#endif
|
||||
|
||||
typedef enum ProductKind {PRODUCT_ANY, PRODUCT_GRIB, PRODUCT_BUFR, PRODUCT_METAR, PRODUCT_GTS} ProductKind;
|
||||
typedef enum ProductKind {PRODUCT_ANY, PRODUCT_GRIB, PRODUCT_BUFR, PRODUCT_METAR, PRODUCT_GTS, PRODUCT_TAF} ProductKind;
|
||||
|
||||
#include "eccodes_version.h"
|
||||
|
||||
|
|
|
@ -834,6 +834,7 @@ struct grib_handle
|
|||
/* grib_accessor* groups[MAX_NUM_GROUPS]; */
|
||||
long missingValueLong;
|
||||
double missingValueDouble;
|
||||
ProductKind product_kind;
|
||||
};
|
||||
|
||||
struct grib_multi_handle {
|
||||
|
|
|
@ -159,11 +159,11 @@ grib_handle* grib_new_handle ( grib_context* c )
|
|||
if ( c == NULL ) c = grib_context_get_default();
|
||||
g = ( grib_handle* ) grib_context_malloc_clear ( c,sizeof ( grib_handle ) );
|
||||
|
||||
|
||||
if ( g == NULL ) {
|
||||
grib_context_log ( c,GRIB_LOG_ERROR,"grib_new_handle: cannot allocate handle" );
|
||||
} else {
|
||||
g->context = c;
|
||||
g->product_kind = PRODUCT_ANY; /* Default. Will later be set to a specific product */
|
||||
}
|
||||
|
||||
grib_context_log ( c,GRIB_LOG_DEBUG,"grib_new_handle: allocated handle %p",g );
|
||||
|
@ -717,6 +717,10 @@ grib_handle* grib_new_from_file ( grib_context* c, FILE* f,int headers_only,int
|
|||
|
||||
if ( h && h->offset == 0 ) c->handle_file_count=1;
|
||||
|
||||
if (h) {
|
||||
h->product_kind = PRODUCT_GRIB;
|
||||
}
|
||||
|
||||
if ( !c->no_fail_on_wrong_length && *error == GRIB_WRONG_LENGTH )
|
||||
{
|
||||
grib_handle_delete ( h );
|
||||
|
@ -757,6 +761,7 @@ grib_handle* gts_new_from_file ( grib_context* c, FILE* f,int *error )
|
|||
|
||||
gl->offset=offset;
|
||||
gl->buffer->property = GRIB_MY_BUFFER;
|
||||
gl->product_kind = PRODUCT_GTS;
|
||||
c->handle_file_count++;
|
||||
c->handle_total_count++;
|
||||
|
||||
|
@ -794,6 +799,7 @@ grib_handle* taf_new_from_file ( grib_context* c, FILE* f,int *error )
|
|||
|
||||
gl->offset=offset;
|
||||
gl->buffer->property = GRIB_MY_BUFFER;
|
||||
gl->product_kind = PRODUCT_TAF;
|
||||
c->handle_file_count++;
|
||||
c->handle_total_count++;
|
||||
|
||||
|
@ -831,6 +837,7 @@ grib_handle* metar_new_from_file ( grib_context* c, FILE* f,int *error )
|
|||
|
||||
gl->offset=offset;
|
||||
gl->buffer->property = GRIB_MY_BUFFER;
|
||||
gl->product_kind = PRODUCT_METAR;
|
||||
c->handle_file_count++;
|
||||
c->handle_total_count++;
|
||||
|
||||
|
@ -868,6 +875,7 @@ grib_handle* bufr_new_from_file ( grib_context* c, FILE* f,int *error )
|
|||
|
||||
gl->offset=offset;
|
||||
gl->buffer->property = GRIB_MY_BUFFER;
|
||||
gl->product_kind = PRODUCT_BUFR;
|
||||
c->handle_file_count++;
|
||||
c->handle_total_count++;
|
||||
|
||||
|
@ -905,6 +913,7 @@ grib_handle* any_new_from_file ( grib_context* c, FILE* f,int *error )
|
|||
|
||||
gl->offset=offset;
|
||||
gl->buffer->property = GRIB_MY_BUFFER;
|
||||
gl->product_kind = PRODUCT_ANY;
|
||||
c->handle_file_count++;
|
||||
c->handle_total_count++;
|
||||
|
||||
|
|
|
@ -42,10 +42,8 @@ static int matching(grib_accessor* a,const char* name,const char* name_space)
|
|||
|
||||
static grib_accessor* search(grib_section* s,const char* name,const char* name_space)
|
||||
{
|
||||
|
||||
grib_accessor* match = NULL;
|
||||
|
||||
|
||||
grib_accessor* a = s ? s->block->first : NULL;
|
||||
grib_accessor* b=NULL;
|
||||
|
||||
|
@ -133,7 +131,6 @@ static grib_accessor* _search_and_cache(grib_handle* h, const char* name,const c
|
|||
} else {
|
||||
return search(h->root,name,the_namespace);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
char* get_rank(const char* name,long *rank) {
|
||||
|
@ -201,7 +198,6 @@ char* get_condition(const char* name,codes_condition* condition)
|
|||
grib_context_free(c,str);
|
||||
str=NULL;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
@ -251,7 +247,8 @@ static int condition_true(grib_accessor* a,codes_condition* condition) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
static void search_from_accessors_list(grib_accessors_list* al,grib_accessors_list* end,const char* name,grib_accessors_list* result) {
|
||||
static void search_from_accessors_list(grib_accessors_list* al,grib_accessors_list* end,const char* name,grib_accessors_list* result)
|
||||
{
|
||||
char* accessor_name=NULL;
|
||||
char attribute_name[200]={0,};
|
||||
grib_accessor* accessor_result=0;
|
||||
|
@ -273,8 +270,8 @@ static void search_from_accessors_list(grib_accessors_list* al,grib_accessors_li
|
|||
}
|
||||
}
|
||||
|
||||
static void search_accessors_list_by_condition(grib_accessors_list* al,const char* name,codes_condition* condition,grib_accessors_list* result) {
|
||||
|
||||
static void search_accessors_list_by_condition(grib_accessors_list* al,const char* name,codes_condition* condition,grib_accessors_list* result)
|
||||
{
|
||||
grib_accessors_list* start=NULL;
|
||||
grib_accessors_list* end=NULL;
|
||||
|
||||
|
@ -295,7 +292,8 @@ static void search_accessors_list_by_condition(grib_accessors_list* al,const cha
|
|||
|
||||
}
|
||||
|
||||
static grib_accessors_list* search_by_condition(grib_handle* h,const char* name,codes_condition* condition) {
|
||||
static grib_accessors_list* search_by_condition(grib_handle* h,const char* name,codes_condition* condition)
|
||||
{
|
||||
grib_accessors_list* al;
|
||||
grib_accessors_list* result=NULL;
|
||||
grib_accessor* data=search_and_cache(h,"dataAccessors",0);
|
||||
|
@ -313,14 +311,16 @@ static grib_accessors_list* search_by_condition(grib_handle* h,const char* name,
|
|||
return result;
|
||||
}
|
||||
|
||||
static void grib_find_same_and_push(grib_accessors_list* al,grib_accessor* a) {
|
||||
static void grib_find_same_and_push(grib_accessors_list* al,grib_accessor* a)
|
||||
{
|
||||
if (a) {
|
||||
grib_find_same_and_push(al,a->same);
|
||||
grib_accessors_list_push(al,a);
|
||||
}
|
||||
}
|
||||
|
||||
grib_accessors_list* grib_find_accessors_list(grib_handle* h,const char* name) {
|
||||
grib_accessors_list* grib_find_accessors_list(grib_handle* h,const char* name)
|
||||
{
|
||||
char* str=NULL;
|
||||
grib_accessors_list* al=NULL;
|
||||
codes_condition* condition=NULL;
|
||||
|
@ -373,9 +373,7 @@ static grib_accessor* search_and_cache(grib_handle* h, const char* name,const ch
|
|||
static grib_accessor* _grib_find_accessor(grib_handle* h, const char* name)
|
||||
{
|
||||
grib_accessor* a = NULL;
|
||||
char* p=NULL;
|
||||
|
||||
p=(char*)name;
|
||||
char* p = (char*)name;
|
||||
DebugAssert(name);
|
||||
|
||||
while ( *p != '.' && *p != '\0' ) p++;
|
||||
|
@ -403,7 +401,8 @@ static grib_accessor* _grib_find_accessor(grib_handle* h, const char* name)
|
|||
return a;
|
||||
}
|
||||
|
||||
char* grib_split_name_attribute(grib_context* c,const char* name,char* attribute_name) {
|
||||
char* grib_split_name_attribute(grib_context* c,const char* name,char* attribute_name)
|
||||
{
|
||||
/*returns accessor name and attribute*/
|
||||
char* p=0;
|
||||
size_t size=0;
|
||||
|
@ -424,10 +423,15 @@ char* grib_split_name_attribute(grib_context* c,const char* name,char* attribute
|
|||
|
||||
grib_accessor* grib_find_accessor(grib_handle* h, const char* name)
|
||||
{
|
||||
grib_accessor* aret = NULL;
|
||||
|
||||
if (h->product_kind == PRODUCT_GRIB) {
|
||||
aret = _grib_find_accessor(h, name); /* ECC-144: Performance */
|
||||
}
|
||||
else {
|
||||
char* accessor_name=NULL;
|
||||
char attribute_name[512]={0,};
|
||||
grib_accessor* a=NULL;
|
||||
grib_accessor* aret=NULL;
|
||||
|
||||
accessor_name=grib_split_name_attribute(h->context,name,attribute_name);
|
||||
|
||||
|
@ -439,7 +443,7 @@ grib_accessor* grib_find_accessor(grib_handle* h, const char* name)
|
|||
aret=grib_accessor_get_attribute(a,attribute_name);
|
||||
grib_context_free(h->context,accessor_name);
|
||||
}
|
||||
|
||||
}
|
||||
return aret;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue