From 2a168ac30d987a81c0e33447e38d68ed43d391c4 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Fri, 18 Dec 2015 18:01:56 +0000 Subject: [PATCH] Remove compiler warnings (using clang) and code clean up --- examples/C/bufr_attributes.c | 4 +- examples/C/bufr_keys_iterator.c | 1 - examples/C/bufr_read_scatterometer.c | 2 - examples/C/bufr_set_keys.c | 2 +- src/grib_accessor_class_bufr_data_array.c | 894 ++++++++++---------- src/grib_accessor_class_bufr_data_element.c | 2 - src/grib_accessor_class_concept.c | 1 - src/grib_io.c | 3 - src/grib_loader_from_handle.c | 8 +- src/grib_parse_utils.c | 2 - src/grib_value.c | 45 +- tools/bufr_dump.c | 1 - tools/grib_tools.c | 6 +- 13 files changed, 480 insertions(+), 491 deletions(-) diff --git a/examples/C/bufr_attributes.c b/examples/C/bufr_attributes.c index 16c642498..27551dd82 100644 --- a/examples/C/bufr_attributes.c +++ b/examples/C/bufr_attributes.c @@ -29,8 +29,8 @@ int main(int argc,char* argv[]) char* unitsPercent= NULL; long longVal; double doubleVal; - size_t values_len=0, desc_len=0, len=0; - int i, err=0; + size_t len=0; + int err=0; int cnt=0; char* infile = "../../data/bufr/syno_multi.bufr"; diff --git a/examples/C/bufr_keys_iterator.c b/examples/C/bufr_keys_iterator.c index 170553a92..d0e9c8c21 100644 --- a/examples/C/bufr_keys_iterator.c +++ b/examples/C/bufr_keys_iterator.c @@ -34,7 +34,6 @@ int main(int argc,char* argv[]) /* message handle. Required in all the eccodes calls acting on a message.*/ codes_handle* h=NULL; - long longVal; int err=0, cnt=0; int keyType; diff --git a/examples/C/bufr_read_scatterometer.c b/examples/C/bufr_read_scatterometer.c index c180728e3..63d62b229 100644 --- a/examples/C/bufr_read_scatterometer.c +++ b/examples/C/bufr_read_scatterometer.c @@ -31,8 +31,6 @@ int main(int argc,char* argv[]) codes_handle* h=NULL; double *lat=NULL, *lon=NULL, *bscatter=NULL; - long longVal; - double doubleVal; long numObs=0; size_t len=0; int i, err=0; diff --git a/examples/C/bufr_set_keys.c b/examples/C/bufr_set_keys.c index 0448f2af2..c9cca4b17 100644 --- a/examples/C/bufr_set_keys.c +++ b/examples/C/bufr_set_keys.c @@ -32,7 +32,7 @@ int main(int argc,char* argv[]) long longVal; /*double doubleVal;*/ - int i, err=0; + int err=0; int cnt=0; size_t size = 0; char* infile = "../../data/bufr/syno_multi.bufr"; diff --git a/src/grib_accessor_class_bufr_data_array.c b/src/grib_accessor_class_bufr_data_array.c index ef186259b..1f4b2ac8d 100644 --- a/src/grib_accessor_class_bufr_data_array.c +++ b/src/grib_accessor_class_bufr_data_array.c @@ -272,6 +272,7 @@ static void init(grib_accessor* a,const long v, grib_arguments* params) /* Assert(a->length>=0); */ } +/* static void clean_string(char* s,int len) { int i=len-1; @@ -281,6 +282,7 @@ static void clean_string(char* s,int len) i--; } } +*/ static int check_end_data(grib_context* c,grib_accessor_bufr_data_array* self,int size) { @@ -353,10 +355,10 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) grib_vsarray* accessor_bufr_data_array_get_stringValues(grib_accessor* a) { - grib_accessor_bufr_data_array *self =(grib_accessor_bufr_data_array*)a; - process_elements(a,PROCESS_DECODE); + grib_accessor_bufr_data_array *self =(grib_accessor_bufr_data_array*)a; + process_elements(a,PROCESS_DECODE); - return self->stringValues; + return self->stringValues; } grib_accessors_list* accessor_bufr_data_array_get_dataAccessors(grib_accessor* a) @@ -424,7 +426,7 @@ static void decode_string_array(grib_context* c,unsigned char* data,long* pos, i } } else { /* for (j=0;jnumberOfSubsets;j++) { */ - grib_sarray_push(c,sa,sval); + grib_sarray_push(c,sa,sval); /* } */ } grib_vsarray_push(c,self->stringValues,sa); @@ -531,80 +533,80 @@ static int encode_double_array(grib_context* c,grib_buffer* buff,long* pos,int i v=dvalues->v; if (nvals==1) { - localWidth=0; - grib_buffer_set_ulength_bits(c,buff,buff->ulength_bits+modifiedWidth); - if (*v == GRIB_MISSING_DOUBLE) { - grib_set_bits_on(buff->data,pos,modifiedWidth); - } else { - lval=round(*v * inverseFactor)-modifiedReference; - grib_encode_unsigned_longb(buff->data,lval,pos,modifiedWidth); - } - grib_buffer_set_ulength_bits(c,buff,buff->ulength_bits+6); - grib_encode_unsigned_longb(buff->data,localWidth,pos,6); - return err; + localWidth=0; + grib_buffer_set_ulength_bits(c,buff,buff->ulength_bits+modifiedWidth); + if (*v == GRIB_MISSING_DOUBLE) { + grib_set_bits_on(buff->data,pos,modifiedWidth); + } else { + lval=round(*v * inverseFactor)-modifiedReference; + grib_encode_unsigned_longb(buff->data,lval,pos,modifiedWidth); + } + grib_buffer_set_ulength_bits(c,buff,buff->ulength_bits+6); + grib_encode_unsigned_longb(buff->data,localWidth,pos,6); + return err; } ii=0; while (*v==GRIB_MISSING_DOUBLE && iimax && *v!=GRIB_MISSING_DOUBLE) max=*v; - if (*v == GRIB_MISSING_DOUBLE) thereIsAMissing=1; - ii++; - v++; + if (*vmax && *v!=GRIB_MISSING_DOUBLE) max=*v; + if (*v == GRIB_MISSING_DOUBLE) thereIsAMissing=1; + ii++; + v++; } if (max>maxAllowed && max!=GRIB_MISSING_DOUBLE) - return GRIB_OUT_OF_RANGE; + return GRIB_OUT_OF_RANGE; if (minulength_bits+modifiedWidth); if (localWidth) { - grib_encode_unsigned_longb(buff->data,localReference,pos,modifiedWidth); + grib_encode_unsigned_longb(buff->data,localReference,pos,modifiedWidth); } else { - if (min==GRIB_MISSING_DOUBLE) { - grib_set_bits_on(buff->data,pos,modifiedWidth); - } else { - lval=localReference-modifiedReference; - grib_encode_unsigned_longb(buff->data,lval,pos,modifiedWidth); - } + if (min==GRIB_MISSING_DOUBLE) { + grib_set_bits_on(buff->data,pos,modifiedWidth); + } else { + lval=localReference-modifiedReference; + grib_encode_unsigned_longb(buff->data,lval,pos,modifiedWidth); + } } grib_buffer_set_ulength_bits(c,buff,buff->ulength_bits+6); grib_encode_unsigned_longb(buff->data,localWidth,pos,6); if (localWidth) { - grib_buffer_set_ulength_bits(c,buff,buff->ulength_bits+self->numberOfSubsets*localWidth); - for (j=0;jnumberOfSubsets;j++) { - if (dvalues->v[j]==GRIB_MISSING_DOUBLE) { - grib_set_bits_on(buff->data,pos,localWidth); - } else { - lval=round(dvalues->v[j]*inverseFactor)-reference; - grib_encode_unsigned_longb(buff->data,lval,pos,localWidth); + grib_buffer_set_ulength_bits(c,buff,buff->ulength_bits+self->numberOfSubsets*localWidth); + for (j=0;jnumberOfSubsets;j++) { + if (dvalues->v[j]==GRIB_MISSING_DOUBLE) { + grib_set_bits_on(buff->data,pos,localWidth); + } else { + lval=round(dvalues->v[j]*inverseFactor)-reference; + grib_encode_unsigned_longb(buff->data,lval,pos,localWidth); + } } - } } return err; @@ -730,7 +732,7 @@ static int decode_element(grib_context* c,grib_accessor_bufr_data_array* self,in stringValuesLen=grib_vsarray_used_size(self->stringValues); index=0; for (ii=0;iistringValues->v[ii]); + index+=grib_sarray_used_size(self->stringValues->v[ii]); } cdval=index*1000+self->expanded->v[i]->width / 8; grib_darray_push(c,dval,cdval); @@ -751,7 +753,7 @@ static int decode_element(grib_context* c,grib_accessor_bufr_data_array* self,in } static int decode_replication(grib_context* c,grib_accessor_bufr_data_array* self,int subsetIndex, - grib_buffer* buff,unsigned char* data,long *pos,int i,long elementIndex,grib_darray* dval,long* numberOfRepetitions) + grib_buffer* buff,unsigned char* data,long *pos,int i,long elementIndex,grib_darray* dval,long* numberOfRepetitions) { int err=0; int localReference,width; @@ -793,7 +795,7 @@ static int decode_replication(grib_context* c,grib_accessor_bufr_data_array* sel static int encode_new_element(grib_context* c,grib_accessor_bufr_data_array* self,int subsetIndex, grib_buffer* buff,unsigned char* data,long *pos,int i,long elementIndex,grib_darray* dval,grib_sarray* sval) { - int index=0,ii; + int ii; char* csval=0; unsigned char missingChar=0xFF; double cdval=GRIB_MISSING_DOUBLE; @@ -836,7 +838,7 @@ static int encode_new_element(grib_context* c,grib_accessor_bufr_data_array* sel } static int encode_new_replication(grib_context* c,grib_accessor_bufr_data_array* self,int subsetIndex, - grib_buffer* buff,unsigned char* data,long *pos,int i,long elementIndex,grib_darray* dval,long* numberOfRepetitions) + grib_buffer* buff,unsigned char* data,long *pos,int i,long elementIndex,grib_darray* dval,long* numberOfRepetitions) { int err=0; /*new data -> only 1 repetition*/ @@ -861,10 +863,8 @@ static int encode_new_replication(grib_context* c,grib_accessor_bufr_data_array* static int encode_element(grib_context* c,grib_accessor_bufr_data_array* self,int subsetIndex, grib_buffer* buff,unsigned char* data,long *pos,int i,long elementIndex,grib_darray* dval,grib_sarray* sval) { - int index=0,ii,idx,j; - char* csval=0; + int idx,j; int err=0; - size_t slen; grib_context_log(c, GRIB_LOG_DEBUG,"BUFR data encoding: -%ld- \tcode=%6.6ld width=%ld pos=%ld ulength=%ld ulength_bits=%ld", i,self->expanded->v[i]->code,self->expanded->v[i]->width,(long)*pos,buff->ulength,buff->ulength_bits); @@ -884,16 +884,16 @@ static int encode_element(grib_context* c,grib_accessor_bufr_data_array* self,in if (self->compressedData) { err=encode_double_array(c,buff,pos,i,self,self->numericValues->v[elementIndex]); if (err) { - grib_context_log(c,GRIB_LOG_ERROR,"encoding %s ( code=%6.6ld width=%ld scale=%g reference=%d )", - self->expanded->v[i]->shortName, self->expanded->v[i]->code, self->expanded->v[i]->width, - self->expanded->v[i]->scale, self->expanded->v[i]->reference); - for (j=0;jnumericValues->v[elementIndex]);j++) - grib_context_log(c,GRIB_LOG_ERROR,"%g ",self->numericValues->v[elementIndex]->v[i]); + grib_context_log(c,GRIB_LOG_ERROR,"encoding %s ( code=%6.6ld width=%ld scale=%g reference=%d )", + self->expanded->v[i]->shortName, self->expanded->v[i]->code, self->expanded->v[i]->width, + self->expanded->v[i]->scale, self->expanded->v[i]->reference); + for (j=0;jnumericValues->v[elementIndex]);j++) + grib_context_log(c,GRIB_LOG_ERROR,"%g ",self->numericValues->v[elementIndex]->v[i]); } } else { err=encode_double_value(c,buff,pos,i,self,self->numericValues->v[subsetIndex]->v[elementIndex]); if (err) { - grib_context_log(c,GRIB_LOG_ERROR,"encoding %s=%g",self->expanded->v[i]->shortName,self->numericValues->v[subsetIndex]->v[elementIndex]); + grib_context_log(c,GRIB_LOG_ERROR,"encoding %s=%g",self->expanded->v[i]->shortName,self->numericValues->v[subsetIndex]->v[elementIndex]); } } } @@ -901,20 +901,16 @@ static int encode_element(grib_context* c,grib_accessor_bufr_data_array* self,in } static int encode_replication(grib_context* c,grib_accessor_bufr_data_array* self,int subsetIndex, -grib_buffer* buff,unsigned char* data,long *pos,int i,long elementIndex,grib_darray* dval,long* numberOfRepetitions) + grib_buffer* buff,unsigned char* data,long *pos,int i,long elementIndex,grib_darray* dval,long* numberOfRepetitions) { - bufr_descriptor** descriptors=0; - if (self->compressedData) { - Assert(grib_darray_used_size(self->numericValues->v[elementIndex])==1); - *numberOfRepetitions=self->numericValues->v[elementIndex]->v[0]; + Assert(grib_darray_used_size(self->numericValues->v[elementIndex])==1); + *numberOfRepetitions=self->numericValues->v[elementIndex]->v[0]; } else { - *numberOfRepetitions=self->numericValues->v[subsetIndex]->v[elementIndex]; + *numberOfRepetitions=self->numericValues->v[subsetIndex]->v[elementIndex]; } - return encode_element(c,self,subsetIndex,buff,data,pos,i,elementIndex,dval,0); - } static int build_bitmap(grib_accessor_bufr_data_array *self,unsigned char* data,long* pos,int iel,grib_iarray* elementsDescriptorsIndex,int iBitmapOperator) @@ -1135,9 +1131,7 @@ static grib_accessor* create_accessor_from_descriptor(grib_accessor* a,grib_acce grib_accessor_bufr_data_array *self =(grib_accessor_bufr_data_array*)a; char code[10]={0,}; int idx=0; - int i; unsigned long flags=0; - grib_accessor* operatorAccessor=NULL; grib_action operatorCreator = {0, }; grib_accessor* elementAccessor=NULL; grib_action creator = {0, }; @@ -1180,13 +1174,13 @@ static grib_accessor* create_accessor_from_descriptor(grib_accessor* a,grib_acce self->expanded->v[idx]->a=elementAccessor; if (attribute) { - /* attribute->parent=elementAccessor->parent; */ - /* + /* attribute->parent=elementAccessor->parent; */ + /* for (i=0;iattributes[i]) attribute->attributes[i]->parent=elementAccessor->parent; } - */ - grib_accessor_add_attribute(elementAccessor,attribute); + */ + grib_accessor_add_attribute(elementAccessor,attribute); } attribute=create_attribute_variable("index",section,GRIB_TYPE_LONG,0,0,count,flags); @@ -1311,7 +1305,6 @@ static grib_accessor* get_element_from_bitmap(grib_accessor* a,bitmap_s* bitmap) int ret; long bitmapVal=1; size_t len; - grib_accessor_bufr_data_array *self =(grib_accessor_bufr_data_array*)a; while (bitmapVal) { len=1; @@ -1328,18 +1321,21 @@ static grib_accessor* get_element_from_bitmap(grib_accessor* a,bitmap_s* bitmap) return bitmap->referredElement ? bitmap->referredElement->prev->accessor : NULL ; } +/* static GRIB_INLINE void reset_qualifiers(grib_accessor* significanceQualifierGroup[]) { int i; for (i=0;ih==NULL && a->parent!=NULL) { - a->h=grib_handle_of_accessor(a); - a->parent=NULL; - } +static void grib_convert_to_attribute(grib_accessor* a) +{ + if (a->h==NULL && a->parent!=NULL) { + a->h=grib_handle_of_accessor(a); + a->parent=NULL; + } } static int create_keys(grib_accessor* a) @@ -1410,168 +1406,168 @@ static int create_keys(grib_accessor* a) extraElement=0; for (iss=0;isscompressedData ? grib_iarray_used_size(self->elementsDescriptorsIndex->v[0]) : - grib_iarray_used_size(self->elementsDescriptorsIndex->v[iss]); - associatedFieldAccessor=NULL; - associatedFieldSignificanceAccessor=NULL; - for (ide=0;idecompressedData ? self->elementsDescriptorsIndex->v[0]->v[ide] : - self->elementsDescriptorsIndex->v[iss]->v[ide] ; + qualityPresent=0; + forceGroupClosure=0; + elementsInSubset= self->compressedData ? grib_iarray_used_size(self->elementsDescriptorsIndex->v[0]) : + grib_iarray_used_size(self->elementsDescriptorsIndex->v[iss]); + associatedFieldAccessor=NULL; + associatedFieldSignificanceAccessor=NULL; + for (ide=0;idecompressedData ? self->elementsDescriptorsIndex->v[0]->v[ide] : + self->elementsDescriptorsIndex->v[iss]->v[ide] ; - descriptor=self->expanded->v[idx]; - elementFromBitmap=NULL; - if (descriptor->F==0 && IS_QUALIFIER(descriptor->X) + descriptor=self->expanded->v[idx]; + elementFromBitmap=NULL; + if (descriptor->F==0 && IS_QUALIFIER(descriptor->X) && self->unpackMode==CODES_BUFR_UNPACK_STRUCTURE) { - int sidx=significanceQualifierIndex(descriptor->X,descriptor->Y); - groupNumber++; + int sidx=significanceQualifierIndex(descriptor->X,descriptor->Y); + groupNumber++; - if (significanceQualifierGroup[sidx]) { - groupSection=significanceQualifierGroup[sidx]->parent; - depth=significanceQualifierDepth[sidx]; - reset_deeper_qualifiers(significanceQualifierGroup,significanceQualifierDepth,depth); - } else { - /* if (forceGroupClosure) { */ - /* groupSection=sectionUp; */ - /* forceGroupClosure=0; */ - /* depth=0; */ - /* } else { */ - groupSection=section; - depth++; - /* } */ - } + if (significanceQualifierGroup[sidx]) { + groupSection=significanceQualifierGroup[sidx]->parent; + depth=significanceQualifierDepth[sidx]; + reset_deeper_qualifiers(significanceQualifierGroup,significanceQualifierDepth,depth); + } else { + /* if (forceGroupClosure) { */ + /* groupSection=sectionUp; */ + /* forceGroupClosure=0; */ + /* depth=0; */ + /* } else { */ + groupSection=section; + depth++; + /* } */ + } - gaGroup = grib_accessor_factory(groupSection, &creatorGroup, 0, NULL); - gaGroup->sub_section=grib_section_create(grib_handle_of_accessor(a),gaGroup); - gaGroup->bufr_group_number=groupNumber; - accessor_constant_set_type(gaGroup,GRIB_TYPE_LONG); - accessor_constant_set_dval(gaGroup,groupNumber); - grib_push_accessor(gaGroup,groupSection->block); + gaGroup = grib_accessor_factory(groupSection, &creatorGroup, 0, NULL); + gaGroup->sub_section=grib_section_create(grib_handle_of_accessor(a),gaGroup); + gaGroup->bufr_group_number=groupNumber; + accessor_constant_set_type(gaGroup,GRIB_TYPE_LONG); + accessor_constant_set_dval(gaGroup,groupNumber); + grib_push_accessor(gaGroup,groupSection->block); - section=gaGroup->sub_section; - sectionUp=gaGroup->parent; + section=gaGroup->sub_section; + sectionUp=gaGroup->parent; - significanceQualifierGroup[sidx]=gaGroup; - significanceQualifierDepth[sidx]=depth; - incrementBitmapIndex=1; - dump=1; - } else if (descriptor->code == 31031 && incrementBitmapIndex!=0) { - /* bitmap */ - bitmapIndex++; - groupNumber++; - incrementBitmapIndex=0; - bitmapStart[bitmapIndex]=grib_accessors_list_last(self->dataAccessors); - bitmapSize[bitmapIndex]=1; - if (self->expanded->v[idx-1]->code ==31002 || self->expanded->v[idx-1]->code==31001) - extraElement=1; - if (bitmapGroup[bitmapIndex]) { - groupSection=bitmapGroup[bitmapIndex]->parent; - depth=bitmapDepth[bitmapIndex]; - reset_deeper_qualifiers(significanceQualifierGroup,significanceQualifierDepth,depth); - reset_deeper_qualifiers(bitmapGroup,bitmapDepth,depth); - } else { - groupSection=section; - depth++; - } - gaGroup = grib_accessor_factory(groupSection, &creatorGroup, 0, NULL); - gaGroup->sub_section=grib_section_create(grib_handle_of_accessor(a),gaGroup); - gaGroup->bufr_group_number=groupNumber; - accessor_constant_set_type(gaGroup,GRIB_TYPE_LONG); - accessor_constant_set_dval(gaGroup,groupNumber); - grib_push_accessor(gaGroup,groupSection->block); + significanceQualifierGroup[sidx]=gaGroup; + significanceQualifierDepth[sidx]=depth; + incrementBitmapIndex=1; + dump=1; + } else if (descriptor->code == 31031 && incrementBitmapIndex!=0) { + /* bitmap */ + bitmapIndex++; + groupNumber++; + incrementBitmapIndex=0; + bitmapStart[bitmapIndex]=grib_accessors_list_last(self->dataAccessors); + bitmapSize[bitmapIndex]=1; + if (self->expanded->v[idx-1]->code ==31002 || self->expanded->v[idx-1]->code==31001) + extraElement=1; + if (bitmapGroup[bitmapIndex]) { + groupSection=bitmapGroup[bitmapIndex]->parent; + depth=bitmapDepth[bitmapIndex]; + reset_deeper_qualifiers(significanceQualifierGroup,significanceQualifierDepth,depth); + reset_deeper_qualifiers(bitmapGroup,bitmapDepth,depth); + } else { + groupSection=section; + depth++; + } + gaGroup = grib_accessor_factory(groupSection, &creatorGroup, 0, NULL); + gaGroup->sub_section=grib_section_create(grib_handle_of_accessor(a),gaGroup); + gaGroup->bufr_group_number=groupNumber; + accessor_constant_set_type(gaGroup,GRIB_TYPE_LONG); + accessor_constant_set_dval(gaGroup,groupNumber); + grib_push_accessor(gaGroup,groupSection->block); - section=gaGroup->sub_section; - sectionUp=gaGroup->parent; - bitmapGroup[bitmapIndex]=gaGroup; - bitmapDepth[bitmapIndex]=depth; - dump=1; - } else if (descriptor->code == 31031) { - dump=1; - bitmapSize[bitmapIndex]++; - bitmap.cursor=0; - } else if (descriptor->code == 222000 || descriptor->code == 224000 ) { - bitmap.referredElement=NULL; - qualityPresent=1; - incrementBitmapIndex=1; - dump=1; - } else if (descriptor->code == 236000 ) { - bitmap.referredElement=NULL; - bitmap.cursor=0; - reuseBitmap=1; - extraElement=1; - dump=1; - } else if (descriptor->code == 236000 || descriptor->code == 237000 ) { - bitmap.referredElement=NULL; - bitmap.cursor=0; - reuseBitmap=1; - dump=1; - } else if (descriptor->code == 237255 ) { - reuseBitmap=0; - incrementBitmapIndex=1; - bitmap.cursor=0; - dump=1; - } else if ( ( descriptor->X==33 || descriptor->isMarker ) && qualityPresent) { - if (!bitmap.referredElement) { - bitmap.cursor=bitmapStart[bitmapIndex]->next; - bitmap.referredElement=bitmapStart[bitmapIndex]; - for (i=0;iprev; + section=gaGroup->sub_section; + sectionUp=gaGroup->parent; + bitmapGroup[bitmapIndex]=gaGroup; + bitmapDepth[bitmapIndex]=depth; + dump=1; + } else if (descriptor->code == 31031) { + dump=1; + bitmapSize[bitmapIndex]++; + bitmap.cursor=0; + } else if (descriptor->code == 222000 || descriptor->code == 224000 ) { + bitmap.referredElement=NULL; + qualityPresent=1; + incrementBitmapIndex=1; + dump=1; + } else if (descriptor->code == 236000 ) { + bitmap.referredElement=NULL; + bitmap.cursor=0; + reuseBitmap=1; + extraElement=1; + dump=1; + } else if (descriptor->code == 236000 || descriptor->code == 237000 ) { + bitmap.referredElement=NULL; + bitmap.cursor=0; + reuseBitmap=1; + dump=1; + } else if (descriptor->code == 237255 ) { + reuseBitmap=0; + incrementBitmapIndex=1; + bitmap.cursor=0; + dump=1; + } else if ( ( descriptor->X==33 || descriptor->isMarker ) && qualityPresent) { + if (!bitmap.referredElement) { + bitmap.cursor=bitmapStart[bitmapIndex]->next; + bitmap.referredElement=bitmapStart[bitmapIndex]; + for (i=0;iprev; + } + } + elementFromBitmap=get_element_from_bitmap(a,&bitmap); + dump=1; + /* } else if ( descriptor->Y==1 && IS_QUALIFIER(self->expanded->v[idx-1]->X)==0) { */ + /* forceGroupClosure=1; */ + /* reset_qualifiers(significanceQualifierGroup); */ } - } - elementFromBitmap=get_element_from_bitmap(a,&bitmap); - dump=1; - /* } else if ( descriptor->Y==1 && IS_QUALIFIER(self->expanded->v[idx-1]->X)==0) { */ - /* forceGroupClosure=1; */ - /* reset_qualifiers(significanceQualifierGroup); */ - } - if (ide==0 && !self->compressedData) { - grib_accessor* asn=NULL; - long subsetNumber=iss+1; - size_t len=1; - grib_action creatorsn = {0, }; - creatorsn.op = "variable"; - creatorsn.name_space = ""; - creatorsn.flags = GRIB_ACCESSOR_FLAG_READ_ONLY | GRIB_ACCESSOR_FLAG_DUMP ; - creatorsn.set = 0; + if (ide==0 && !self->compressedData) { + grib_accessor* asn=NULL; + long subsetNumber=iss+1; + size_t len=1; + grib_action creatorsn = {0, }; + creatorsn.op = "variable"; + creatorsn.name_space = ""; + creatorsn.flags = GRIB_ACCESSOR_FLAG_READ_ONLY | GRIB_ACCESSOR_FLAG_DUMP ; + creatorsn.set = 0; - creatorsn.name="subsetNumber"; - asn=grib_accessor_factory(section, &creatorsn, 0, NULL); - accessor_variable_set_type(asn,GRIB_TYPE_LONG); - grib_pack_long(asn,&subsetNumber,&len); + creatorsn.name="subsetNumber"; + asn=grib_accessor_factory(section, &creatorsn, 0, NULL); + accessor_variable_set_type(asn,GRIB_TYPE_LONG); + grib_pack_long(asn,&subsetNumber,&len); - grib_push_accessor(asn,section->block); - grib_accessors_list_push(self->dataAccessors,asn); - } - count++; - elementAccessor=create_accessor_from_descriptor(a,associatedFieldAccessor,section,ide,iss,dump,count); - associatedFieldAccessor=NULL; - if (elementFromBitmap && self->unpackMode==CODES_BUFR_UNPACK_STRUCTURE) { - grib_accessor_add_attribute(elementFromBitmap,elementAccessor); - } else if (elementAccessor) { - - switch (descriptor->code) { - case 999999: - associatedFieldAccessor=elementAccessor; - grib_convert_to_attribute(associatedFieldAccessor); - if (associatedFieldSignificanceAccessor) { - grib_accessor* newAccessor=grib_accessor_clone(associatedFieldSignificanceAccessor,section,&err); - if (err) { - grib_context_log(a->context,GRIB_LOG_ERROR,"unable to clone accessor '%s'\n",associatedFieldSignificanceAccessor->name); - return err; - } - grib_accessor_add_attribute(associatedFieldAccessor,newAccessor); + grib_push_accessor(asn,section->block); + grib_accessors_list_push(self->dataAccessors,asn); + } + count++; + elementAccessor=create_accessor_from_descriptor(a,associatedFieldAccessor,section,ide,iss,dump,count); + associatedFieldAccessor=NULL; + if (elementFromBitmap && self->unpackMode==CODES_BUFR_UNPACK_STRUCTURE) { + grib_accessor_add_attribute(elementFromBitmap,elementAccessor); + } else if (elementAccessor) { + + switch (descriptor->code) { + case 999999: + associatedFieldAccessor=elementAccessor; + grib_convert_to_attribute(associatedFieldAccessor); + if (associatedFieldSignificanceAccessor) { + grib_accessor* newAccessor=grib_accessor_clone(associatedFieldSignificanceAccessor,section,&err); + if (err) { + grib_context_log(a->context,GRIB_LOG_ERROR,"unable to clone accessor '%s'\n",associatedFieldSignificanceAccessor->name); + return err; + } + grib_accessor_add_attribute(associatedFieldAccessor,newAccessor); + } + break; + case 31021: + associatedFieldSignificanceAccessor=elementAccessor; + default: + grib_push_accessor(elementAccessor,section->block); + grib_accessors_list_push(self->dataAccessors,elementAccessor); + } } - break; - case 31021: - associatedFieldSignificanceAccessor=elementAccessor; - default: - grib_push_accessor(elementAccessor,section->block); - grib_accessors_list_push(self->dataAccessors,elementAccessor); } - } - } } return err; @@ -1591,7 +1587,7 @@ static int process_elements(grib_accessor* a,int flag) unsigned char* data=0; int i; grib_iarray* elementsDescriptorsIndex=0; - long localReference=0,width=0; + long pos=0; int iss,end,elementIndex,index; long numberOfDescriptors; @@ -1613,7 +1609,7 @@ static int process_elements(grib_accessor* a,int flag) totalSize=self->bitsToEndData; switch (flag) { - case PROCESS_DECODE: + case PROCESS_DECODE: if (!self->do_decode) return 0; self->do_decode=0; buffer=h->buffer; @@ -1623,7 +1619,7 @@ static int process_elements(grib_accessor* a,int flag) codec_element=&decode_element; codec_replication=&decode_replication; break; - case PROCESS_NEW_DATA: + case PROCESS_NEW_DATA: buffer=grib_create_growable_buffer(c); decoding=0; do_clean=1; @@ -1632,7 +1628,7 @@ static int process_elements(grib_accessor* a,int flag) codec_element=&encode_new_element; codec_replication=&encode_new_replication; break; - case PROCESS_ENCODE: + case PROCESS_ENCODE: buffer=grib_create_growable_buffer(c); decoding=0; do_clean=0; @@ -1641,7 +1637,7 @@ static int process_elements(grib_accessor* a,int flag) codec_element=&encode_element; codec_replication=&encode_replication; break; - default : + default : return GRIB_NOT_IMPLEMENTED; } data=(unsigned char*)buffer->data; @@ -1652,18 +1648,18 @@ static int process_elements(grib_accessor* a,int flag) descriptors=self->expanded->v; if (do_clean==1 && self->numericValues) { - grib_vdarray_delete_content(c,self->numericValues); - grib_vdarray_delete(c,self->numericValues); - grib_vsarray_delete_content(c,self->stringValues); - grib_vsarray_delete(c,self->stringValues); + grib_vdarray_delete_content(c,self->numericValues); + grib_vdarray_delete(c,self->numericValues); + grib_vsarray_delete_content(c,self->stringValues); + grib_vsarray_delete(c,self->stringValues); } if (flag!=PROCESS_ENCODE) { - self->numericValues=grib_vdarray_new(c,100,100); - self->stringValues=grib_vsarray_new(c,10,10); + self->numericValues=grib_vdarray_new(c,100,100); + self->stringValues=grib_vsarray_new(c,10,10); - if (self->elementsDescriptorsIndex) grib_viarray_delete(c,self->elementsDescriptorsIndex); - self->elementsDescriptorsIndex=grib_viarray_new(c,100,100); + if (self->elementsDescriptorsIndex) grib_viarray_delete(c,self->elementsDescriptorsIndex); + self->elementsDescriptorsIndex=grib_viarray_new(c,100,100); } end= self->compressedData ? 1 : self->numberOfSubsets; @@ -1671,201 +1667,201 @@ static int process_elements(grib_accessor* a,int flag) numberOfDescriptors=grib_bufr_descriptors_array_used_size(self->expanded); for (iss=0;isscompressedData) { - dval=grib_darray_new(c,100,100); - /* sval=grib_sarray_new(c,10,10); */ + if (flag!=PROCESS_ENCODE) { + elementsDescriptorsIndex=grib_iarray_new(c,100,100); + if (!self->compressedData) { + dval=grib_darray_new(c,100,100); + /* sval=grib_sarray_new(c,10,10); */ + } + } else { + elementsDescriptorsIndex=self->elementsDescriptorsIndex->v[iss]; + dval=self->numericValues->v[iss]; } - } else { - elementsDescriptorsIndex=self->elementsDescriptorsIndex->v[iss]; - dval=self->numericValues->v[iss]; - } - elementIndex=0; + elementIndex=0; - for (i=0;icode); - switch(descriptors[i]->F) { - case 0: - /* Table B element */ - if (flag!=PROCESS_ENCODE) grib_iarray_push(elementsDescriptorsIndex,i); - if (descriptors[i]->code==31031 && !is_bitmap_start_defined(self)) { - /* self->bitmapStart=grib_iarray_used_size(elementsDescriptorsIndex)-1; */ - self->bitmapStart=elementIndex; - } - err=codec_element(c,self,iss,buffer,data,&pos,i,elementIndex,dval,sval); - if (err) return err; - elementIndex++; - break; - case 1: - /* Delayed replication */ - inr=numberOfNestedRepetitions; - numberOfNestedRepetitions++; - Assert(numberOfNestedRepetitions<=MAX_NESTED_REPLICATIONS); - numberOfElementsToRepeat[inr]=descriptors[i]->X; - n[inr]=numberOfElementsToRepeat[inr]; - i++; - - err=codec_replication(c,self,iss,buffer,data,&pos,i,elementIndex,dval,&(numberOfRepetitions[inr])); - if (err) return err; - - startRepetition[inr]=i; - nn[inr]=numberOfRepetitions[inr]; - if (flag!=PROCESS_ENCODE) grib_iarray_push(elementsDescriptorsIndex,i); - elementIndex++; - if (numberOfRepetitions[inr]==0) { - i+=numberOfElementsToRepeat[inr]; - if (inr>0) { - n[inr-1]-=numberOfElementsToRepeat[inr]+2; - /* if the empty nested repetion is at the end of the nesting repetition - we need to repoint to the start of the nesting repetition */ - if (n[inr-1]==0) { - nn[inr-1]--; - if (nn[inr-1]<=0) numberOfNestedRepetitions--; + for (i=0;icode); + switch(descriptors[i]->F) { + case 0: + /* Table B element */ + if (flag!=PROCESS_ENCODE) grib_iarray_push(elementsDescriptorsIndex,i); + if (descriptors[i]->code==31031 && !is_bitmap_start_defined(self)) { + /* self->bitmapStart=grib_iarray_used_size(elementsDescriptorsIndex)-1; */ + self->bitmapStart=elementIndex; } - } - numberOfNestedRepetitions--; - } - continue; - case 2: - /* Operator */ - associatedFieldWidth=0; - localDescriptorWidth=0; - switch(descriptors[i]->X) { - case 5: - descriptors[i]->width=descriptors[i]->Y*8; - descriptors[i]->type=BUFR_DESCRIPTOR_TYPE_STRING; err=codec_element(c,self,iss,buffer,data,&pos,i,elementIndex,dval,sval); if (err) return err; - if (flag!=PROCESS_ENCODE) grib_iarray_push(elementsDescriptorsIndex,i); elementIndex++; break; - case 22: - case 26: - case 27: - case 29: - case 30: - case 31: - case 33: - case 34: - case 38: - case 39: - case 40: - case 41: - case 42: + case 1: + /* Delayed replication */ + inr=numberOfNestedRepetitions; + numberOfNestedRepetitions++; + Assert(numberOfNestedRepetitions<=MAX_NESTED_REPLICATIONS); + numberOfElementsToRepeat[inr]=descriptors[i]->X; + n[inr]=numberOfElementsToRepeat[inr]; + i++; + + err=codec_replication(c,self,iss,buffer,data,&pos,i,elementIndex,dval,&(numberOfRepetitions[inr])); + if (err) return err; + + startRepetition[inr]=i; + nn[inr]=numberOfRepetitions[inr]; if (flag!=PROCESS_ENCODE) grib_iarray_push(elementsDescriptorsIndex,i); - if (decoding) push_zero_element(self,dval); elementIndex++; - break; - case 23: - /* substituted values marker operator */ - case 24: - /*first-order statistical values marker operator*/ - case 32: - /*replaced/retained values marker operator*/ - if (descriptors[i]->Y==255) { - index=get_next_bitmap_descriptor_index(self,elementsDescriptorsIndex,dval); - err=codec_element(c,self,iss,buffer,data,&pos,index,elementIndex,dval,sval); - if (err) return err; - /* self->expanded->v[index] */ - if (flag!=PROCESS_ENCODE) grib_iarray_push(elementsDescriptorsIndex,i); - elementIndex++; - } else { - if (flag!=PROCESS_ENCODE) grib_iarray_push(elementsDescriptorsIndex,i); - if (decoding) push_zero_element(self,dval); - elementIndex++; + if (numberOfRepetitions[inr]==0) { + i+=numberOfElementsToRepeat[inr]; + if (inr>0) { + n[inr-1]-=numberOfElementsToRepeat[inr]+2; + /* if the empty nested repetion is at the end of the nesting repetition + we need to repoint to the start of the nesting repetition */ + if (n[inr-1]==0) { + nn[inr-1]--; + if (nn[inr-1]<=0) numberOfNestedRepetitions--; + } + } + numberOfNestedRepetitions--; + } + continue; + case 2: + /* Operator */ + associatedFieldWidth=0; + localDescriptorWidth=0; + switch(descriptors[i]->X) { + case 5: + descriptors[i]->width=descriptors[i]->Y*8; + descriptors[i]->type=BUFR_DESCRIPTOR_TYPE_STRING; + err=codec_element(c,self,iss,buffer,data,&pos,i,elementIndex,dval,sval); + if (err) return err; + if (flag!=PROCESS_ENCODE) grib_iarray_push(elementsDescriptorsIndex,i); + elementIndex++; + break; + case 22: + case 26: + case 27: + case 29: + case 30: + case 31: + case 33: + case 34: + case 38: + case 39: + case 40: + case 41: + case 42: + if (flag!=PROCESS_ENCODE) grib_iarray_push(elementsDescriptorsIndex,i); + if (decoding) push_zero_element(self,dval); + elementIndex++; + break; + case 23: + /* substituted values marker operator */ + case 24: + /*first-order statistical values marker operator*/ + case 32: + /*replaced/retained values marker operator*/ + if (descriptors[i]->Y==255) { + index=get_next_bitmap_descriptor_index(self,elementsDescriptorsIndex,dval); + err=codec_element(c,self,iss,buffer,data,&pos,index,elementIndex,dval,sval); + if (err) return err; + /* self->expanded->v[index] */ + if (flag!=PROCESS_ENCODE) grib_iarray_push(elementsDescriptorsIndex,i); + elementIndex++; + } else { + if (flag!=PROCESS_ENCODE) grib_iarray_push(elementsDescriptorsIndex,i); + if (decoding) push_zero_element(self,dval); + elementIndex++; + } + break; + case 25: + /*difference statistical values marker operator*/ + break; + case 35: + /* cancel bitmap */ + if (flag!=PROCESS_ENCODE) { + grib_iarray_push(elementsDescriptorsIndex,i); + if (decoding) push_zero_element(self,dval); + if (descriptors[i]->Y==0) cancel_bitmap(self); + } + elementIndex++; + break; + case 36: + /* bitmap */ + if (flag!=PROCESS_ENCODE) { + grib_iarray_push(elementsDescriptorsIndex,i); + if (decoding) push_zero_element(self,dval); + build_bitmap(self,data,&pos,elementIndex,elementsDescriptorsIndex,i); + } else { + restart_bitmap(self); + } + elementIndex++; + break; + case 37: + /* reuse defined bitmap */ + if (flag!=PROCESS_ENCODE) { + grib_iarray_push(elementsDescriptorsIndex,i); + if (decoding) push_zero_element(self,dval); + } + if (descriptors[i]->Y==0) restart_bitmap(self); + /* cancel reuse */ + else cancel_bitmap(self); + elementIndex++; + break; + default : + grib_context_log(c,GRIB_LOG_ERROR,"unsupported operator %d\n",descriptors[i]->X); + return GRIB_INTERNAL_ERROR; } break; - case 25: - /*difference statistical values marker operator*/ - break; - case 35: - /* cancel bitmap */ - if (flag!=PROCESS_ENCODE) { - grib_iarray_push(elementsDescriptorsIndex,i); - if (decoding) push_zero_element(self,dval); - if (descriptors[i]->Y==0) cancel_bitmap(self); - } - elementIndex++; - break; - case 36: - /* bitmap */ - if (flag!=PROCESS_ENCODE) { - grib_iarray_push(elementsDescriptorsIndex,i); - if (decoding) push_zero_element(self,dval); - build_bitmap(self,data,&pos,elementIndex,elementsDescriptorsIndex,i); - } else { - restart_bitmap(self); - } - elementIndex++; - break; - case 37: - /* reuse defined bitmap */ - if (flag!=PROCESS_ENCODE) { - grib_iarray_push(elementsDescriptorsIndex,i); - if (decoding) push_zero_element(self,dval); - } - if (descriptors[i]->Y==0) restart_bitmap(self); - /* cancel reuse */ - else cancel_bitmap(self); - elementIndex++; - break; - default : - grib_context_log(c,GRIB_LOG_ERROR,"unsupported operator %d\n",descriptors[i]->X); - return GRIB_INTERNAL_ERROR; + case 9: + /* associated field */ + if (descriptors[i]->X==99 && descriptors[i]->Y==999) { + err=codec_element(c,self,iss,buffer,data,&pos,i,elementIndex,dval,sval); + if (err) return err; + if (flag!=PROCESS_ENCODE) grib_iarray_push(elementsDescriptorsIndex,i); + elementIndex++; + } else { + return GRIB_INTERNAL_ERROR; + } + break; + default: + err=GRIB_INTERNAL_ERROR; + return err; } - break; - case 9: - /* associated field */ - if (descriptors[i]->X==99 && descriptors[i]->Y==999) { - err=codec_element(c,self,iss,buffer,data,&pos,i,elementIndex,dval,sval); - if (err) return err; - if (flag!=PROCESS_ENCODE) grib_iarray_push(elementsDescriptorsIndex,i); - elementIndex++; - } else { - return GRIB_INTERNAL_ERROR; - } - break; - default: - err=GRIB_INTERNAL_ERROR; - return err; - } - /* delayed repetition check */ - innr=numberOfNestedRepetitions-1; - for (ir=innr;ir>=0;ir--) { - if (nn[ir]) { - if (n[ir]>1) { - n[ir]--; - break; - } else { - n[ir]=numberOfElementsToRepeat[ir]; - nn[ir]--; - if (nn[ir]) { - i=startRepetition[ir]; - break; - } else { - if (ir>0) { - n[ir-1]-=numberOfElementsToRepeat[ir]+2; + /* delayed repetition check */ + innr=numberOfNestedRepetitions-1; + for (ir=innr;ir>=0;ir--) { + if (nn[ir]) { + if (n[ir]>1) { + n[ir]--; + break; + } else { + n[ir]=numberOfElementsToRepeat[ir]; + nn[ir]--; + if (nn[ir]) { + i=startRepetition[ir]; + break; + } else { + if (ir>0) { + n[ir-1]-=numberOfElementsToRepeat[ir]+2; + } + i=startRepetition[ir]+numberOfElementsToRepeat[ir]; + numberOfNestedRepetitions--; + } + } + } else { + if (ir==0) { + i=startRepetition[ir]+numberOfElementsToRepeat[ir]+1; + numberOfNestedRepetitions=0; + } else { + numberOfNestedRepetitions--; + } } - i=startRepetition[ir]+numberOfElementsToRepeat[ir]; - numberOfNestedRepetitions--; - } } - } else { - if (ir==0) { - i=startRepetition[ir]+numberOfElementsToRepeat[ir]+1; - numberOfNestedRepetitions=0; - } else { - numberOfNestedRepetitions--; - } - } - } - } + } if (flag!=PROCESS_ENCODE) grib_viarray_push(c,self->elementsDescriptorsIndex,elementsDescriptorsIndex); if (decoding && !self->compressedData) { grib_vdarray_push(c,self->numericValues,dval); @@ -1906,25 +1902,24 @@ static void dump(grib_accessor* a, grib_dumper* dumper) static int value_count(grib_accessor* a,long* count) { - int err=0,l; - long i,subsetNumber=0; - grib_accessor_bufr_data_array *self =(grib_accessor_bufr_data_array*)a; - grib_context* c=a->context; + int err=0,l; + long i; + grib_accessor_bufr_data_array *self =(grib_accessor_bufr_data_array*)a; - err=process_elements(a,PROCESS_DECODE); - if (err) return err; + err=process_elements(a,PROCESS_DECODE); + if (err) return err; - if (self->compressedData) { - l=grib_vdarray_used_size(self->numericValues); + if (self->compressedData) { + l=grib_vdarray_used_size(self->numericValues); - *count=l*self->numberOfSubsets; - } else { - *count=0; - for (i=0;inumberOfSubsets;i++) - *count+=grib_iarray_used_size(self->elementsDescriptorsIndex->v[i]); - } + *count=l*self->numberOfSubsets; + } else { + *count=0; + for (i=0;inumberOfSubsets;i++) + *count+=grib_iarray_used_size(self->elementsDescriptorsIndex->v[i]); + } - return err; + return err; } static int unpack_double(grib_accessor* a, double* val, size_t *len) @@ -1934,7 +1929,6 @@ static int unpack_double(grib_accessor* a, double* val, size_t *len) size_t l=0,elementsInSubset; long numberOfSubsets=0; grib_accessor_bufr_data_array *self =(grib_accessor_bufr_data_array*)a; - grib_context* c=a->context; if (self->unpackMode == CODES_BUFR_NEW_DATA) proc_flag=PROCESS_NEW_DATA; @@ -1947,20 +1941,20 @@ static int unpack_double(grib_accessor* a, double* val, size_t *len) if (err) return err; if (self->compressedData) { - ii=0; - for (k=0;knumericValues->v[i]->n > 1 ? self->numericValues->v[i]->v[k] : self->numericValues->v[i]->v[0]; + ii=0; + for (k=0;knumericValues->v[i]->n > 1 ? self->numericValues->v[i]->v[k] : self->numericValues->v[i]->v[0]; + } } - } } else { - ii=0; - for (k=0;kelementsDescriptorsIndex->v[k]); - for (i=0;inumericValues->v[k]->v[i]; + ii=0; + for (k=0;kelementsDescriptorsIndex->v[k]); + for (i=0;inumericValues->v[k]->v[i]; + } } - } } return GRIB_SUCCESS; diff --git a/src/grib_accessor_class_bufr_data_element.c b/src/grib_accessor_class_bufr_data_element.c index 836a95622..6dd87662e 100644 --- a/src/grib_accessor_class_bufr_data_element.c +++ b/src/grib_accessor_class_bufr_data_element.c @@ -156,8 +156,6 @@ static void init_class(grib_accessor_class* c) static grib_accessor* make_clone(grib_accessor* a,grib_section* s,int* err) { - grib_accessor* operatorAccessor=NULL; - grib_action operatorCreator = {0, }; grib_accessor* the_clone=NULL; grib_accessor* attribute=NULL; grib_accessor_bufr_data_element* elementAccessor; diff --git a/src/grib_accessor_class_concept.c b/src/grib_accessor_class_concept.c index ba7cbdd0c..9336e245a 100644 --- a/src/grib_accessor_class_concept.c +++ b/src/grib_accessor_class_concept.c @@ -323,7 +323,6 @@ int grib_concept_apply(grib_accessor* a, const char* name) grib_values values[1024]; grib_sarray* sa=NULL; grib_concept_value* c=NULL; - grib_accessor_concept* self=(grib_accessor_concept*)a; grib_concept_value* concepts = action_concept_get_concept(a); grib_handle* h=grib_handle_of_accessor(a); grib_action* act=a->creator; diff --git a/src/grib_io.c b/src/grib_io.c index 086d1b3ad..76d218267 100644 --- a/src/grib_io.c +++ b/src/grib_io.c @@ -578,8 +578,6 @@ static int read_BUFR(reader *r) /* unsigned char tmp[65536];*/ /* Should be enough */ size_t length = 0; long edition = 0; - size_t sec1len = 0; - size_t sec2len = 0; int err = 0; int i = 0 ,j; size_t buflen=2048; @@ -1513,5 +1511,4 @@ int grib_count_in_file(grib_context* c, FILE* f,int* n) rewind(f); return err==GRIB_END_OF_FILE ? 0 : err; - } diff --git a/src/grib_loader_from_handle.c b/src/grib_loader_from_handle.c index aed34129c..66bc24591 100644 --- a/src/grib_loader_from_handle.c +++ b/src/grib_loader_from_handle.c @@ -119,11 +119,9 @@ int grib_init_accessor_from_handle(grib_loader* loader,grib_accessor* ga,grib_ar g = h; while(g) { - if(g->values) { - if(copy_values(g,ga) == GRIB_SUCCESS) { - grib_context_log(h->context,GRIB_LOG_DEBUG, "Copying: setting %s to multi-set-value", ga->name); - return GRIB_SUCCESS; - } + if(copy_values(g,ga) == GRIB_SUCCESS) { + grib_context_log(h->context,GRIB_LOG_DEBUG, "Copying: setting %s to multi-set-value", ga->name); + return GRIB_SUCCESS; } g = g->main; } diff --git a/src/grib_parse_utils.c b/src/grib_parse_utils.c index 3f6056b53..6d64f644e 100644 --- a/src/grib_parse_utils.c +++ b/src/grib_parse_utils.c @@ -144,7 +144,6 @@ int grib_recompose_name(grib_handle* h, grib_accessor *observer, const char* una int grib_accessor_print(grib_accessor* a,const char* name,int type,const char* format,const char* separator,int maxcols,int* newline,FILE* out) { size_t size=0; - char val[1024] = {0,}; char* sval=NULL; char* p=NULL; double* dval=0; @@ -256,7 +255,6 @@ int grib_accessor_print(grib_accessor* a,const char* name,int type,const char* f int grib_accessors_list_print(grib_handle* h,grib_accessors_list* al,const char* name,int type,const char* format,const char* separator,int maxcols,int* newline,FILE* out) { size_t size=0,len=0,replen=0; - char val[1024] = {0,}; char* sval=NULL; char* p=NULL; double* dval=0; diff --git a/src/grib_value.c b/src/grib_value.c index bf6029317..cbe83a9b5 100644 --- a/src/grib_value.c +++ b/src/grib_value.c @@ -13,7 +13,8 @@ ***************************************************************************/ #include "grib_api_internal.h" -GRIB_INLINE static int grib_inline_strcmp(const char* a,const char* b) { +GRIB_INLINE static int grib_inline_strcmp(const char* a,const char* b) +{ if (*a != *b) return 1; while((*a!=0 && *b!=0) && *(a) == *(b) ) {a++;b++;} return (*a==0 && *b==0) ? 0 : 1; @@ -21,7 +22,8 @@ GRIB_INLINE static int grib_inline_strcmp(const char* a,const char* b) { #define SWAP(a,b) temp=(a);(a)=(b);(b)=temp; -int grib_set_expression(grib_handle* h, const char* name,grib_expression* e) { +int grib_set_expression(grib_handle* h, const char* name,grib_expression* e) +{ grib_accessor* a = grib_find_accessor(h, name); int ret = GRIB_SUCCESS; @@ -39,7 +41,8 @@ int grib_set_expression(grib_handle* h, const char* name,grib_expression* e) { return GRIB_NOT_FOUND; } -int grib_set_expression_internal(grib_handle* h, const char* name,grib_expression* e) { +int grib_set_expression_internal(grib_handle* h, const char* name,grib_expression* e) +{ grib_accessor* a = grib_find_accessor(h, name); int ret = GRIB_SUCCESS; @@ -53,7 +56,8 @@ int grib_set_expression_internal(grib_handle* h, const char* name,grib_expressio return GRIB_NOT_FOUND; } -int grib_set_long_internal(grib_handle* h, const char* name, long val) { +int grib_set_long_internal(grib_handle* h, const char* name, long val) +{ grib_context* c=h->context; int ret = GRIB_SUCCESS; grib_accessor* a =NULL; @@ -79,7 +83,8 @@ int grib_set_long_internal(grib_handle* h, const char* name, long val) { return GRIB_NOT_FOUND; } -int grib_set_long(grib_handle* h, const char* name, long val) { +int grib_set_long(grib_handle* h, const char* name, long val) +{ int ret = GRIB_SUCCESS; grib_accessor* a =NULL; size_t l = 1; @@ -102,7 +107,8 @@ int grib_set_long(grib_handle* h, const char* name, long val) { return GRIB_NOT_FOUND; } -int grib_set_double_internal(grib_handle* h, const char* name, double val) { +int grib_set_double_internal(grib_handle* h, const char* name, double val) +{ int ret = GRIB_SUCCESS; grib_accessor* a =NULL; size_t l = 1; @@ -134,7 +140,8 @@ struct grib_key_err { grib_key_err* next; }; -int grib_copy_namespace(grib_handle* dest, const char* name, grib_handle* src) { +int grib_copy_namespace(grib_handle* dest, const char* name, grib_handle* src) +{ int *err=0; int type; size_t len; @@ -291,8 +298,8 @@ int grib_copy_namespace(grib_handle* dest, const char* name, grib_handle* src) { return *err; } - -int grib_set_double(grib_handle* h, const char* name, double val) { +int grib_set_double(grib_handle* h, const char* name, double val) +{ int ret = GRIB_SUCCESS; grib_accessor* a =NULL; size_t l = 1; @@ -522,11 +529,13 @@ int grib_set_missing(grib_handle* h, const char* name) return GRIB_NOT_FOUND; } -int grib_is_missing_long(grib_accessor* a,long x) { +int grib_is_missing_long(grib_accessor* a,long x) +{ int ret = ( a==NULL || (a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING)) && (x==GRIB_MISSING_LONG) ? 1 : 0; return ret; } -int grib_is_missing_double(grib_accessor* a,double x) { +int grib_is_missing_double(grib_accessor* a,double x) +{ int ret = ( a==NULL || (a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING)) && (x==GRIB_MISSING_DOUBLE) ? 1 : 0; return ret; } @@ -561,7 +570,8 @@ int grib_is_defined(grib_handle* h, const char* name) return (a ? 1 : 0); } -int grib_set_flag(grib_handle *h,const char* name,unsigned long flag) { +int grib_set_flag(grib_handle *h,const char* name,unsigned long flag) +{ grib_accessor* a=grib_find_accessor(h,name); if (!a) return GRIB_NOT_FOUND; @@ -795,7 +805,8 @@ int grib_get_long_internal(grib_handle* h, const char* name, long* val) return ret; } -int grib_is_in_dump(grib_handle* h, const char* name) { +int grib_is_in_dump(grib_handle* h, const char* name) +{ grib_accessor* a=grib_find_accessor(h, name); if (a!=NULL && (a->flags & GRIB_ACCESSOR_FLAG_DUMP)) return 1; @@ -953,7 +964,6 @@ int grib_get_string_internal(grib_handle* h, const char* name, char* val, size_t int grib_get_string(grib_handle* h, const char* name, char* val, size_t *length) { - size_t len = 1; grib_accessor* a = NULL; grib_accessors_list* al=NULL; int ret=0; @@ -1033,7 +1043,6 @@ int _grib_get_double_array_internal(grib_handle* h,grib_accessor* a,double* val, } return err; - } else { return GRIB_SUCCESS; @@ -1534,7 +1543,8 @@ void grib_print_values(grib_values* values,int count) } } -int grib_values_check(grib_handle* h, grib_values* values, int count) { +int grib_values_check(grib_handle* h, grib_values* values, int count) +{ int i=0; long long_value; double double_value; @@ -1595,7 +1605,8 @@ int grib_values_check(grib_handle* h, grib_values* values, int count) { return 0; } -int grib_key_equal(grib_handle* h1,grib_handle* h2,const char* key,int type,int *err) { +int grib_key_equal(grib_handle* h1,grib_handle* h2,const char* key,int type,int *err) +{ double d1,d2; long l1,l2; char s1[500]={0,}; diff --git a/tools/bufr_dump.c b/tools/bufr_dump.c index e9036467f..84b59dff8 100644 --- a/tools/bufr_dump.c +++ b/tools/bufr_dump.c @@ -145,7 +145,6 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h) { long length=0; char tmp[1024]; - size_t idlen=100; int i,err=0; grib_accessor* a=NULL; grib_accessors_list* al=NULL; diff --git a/tools/grib_tools.c b/tools/grib_tools.c index 1b15ddfa0..6cd0868df 100644 --- a/tools/grib_tools.c +++ b/tools/grib_tools.c @@ -622,14 +622,12 @@ static void grib_print_header(grib_runtime_options* options,grib_handle* h) size_t strlenkey=0; int width; int written_to_dump = 0; /* boolean */ - if (!options->print_keys || options->handle_count!=1) + if (options->handle_count!=1) return; grib_tools_set_print_keys(options,h,options->name_space); - if (options->print_keys - && options->verbose - && options->print_header) { + if (options->verbose && options->print_header) { int j=0; for (j=0;jprint_keys_count;j++) { strlenkey=strlen(options->print_keys[j].name);