added search by rank (example pressure#3). Still something to fix. Changed default of bufr_dump, now -j, not -jL

This commit is contained in:
Enrico Fucile 2015-02-23 11:13:41 +00:00
parent ee94336bda
commit a481836df8
3 changed files with 99 additions and 29 deletions

View File

@ -30,3 +30,5 @@ meta unpack unpack_bufr_values(numericValues) ;
section_padding section4Padding;
position offsetEndSection4;
meta md5Data md5(offsetSection4,section4Length);
alias dataAccessor=numericValues;

View File

@ -108,6 +108,7 @@ extern "C" {
#endif
#include <limits.h>
#include <errno.h>
#include <stdarg.h>
#include <stdlib.h>

View File

@ -124,46 +124,113 @@ static void rebuild_hash_keys (grib_handle* h,grib_section* s)
}
}
static grib_accessor* search_and_cache(grib_handle* h, const char* name,const char *the_namespace)
static grib_accessor* search_and_cache(grib_handle* h, const char* name,const char *the_namespace);
static grib_accessor* _search_and_cache(grib_handle* h, const char* name,const char *the_namespace)
{
if(h->use_trie)
{
grib_accessor* a = NULL;
int id=-1;
if (h->use_trie)
{
grib_accessor* a = NULL;
int id=-1;
if (h->trie_invalid && h->kid == NULL)
{
int i=0;
for (i=0;i<ACCESSORS_ARRAY_SIZE;i++)
h->accessors[i]=NULL;
if (h->trie_invalid && h->kid == NULL)
{
int i=0;
for (i=0;i<ACCESSORS_ARRAY_SIZE;i++)
h->accessors[i]=NULL;
if (h->root)
rebuild_hash_keys(h,h->root);
if (h->root)
rebuild_hash_keys(h,h->root);
h->trie_invalid=0;
id = grib_hash_keys_get_id(h->context->keys,name);
h->trie_invalid=0;
id = grib_hash_keys_get_id(h->context->keys,name);
}
else
{
id = grib_hash_keys_get_id(h->context->keys,name);
} else {
id = grib_hash_keys_get_id(h->context->keys,name);
if ((a=h->accessors[id])!=NULL &&
(the_namespace==NULL || matching(a,name,the_namespace) ))
return a;
}
if ((a=h->accessors[id])!=NULL &&
(the_namespace==NULL || matching(a,name,the_namespace) ))
return a;
}
a = search(h->root,name,the_namespace);
h->accessors[id] = a;
a = search(h->root,name,the_namespace);
h->accessors[id] = a;
return a;
}
else {
return search(h->root,name,the_namespace);
}
return a;
} else {
return search(h->root,name,the_namespace);
}
}
char* get_rank(const char* name,long *rank) {
char* p=(char*)name;
char* end=p;
char* ret=NULL;
size_t len;
*rank=-1;
while (*p!=0 && *p!='#') p++;
if (*p=='#') {
*rank=strtol(++p,&end,10);
if (errno!=0 || end == p) {
*rank=-1;
} else {
grib_context* c=grib_context_get_default();
len=p-name;
ret=grib_context_malloc_clear(c,len);
memcpy(ret,name,len-1);
}
}
return ret;
}
static grib_accessor* _search_by_rank(grib_accessor* a,const char* name,long rank) {
long r=1;
grib_accessors_list* al=accessor_bufr_data_array_get_dataAccessors(a);
while (al) {
if (!strcmp(al->accessor->name,name)) {
if (r==rank) return al->accessor;
r++;
}
al=al->next;
}
return NULL;
}
static grib_accessor* search_by_rank(grib_handle* h, const char* name,const char *the_namespace,long rank)
{
grib_accessor* data=search_and_cache(h,"numericValues",the_namespace);
if (data) {
return _search_by_rank(data,name,rank);
} else {
return _search_and_cache(h,name,the_namespace);
}
}
static grib_accessor* search_and_cache(grib_handle* h, const char* name,const char *the_namespace)
{
char* str=0;
long rank;
str=get_rank(name,&rank);
if (rank>0) {
grib_accessor* a=NULL;
a=search_by_rank(h,str,the_namespace,rank);
grib_context_free(h->context,str);
return a;
} else {
return _search_and_cache(h,name,the_namespace);
}
}
static grib_accessor* _grib_find_accessor(grib_handle* h, const char* name)
{
grib_accessor* a = NULL;