Fix compiler errors when using g++

This commit is contained in:
Shahram Najm 2015-06-01 17:07:16 +01:00
parent e3389fe601
commit 26ae520583
9 changed files with 412 additions and 426 deletions

View File

@ -691,7 +691,7 @@ int grib_accessor_has_attributes(grib_accessor* a) {
}
grib_accessor* grib_accessor_get_attribute(grib_accessor* a,const char* name) {
int i=0,index=0;
int index=0;
char* p=0;
char* basename=NULL;
char* attribute_name=NULL;
@ -703,8 +703,8 @@ grib_accessor* grib_accessor_get_attribute(grib_accessor* a,const char* name) {
} else {
size_t size=p-name;
attribute_name=p+2;
basename=grib_context_malloc_clear(a->parent->h->context,size+1);
basename=memcpy(basename,name,size);
basename=(char*)grib_context_malloc_clear(a->parent->h->context,size+1);
basename=(char*)memcpy(basename,name,size);
acc=_grib_accessor_get_attribute(a,basename,&index);
grib_context_free(a->parent->h->context,basename);
if (acc) return grib_accessor_get_attribute(acc,attribute_name);
@ -712,11 +712,13 @@ grib_accessor* grib_accessor_get_attribute(grib_accessor* a,const char* name) {
}
}
grib_accessors_list* grib_accessors_list_create(grib_context* c) {
return grib_context_malloc_clear(c,sizeof(grib_accessors_list));
grib_accessors_list* grib_accessors_list_create(grib_context* c)
{
return (grib_accessors_list*)grib_context_malloc_clear(c,sizeof(grib_accessors_list));
}
void grib_accessors_list_push(grib_accessors_list* al,grib_accessor* a) {
void grib_accessors_list_push(grib_accessors_list* al,grib_accessor* a)
{
grib_accessors_list* last;
grib_context* c=a->parent->h->context;
@ -732,8 +734,9 @@ void grib_accessors_list_push(grib_accessors_list* al,grib_accessor* a) {
}
}
grib_accessors_list* grib_accessors_list_last(grib_accessors_list* al) {
grib_accessors_list* last=al;
grib_accessors_list* grib_accessors_list_last(grib_accessors_list* al)
{
/*grib_accessors_list* last=al;*/
grib_accessors_list* next=al->next;
/*

View File

@ -178,7 +178,7 @@ char** str_split(char* a_str, const char a_delim)
knows where the list of returned strings ends. */
count++;
result = malloc(sizeof(char*) * count);
result = (char**)malloc(sizeof(char*) * count);
if (result)
{

View File

@ -360,7 +360,7 @@ static int unpack_string_array(grib_accessor*a , char** v, size_t *len){
err= _grib_get_string_length(a,&length);
if (err) return err;
v[0]=grib_context_malloc_clear(a->parent->h->context,length);
v[0]=(char*)grib_context_malloc_clear(a->parent->h->context,length);
grib_unpack_string(a,v[0],&length);
*len=1;

View File

@ -134,128 +134,122 @@ static void init_class(grib_accessor_class* c)
/* END_CLASS_IMP */
static long compute_byte_count(grib_accessor* a){
grib_accessor_unexpanded_descriptors* self = (grib_accessor_unexpanded_descriptors*)a;
long numberOfUnexpandedDescriptors;
int ret=0;
grib_accessor_unexpanded_descriptors* self = (grib_accessor_unexpanded_descriptors*)a;
long numberOfUnexpandedDescriptors;
int ret=0;
ret=grib_get_long(a->parent->h,self->numberOfUnexpandedDescriptors,&numberOfUnexpandedDescriptors);
if (ret) {
grib_context_log(a->parent->h->context,GRIB_LOG_ERROR,
"%s unable to get %s to compute size",a->name,self->numberOfUnexpandedDescriptors);
return 0;
}
ret=grib_get_long(a->parent->h,self->numberOfUnexpandedDescriptors,&numberOfUnexpandedDescriptors);
if (ret) {
grib_context_log(a->parent->h->context,GRIB_LOG_ERROR,
"%s unable to get %s to compute size",a->name,self->numberOfUnexpandedDescriptors);
return 0;
}
return 2*numberOfUnexpandedDescriptors;
return 2*numberOfUnexpandedDescriptors;
}
static void init(grib_accessor* a, const long len , grib_arguments* args )
{
grib_accessor_unexpanded_descriptors* self = (grib_accessor_unexpanded_descriptors*)a;
int n=0;
self->numberOfUnexpandedDescriptors=grib_arguments_get_name(a->parent->h,args,n++);
a->length = compute_byte_count(a);
grib_accessor_unexpanded_descriptors* self = (grib_accessor_unexpanded_descriptors*)a;
int n=0;
self->numberOfUnexpandedDescriptors=grib_arguments_get_name(a->parent->h,args,n++);
a->length = compute_byte_count(a);
}
static void dump(grib_accessor* a, grib_dumper* dumper)
{
grib_dump_long(dumper,a,NULL);
grib_dump_long(dumper,a,NULL);
}
static int unpack_long (grib_accessor* a, long* val, size_t *len)
{
grib_accessor_unexpanded_descriptors* self = (grib_accessor_unexpanded_descriptors*)a;
int ret=0;
long pos = a->offset*8;
long rlen =0;
long numberOfUnexpandedDescriptors = 0;
long f,x,y;
long *v=val;
int i;
grib_accessor_unexpanded_descriptors* self = (grib_accessor_unexpanded_descriptors*)a;
int ret=0;
long pos = a->offset*8;
long rlen =0;
long numberOfUnexpandedDescriptors = 0;
long f,x,y;
long *v=val;
int i;
ret=value_count(a,&rlen);
if (ret) return ret;
ret=value_count(a,&rlen);
if (ret) return ret;
if (rlen==0) {
grib_context_log(a->parent->h->context,GRIB_LOG_FATAL,
"No descriptors in section 3. Malformed message.");
return GRIB_MESSAGE_MALFORMED;
}
if (rlen==0) {
grib_context_log(a->parent->h->context,GRIB_LOG_FATAL,
"No descriptors in section 3. Malformed message.");
return GRIB_MESSAGE_MALFORMED;
}
if(*len < rlen)
{
grib_context_log(a->parent->h->context, GRIB_LOG_ERROR,
" wrong size (%ld) for %s it contains %d values ",*len, a->name , rlen);
*len = 0;
return GRIB_ARRAY_TOO_SMALL;
}
if(*len < rlen)
{
grib_context_log(a->parent->h->context, GRIB_LOG_ERROR,
" wrong size (%ld) for %s it contains %d values ",*len, a->name , rlen);
*len = 0;
return GRIB_ARRAY_TOO_SMALL;
}
ret=grib_get_long(a->parent->h,self->numberOfUnexpandedDescriptors,&numberOfUnexpandedDescriptors);
if (ret) return ret;
ret=grib_get_long(a->parent->h,self->numberOfUnexpandedDescriptors,&numberOfUnexpandedDescriptors);
if (ret) return ret;
for (i=0;i<rlen;i++) {
f=grib_decode_unsigned_long(a->parent->h->buffer->data,&pos,2);
x=grib_decode_unsigned_long(a->parent->h->buffer->data,&pos,6);
y=grib_decode_unsigned_long(a->parent->h->buffer->data,&pos,8);
*v++=f*100000+x*1000+y;
}
*len = rlen;
return GRIB_SUCCESS;
for (i=0;i<rlen;i++) {
f=grib_decode_unsigned_long(a->parent->h->buffer->data,&pos,2);
x=grib_decode_unsigned_long(a->parent->h->buffer->data,&pos,6);
y=grib_decode_unsigned_long(a->parent->h->buffer->data,&pos,8);
*v++=f*100000+x*1000+y;
}
*len = rlen;
return GRIB_SUCCESS;
}
static int pack_long (grib_accessor* a, const long* val, size_t *len)
{
int ret=0,i;
long pos = 0;
unsigned long f,x,y;
unsigned char* buf = NULL;
size_t buflen=*len*2;
int ret=0,i;
long pos = 0;
unsigned long f,x,y;
unsigned char* buf = NULL;
size_t buflen=*len*2;
buf=grib_context_malloc_clear(a->parent->h->context,buflen);
buf=(unsigned char*)grib_context_malloc_clear(a->parent->h->context,buflen);
for (i=0;i<*len;i++) {
f=val[i]/100000;
x=(val[i]%100000)/1000;
y=(val[i]%100000)%1000;
grib_encode_unsigned_longb(buf,f,&pos,2);
grib_encode_unsigned_longb(buf,x,&pos,6);
grib_encode_unsigned_longb(buf,y,&pos,8);
}
grib_buffer_replace(a,buf,buflen,1,1);
for (i=0;i<*len;i++) {
f=val[i]/100000;
x=(val[i]%100000)/1000;
y=(val[i]%100000)%1000;
grib_encode_unsigned_longb(buf,f,&pos,2);
grib_encode_unsigned_longb(buf,x,&pos,6);
grib_encode_unsigned_longb(buf,y,&pos,8);
}
grib_buffer_replace(a,buf,buflen,1,1);
/* update_size(a,buflen); */
return ret;
/* update_size(a,buflen); */
return ret;
}
static long byte_count(grib_accessor* a){
return a->length;
return a->length;
}
static int value_count(grib_accessor* a,long* numberOfUnexpandedDescriptors)
{
grib_accessor_unexpanded_descriptors* self = (grib_accessor_unexpanded_descriptors*)a;
*numberOfUnexpandedDescriptors=0;
grib_accessor_unexpanded_descriptors* self = (grib_accessor_unexpanded_descriptors*)a;
*numberOfUnexpandedDescriptors=0;
return grib_get_long(a->parent->h,self->numberOfUnexpandedDescriptors,numberOfUnexpandedDescriptors);
return grib_get_long(a->parent->h,self->numberOfUnexpandedDescriptors,numberOfUnexpandedDescriptors);
}
static long byte_offset(grib_accessor* a){
return a->offset;
return a->offset;
}
static void update_size(grib_accessor* a,size_t s)
{
a->length = s;
a->length = s;
}
static long next_offset(grib_accessor* a){
return byte_offset(a)+a->length;
return byte_offset(a)+a->length;
}

View File

@ -24,7 +24,7 @@ bufr_descriptor* grib_bufr_descriptor_clone(bufr_descriptor* d) {
if (!d) return NULL;
cd=grib_context_malloc_clear(d->context,sizeof(bufr_descriptor));
cd=(bufr_descriptor*)grib_context_malloc_clear(d->context,sizeof(bufr_descriptor));
cd->code=d->code;
cd->F=d->F;

View File

@ -51,9 +51,7 @@ struct grib_keys_hash { char* name; int id;};
#endif
#endif
static unsigned int
hash_keys (str, len)
register const char *str;
register unsigned int len;
hash_keys (const char *str, unsigned int len)
{
static unsigned short asso_values[] =
{
@ -7171,9 +7169,7 @@ static struct grib_keys_hash wordlist[] =
#endif
#endif
struct grib_keys_hash *
grib_keys_hash_get (str, len)
register const char *str;
register unsigned int len;
grib_keys_hash_get (const char *str, unsigned int len)
{
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
{

View File

@ -284,7 +284,7 @@ int grib_accessors_list_print(grib_accessors_list* al,const char* name,int type,
} else {
int i=0;
int cols=0;
cvals=grib_context_malloc_clear(h->context,sizeof(char*)*size);
cvals=(char**)grib_context_malloc_clear(h->context,sizeof(char*)*size);
grib_accessors_list_unpack_string(al,cvals,&size);
for (i=0;i<size;i++) {
*newline=1;

View File

@ -23,476 +23,469 @@ GRIB_INLINE static int strcmp(const char* a,const char* b) {
}
#endif
static int matching(grib_accessor* a,const char* name,const char* name_space)
{
int i = 0;
while(i < MAX_ACCESSOR_NAMES)
{
if(a->all_names[i] == 0) return 0;
int i = 0;
while(i < MAX_ACCESSOR_NAMES)
{
if(a->all_names[i] == 0) return 0;
if((strcmp(name,a->all_names[i]) == 0) &&
((name_space == NULL) || (a->all_name_spaces[i] != NULL &&
strcmp(a->all_name_spaces[i],name_space) == 0))
)
return 1;
i++;
}
return 0;
if((strcmp(name,a->all_names[i]) == 0) &&
((name_space == NULL) || (a->all_name_spaces[i] != NULL &&
strcmp(a->all_name_spaces[i],name_space) == 0))
)
return 1;
i++;
}
return 0;
}
static grib_accessor* search(grib_section* s,const char* name,const char* name_space)
{
grib_accessor* match = NULL;
grib_accessor* match = NULL;
grib_accessor* a = s ? s->block->first : NULL;
grib_accessor* b=NULL;
grib_accessor* a = s ? s->block->first : NULL;
grib_accessor* b=NULL;
if(!a || !s) return NULL;
if(!a || !s) return NULL;
while(a)
{
grib_section* sub = a->sub_section;
while(a)
{
grib_section* sub = a->sub_section;
if(matching(a,name,name_space))
match = a;
if(matching(a,name,name_space))
match = a;
if((b = search(sub,name,name_space) ) != NULL )
match = b;
if((b = search(sub,name,name_space) ) != NULL )
match = b;
a = a->next;
}
a = a->next;
}
return match;
return match;
}
static void rebuild_hash_keys (grib_handle* h,grib_section* s)
{
grib_accessor* a = s ? s->block->first : NULL;
grib_accessor* a = s ? s->block->first : NULL;
while(a)
{
grib_section* sub = a->sub_section;
int i=0;
int id=-1;
const char *p;
Assert(h == a->parent->h);
while(a)
{
grib_section* sub = a->sub_section;
int i=0;
int id=-1;
const char *p;
Assert(h == a->parent->h);
while(i<MAX_ACCESSOR_NAMES && ((p = a->all_names[i]) != NULL)) {
if(*p != '_') {
id=grib_hash_keys_get_id(a->parent->h->context->keys,p);
while(i<MAX_ACCESSOR_NAMES && ((p = a->all_names[i]) != NULL)) {
if(*p != '_') {
id=grib_hash_keys_get_id(a->parent->h->context->keys,p);
if (a->same != a && i==0) {
a->same=a->parent->h->accessors[id];
a->parent->h->accessors[id]=a;
Assert(a->same != a);
}
if (a->same != a && i==0) {
a->same=a->parent->h->accessors[id];
a->parent->h->accessors[id]=a;
Assert(a->same != a);
}
}
i++;
}
rebuild_hash_keys(h,sub);
a = a->next;
}
}
i++;
}
rebuild_hash_keys(h,sub);
a = a->next;
}
}
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->trie_invalid && h->kid == NULL)
if (h->use_trie)
{
int i=0;
for (i=0;i<ACCESSORS_ARRAY_SIZE;i++)
h->accessors[i]=NULL;
grib_accessor* a = NULL;
int id=-1;
if (h->root)
rebuild_hash_keys(h,h->root);
if (h->trie_invalid && h->kid == NULL)
{
int i=0;
for (i=0;i<ACCESSORS_ARRAY_SIZE;i++)
h->accessors[i]=NULL;
h->trie_invalid=0;
id = grib_hash_keys_get_id(h->context->keys,name);
if (h->root)
rebuild_hash_keys(h,h->root);
} else {
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);
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;
if ((a=h->accessors[id])!=NULL &&
(the_namespace==NULL || matching(a,name,the_namespace) ))
return a;
} else {
return search(h->root,name,the_namespace);
}
a = search(h->root,name,the_namespace);
h->accessors[id] = a;
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;
char* p=(char*)name;
char* end=p;
char* ret=NULL;
size_t len;
*rank=-1;
while (*p!=0 && *p!='#') p++;
*rank=-1;
while (*p!=0 && *p!='#') p++;
if (*p=='#') {
*rank=strtol(++p,&end,10);
if ( *end != 0) {
*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);
if (*p=='#') {
*rank=strtol(++p,&end,10);
if ( *end != 0) {
*rank=-1;
} else {
grib_context* c=grib_context_get_default();
len=p-name;
ret=(char*)grib_context_malloc_clear(c,len);
memcpy(ret,name,len-1);
}
}
}
return ret;
return ret;
}
char* get_condition(const char* name,codes_condition* condition) {
char* equal=(char*)name;
char* endCondition=NULL;
char* startLeft=NULL;
char* str=NULL;
char* end=NULL;
size_t len;
long lval;
double dval;
grib_context* c=grib_context_get_default();
char* get_condition(const char* name,codes_condition* condition)
{
char* equal=(char*)name;
char* endCondition=NULL;
char* str=NULL;
char* end=NULL;
long lval;
double dval;
grib_context* c=grib_context_get_default();
condition->rightType=GRIB_TYPE_UNDEFINED;
condition->rightType=GRIB_TYPE_UNDEFINED;
Assert(name[0]=='/');
Assert(name[0]=='/');
while (*equal!=0 && *equal!='=') equal++;
if (*equal==0) return NULL;
while (*equal!=0 && *equal!='=') equal++;
if (*equal==0) return NULL;
endCondition=equal;
while (*endCondition!=0 && *endCondition!='/') endCondition++;
if (*endCondition==0) return NULL;
endCondition=equal;
while (*endCondition!=0 && *endCondition!='/') endCondition++;
if (*endCondition==0) return NULL;
str=grib_context_malloc_clear(c,strlen(name));
memcpy(str,equal+1,endCondition-equal-1);
str=(char*)grib_context_malloc_clear(c,strlen(name));
memcpy(str,equal+1,endCondition-equal-1);
end=NULL;
lval=strtol(str,&end,10);
if (*end != 0) {
dval=strtod(str,&end);
end=NULL;
lval=strtol(str,&end,10);
if (*end != 0) {
condition->rightType=GRIB_TYPE_DOUBLE;
condition->rightDouble=dval;
dval=strtod(str,&end);
if (*end != 0) {
condition->rightType=GRIB_TYPE_DOUBLE;
condition->rightDouble=dval;
}
} else {
condition->rightType=GRIB_TYPE_LONG;
condition->rightLong=lval;
}
} else {
condition->rightType=GRIB_TYPE_LONG;
condition->rightLong=lval;
}
if (condition->rightType!=GRIB_TYPE_UNDEFINED) {
strcpy(str,endCondition+1);
condition->left=grib_context_malloc_clear(c,equal-name);
memcpy(condition->left,name+1,equal-name-1);
} else {
grib_context_free(c,str);
str=NULL;
}
if (condition->rightType!=GRIB_TYPE_UNDEFINED) {
strcpy(str,endCondition+1);
condition->left=(char*)grib_context_malloc_clear(c,equal-name);
memcpy(condition->left,name+1,equal-name-1);
} else {
grib_context_free(c,str);
str=NULL;
}
return str;
return str;
}
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);
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++;
while (al) {
if (!strcmp(al->accessor->name,name)) {
if (r==rank) return al->accessor;
r++;
}
al=al->next;
}
al=al->next;
}
return NULL;
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,"dataAccessors",the_namespace);
if (data) {
return _search_by_rank(data,name,rank);
} else {
return _search_and_cache(h,name,the_namespace);
}
grib_accessor* data=search_and_cache(h,"dataAccessors",the_namespace);
if (data) {
return _search_by_rank(data,name,rank);
} else {
return _search_and_cache(h,name,the_namespace);
}
}
static int condition_true(grib_accessor* a,codes_condition* condition) {
int ret=0;
size_t size=1;
long lval;
double dval;
switch (condition->rightType) {
int ret=0;
size_t size=1;
long lval;
double dval;
switch (condition->rightType) {
case GRIB_TYPE_LONG:
grib_unpack_long(a,&lval,&size);
ret = lval==condition->rightLong ? 1 : 0;
break;
grib_unpack_long(a,&lval,&size);
ret = lval==condition->rightLong ? 1 : 0;
break;
case GRIB_TYPE_DOUBLE:
grib_unpack_double(a,&dval,&size);
ret = dval==condition->rightDouble ? 1 : 0;
break;
grib_unpack_double(a,&dval,&size);
ret = dval==condition->rightDouble ? 1 : 0;
break;
default :
ret=0;
break;
}
return ret;
ret=0;
break;
}
return ret;
}
static void search_from_accessors_list(grib_accessors_list* al,grib_accessors_list* end,const char* name,grib_accessors_list* result) {
while (al && al!=end && al->accessor) {
if (!strcmp(al->accessor->name,name))
grib_accessors_list_push(result,al->accessor);
al=al->next;
}
while (al && al!=end && al->accessor) {
if (!strcmp(al->accessor->name,name))
grib_accessors_list_push(result,al->accessor);
al=al->next;
}
}
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;
grib_accessors_list* start=NULL;
grib_accessors_list* end=NULL;
while (al) {
if (!strcmp(al->accessor->name,condition->left)) {
if (start==NULL && condition_true(al->accessor,condition)) start=al;
if (start && !condition_true(al->accessor,condition)) end=al;
while (al) {
if (!strcmp(al->accessor->name,condition->left)) {
if (start==NULL && condition_true(al->accessor,condition)) start=al;
if (start && !condition_true(al->accessor,condition)) end=al;
}
al=al->next;
if (start && end) {
search_from_accessors_list(start,end,name,result);
al=end;
start=NULL;
end=NULL;
}
}
al=al->next;
if (start && end) {
search_from_accessors_list(start,end,name,result);
al=end;
start=NULL;
end=NULL;
}
}
}
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);
if (data && condition->left) {
al=accessor_bufr_data_array_get_dataAccessors(data);
result=grib_context_malloc_clear(al->accessor->parent->h->context,sizeof(grib_accessors_list));
search_accessors_list_by_condition(al,name,condition,result);
if (!result->accessor) {
grib_accessors_list_delete(h->context,result);
result=NULL;
grib_accessors_list* al;
grib_accessors_list* result=NULL;
grib_accessor* data=search_and_cache(h,"dataAccessors",0);
if (data && condition->left) {
al=accessor_bufr_data_array_get_dataAccessors(data);
result=(grib_accessors_list*)grib_context_malloc_clear(al->accessor->parent->h->context,sizeof(grib_accessors_list));
search_accessors_list_by_condition(al,name,condition,result);
if (!result->accessor) {
grib_accessors_list_delete(h->context,result);
result=NULL;
}
}
}
return result;
return result;
}
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);
}
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) {
char* str=NULL;
grib_accessors_list* al=NULL;
codes_condition* condition=NULL;
grib_accessor* a=NULL;
char* str=NULL;
grib_accessors_list* al=NULL;
codes_condition* condition=NULL;
grib_accessor* a=NULL;
if (name[0]=='/') {
condition=grib_context_malloc_clear(h->context,sizeof(codes_condition));
str=get_condition(name,condition);
if (str) {
al=search_by_condition(h,str,condition);
grib_context_free(h->context,str);
if (condition->left) grib_context_free(h->context,condition->left);
if (condition->rightString) grib_context_free(h->context,condition->rightString);
if (name[0]=='/') {
condition=(codes_condition*)grib_context_malloc_clear(h->context,sizeof(codes_condition));
str=get_condition(name,condition);
if (str) {
al=search_by_condition(h,str,condition);
grib_context_free(h->context,str);
if (condition->left) grib_context_free(h->context,condition->left);
if (condition->rightString) grib_context_free(h->context,condition->rightString);
}
grib_context_free(h->context,condition);
} else if (has_rank(name)) {
a=grib_find_accessor(h, name);
if (a) {
al=(grib_accessors_list*)grib_context_malloc_clear(h->context,sizeof(grib_accessors_list));
grib_accessors_list_push(al,a);
}
} else {
a=grib_find_accessor(h, name);
if (a) {
al=(grib_accessors_list*)grib_context_malloc_clear(h->context,sizeof(grib_accessors_list));
grib_find_same_and_push(al,a);
}
}
grib_context_free(h->context,condition);
} else if (has_rank(name)) {
a=grib_find_accessor(h, name);
if (a) {
al=grib_context_malloc_clear(h->context,sizeof(grib_accessors_list));
grib_accessors_list_push(al,a);
}
} else {
a=grib_find_accessor(h, name);
if (a) {
al=grib_context_malloc_clear(h->context,sizeof(grib_accessors_list));
grib_find_same_and_push(al,a);
}
}
return al;
return al;
}
static grib_accessor* search_and_cache(grib_handle* h, const char* name,const char *the_namespace)
{
char* str=0;
grib_accessor* a=NULL;
codes_condition* condition=NULL;
long rank;
char* str=0;
grib_accessor* a=NULL;
long rank;
str=get_rank(name,&rank);
if (rank>0) {
a=search_by_rank(h,str,the_namespace,rank);
grib_context_free(h->context,str);
} else {
a=_search_and_cache(h,name,the_namespace);
}
str=get_rank(name,&rank);
if (rank>0) {
a=search_by_rank(h,str,the_namespace,rank);
grib_context_free(h->context,str);
} else {
a=_search_and_cache(h,name,the_namespace);
}
return a;
return a;
}
static grib_accessor* _grib_find_accessor(grib_handle* h, const char* name)
{
grib_accessor* a = NULL;
char* p=NULL;
char* basename=NULL;
char name_space[1024];
int i=0,len=0;
grib_accessor* a = NULL;
char* p=NULL;
char* basename=NULL;
char name_space[1024];
int i=0,len=0;
p=(char*)name;
Assert(name);
p=(char*)name;
Assert(name);
while ( *p != '.' && *p != '\0' ) p++;
if ( *p == '.' ) {
basename=p+1;
p--;
i=0;
len=p-name+1;
while ( *p != '.' && *p != '\0' ) p++;
if ( *p == '.' ) {
basename=p+1;
p--;
i=0;
len=p-name+1;
for ( i=0;i<len;i++ ) name_space[i] = *(name+i);
for ( i=0;i<len;i++ ) name_space[i] = *(name+i);
name_space[len]='\0';
name_space[len]='\0';
a = search_and_cache(h,basename,name_space);
} else {
a = search_and_cache(h,name,NULL);
}
a = search_and_cache(h,basename,name_space);
} else {
a = search_and_cache(h,name,NULL);
}
if(a == NULL && h->main)
a = grib_find_accessor(h->main,name);
if(a == NULL && h->main)
a = grib_find_accessor(h->main,name);
return a;
return a;
}
int has_rank(const char* name) {
char* p=(char*)name;
while (*p!=0 && *p!='#') p++;
return *p ? 1 : 0 ;
char* p=(char*)name;
while (*p!=0 && *p!='#') p++;
return *p ? 1 : 0 ;
}
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;
char* accessor_name=NULL;
p=(char*)name;
while ( *(p+1) != '\0' && ( *p != '-' || *(p+1)!= '>' ) ) p++;
if (*(p+1) == '\0') {
*attribute_name=0;
return (char*)name;
}
size=p-name;
accessor_name=grib_context_malloc_clear(c,size+1);
accessor_name=memcpy(accessor_name,name,size);
p+=2;
strcpy(attribute_name,p);
return accessor_name;
/*returns accessor name and attribute*/
char* p=0;
size_t size=0;
char* accessor_name=NULL;
p=(char*)name;
while ( *(p+1) != '\0' && ( *p != '-' || *(p+1)!= '>' ) ) p++;
if (*(p+1) == '\0') {
*attribute_name=0;
return (char*)name;
}
size=p-name;
accessor_name=(char*)grib_context_malloc_clear(c,size+1);
accessor_name=(char*)memcpy(accessor_name,name,size);
p+=2;
strcpy(attribute_name,p);
return accessor_name;
}
grib_accessor* grib_find_accessor(grib_handle* h, const char* name)
{
char* accessor_name=NULL;
char attribute_name[512]={0,};
grib_accessor* a=NULL;
grib_accessor* aret=NULL;
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);
accessor_name=grib_split_name_attribute(h->context,name,attribute_name);
a=_grib_find_accessor(h,accessor_name);
a=_grib_find_accessor(h,accessor_name);
if (*attribute_name==0) {
aret=a;
} else if (a) {
aret=grib_accessor_get_attribute(a,attribute_name);
grib_context_free(h->context,accessor_name);
}
if (*attribute_name==0) {
aret=a;
} else if (a) {
aret=grib_accessor_get_attribute(a,attribute_name);
grib_context_free(h->context,accessor_name);
}
return aret;
return aret;
}
grib_accessor* grib_find_attribute(grib_handle* h, const char* name,const char* attr_name, int* err)
{
grib_accessor* a = NULL;
grib_accessor* act = NULL;
int id=0;
int id=0;
if ((a = grib_find_accessor(h, name))==NULL) {
*err=GRIB_NOT_FOUND;
return NULL;
}
*err=GRIB_NOT_FOUND;
return NULL;
}
if((act=grib_accessor_get_attribute(a,attr_name))==NULL) {
*err=GRIB_ATTRIBUTE_NOT_FOUND;
return NULL;
}
return act;
*err=GRIB_ATTRIBUTE_NOT_FOUND;
return NULL;
}
return act;
}
/* Only look in trie. Used only in alias. Should not be used in other cases.*/
grib_accessor* grib_find_accessor_fast(grib_handle* h, const char* name)
{
grib_accessor* a = NULL;
char* p=NULL;
char* basename=NULL;
char name_space[1024];
int i=0,len=0;
grib_accessor* a = NULL;
char* p=NULL;
char* basename=NULL;
char name_space[1024];
int i=0,len=0;
p=(char*)name;
p=(char*)name;
while ( *p != '.' && *p != '\0' ) p++;
if ( *p == '.' ) {
basename=p+1;
p--;
i=0;
len=p-name+1;
while ( *p != '.' && *p != '\0' ) p++;
if ( *p == '.' ) {
basename=p+1;
p--;
i=0;
len=p-name+1;
for ( i=0;i<len;i++ ) name_space[i] = *(name+i);
for ( i=0;i<len;i++ ) name_space[i] = *(name+i);
name_space[len]='\0';
name_space[len]='\0';
a = h->accessors[grib_hash_keys_get_id(h->context->keys,name)];
if(a && !matching(a,name,name_space))
a = NULL;
a = h->accessors[grib_hash_keys_get_id(h->context->keys,name)];
if(a && !matching(a,name,name_space))
a = NULL;
} else {
a = h->accessors[grib_hash_keys_get_id(h->context->keys,name)];
}
} else {
a = h->accessors[grib_hash_keys_get_id(h->context->keys,name)];
}
if(a == NULL && h->main)
a = grib_find_accessor_fast(h->main,name);
if(a == NULL && h->main)
a = grib_find_accessor_fast(h->main,name);
return a;
return a;
}

View File

@ -243,30 +243,30 @@ grib_handle* merge(grib_handle* h1,grib_handle* h2) {
grib_get_long(h,"numberOfPoints",&n);
grib_get_double(h,"missingValue",&missingValue);
v=grib_context_malloc_clear(h->context,sizeof(double)*n);
v=(double*)grib_context_malloc_clear(h->context,sizeof(double)*n);
for (i=0;i<n;i++) v[i]=1.0;
sn=n;
grib_set_double_array(h,"values",v,sn);
for (i=0;i<n;i++) v[i]=missingValue;
lat=grib_context_malloc_clear(h->context,sizeof(double)*n);
lon=grib_context_malloc_clear(h->context,sizeof(double)*n);
lat=(double*)grib_context_malloc_clear(h->context,sizeof(double)*n);
lon=(double*)grib_context_malloc_clear(h->context,sizeof(double)*n);
sn=n;
grib_get_double_array(h,"latitudes",lat,&sn);
grib_get_double_array(h,"longitudes",lon,&sn);
grib_get_long(h1,"numberOfPoints",&n1);
v1=grib_context_malloc_clear(h->context,sizeof(double)*n1);
lat1=grib_context_malloc_clear(h->context,sizeof(double)*n1);
lon1=grib_context_malloc_clear(h->context,sizeof(double)*n1);
v1=(double*)grib_context_malloc_clear(h->context,sizeof(double)*n1);
lat1=(double*)grib_context_malloc_clear(h->context,sizeof(double)*n1);
lon1=(double*)grib_context_malloc_clear(h->context,sizeof(double)*n1);
sn=n1;
grib_get_double_array(h1,"latitudes",lat1,&sn);
grib_get_double_array(h1,"longitudes",lon1,&sn);
grib_get_double_array(h1,"values",v1,&sn);
grib_get_long(h2,"numberOfPoints",&n2);
v2=grib_context_malloc_clear(h->context,sizeof(double)*n2);
lat2=grib_context_malloc_clear(h->context,sizeof(double)*n2);
lon2=grib_context_malloc_clear(h->context,sizeof(double)*n2);
v2=(double*)grib_context_malloc_clear(h->context,sizeof(double)*n2);
lat2=(double*)grib_context_malloc_clear(h->context,sizeof(double)*n2);
lon2=(double*)grib_context_malloc_clear(h->context,sizeof(double)*n2);
sn=n2;
grib_get_double_array(h2,"latitudes",lat2,&sn);
grib_get_double_array(h2,"longitudes",lon2,&sn);