From cedda25bf9c4b6b4cffe0062e4720be92529e2c1 Mon Sep 17 00:00:00 2001 From: Enrico Fucile Date: Thu, 26 Feb 2015 18:28:42 +0000 Subject: [PATCH] fixed ECC-73 --- src/grib_accessor.c | 9 ++++ src/grib_accessor_class.c | 13 ++++++ src/grib_accessor_class_bufr_data_array.c | 22 +++++++--- src/grib_api_internal.h | 2 +- src/grib_dumper_class_json.c | 4 +- tests/bufr_filter.sh | 53 +++++++++++++++++++++++ 6 files changed, 95 insertions(+), 8 deletions(-) diff --git a/src/grib_accessor.c b/src/grib_accessor.c index 86ff2a3a0..3921abd85 100644 --- a/src/grib_accessor.c +++ b/src/grib_accessor.c @@ -563,10 +563,15 @@ const char* grib_get_type_name(int type) int grib_accessor_add_attribute(grib_accessor* a,grib_accessor* attr) { int id=0; + int idx=0; if (_grib_accessor_get_attribute(a,attr->name,&id)) return GRIB_ATTRIBUTE_CLASH; for (id=0;idattributes[id] == NULL) { a->attributes[id]=attr; + attr->parent_as_attribute=a; + if (a->same) + attr->same=_grib_accessor_get_attribute(a->same,attr->name,&idx); + return GRIB_SUCCESS; } } @@ -575,9 +580,13 @@ int grib_accessor_add_attribute(grib_accessor* a,grib_accessor* attr) { int grib_accessor_replace_attribute(grib_accessor* a,grib_accessor* attr) { int id=0; + int idx=0; if (_grib_accessor_get_attribute(a,attr->name,&id) != NULL) { grib_accessor_delete(a->parent->h->context,a->attributes[id]); a->attributes[id]=attr; + attr->parent_as_attribute=a; + if (a->same) + attr->same=_grib_accessor_get_attribute(a->same,attr->name,&idx); } else { grib_accessor_add_attribute(a,attr); } diff --git a/src/grib_accessor_class.c b/src/grib_accessor_class.c index d050f2cba..b0275f3dc 100644 --- a/src/grib_accessor_class.c +++ b/src/grib_accessor_class.c @@ -174,6 +174,18 @@ grib_accessor* grib_accessor_factory(grib_section* p, grib_action* creator, return a; } +static void link_same_attributes(grib_accessor* a,grib_accessor* b) { + int i=0; + int idx=0; + grib_accessor* bAttribute=NULL; + if (a==NULL || b==NULL) return; + while (a->attributes[i] && iattributes[i]->name,&idx); + if (bAttribute) a->attributes[i]->same=bAttribute; + i++; + } +} + void grib_push_accessor(grib_accessor* a, grib_block_of_accessors* l) { int id; @@ -192,6 +204,7 @@ void grib_push_accessor(grib_accessor* a, grib_block_of_accessors* l) a->same=a->parent->h->accessors[id]; + link_same_attributes(a,a->same); a->parent->h->accessors[id]=a; if(a->same == a) { diff --git a/src/grib_accessor_class_bufr_data_array.c b/src/grib_accessor_class_bufr_data_array.c index a1d53c605..7ff36b131 100644 --- a/src/grib_accessor_class_bufr_data_array.c +++ b/src/grib_accessor_class_bufr_data_array.c @@ -631,7 +631,7 @@ static void set_creator_name(grib_action* creator,int code) { } } -static grib_accessor* create_accessor_from_descriptor(grib_accessor* a,grib_section* section,long ide,long subset,int dump) { +static grib_accessor* create_accessor_from_descriptor(grib_accessor* a,grib_section* section,long ide,long subset,int dump,int count) { grib_accessor_bufr_data_array *self =(grib_accessor_bufr_data_array*)a; char code[7]={0,}; int idx=0; @@ -660,6 +660,7 @@ static grib_accessor* create_accessor_from_descriptor(grib_accessor* a,grib_sect switch (self->expanded->v[idx]->F) { case 0: + case 1: creator.name=self->expanded->v[idx]->shortName; elementAccessor = grib_accessor_factory(section, &creator, 0, NULL); if (self->canBeMissing[idx]) elementAccessor->flags |= GRIB_ACCESSOR_FLAG_CAN_BE_MISSING; @@ -673,6 +674,8 @@ static grib_accessor* create_accessor_from_descriptor(grib_accessor* a,grib_sect accessor_bufr_data_element_set_subsetNumber(elementAccessor,subset); self->expanded->v[idx]->a=elementAccessor; + attribute=create_attribute("number",section,GRIB_TYPE_LONG,0,0,count); + grib_accessor_add_attribute(elementAccessor,attribute); sprintf(code,"%06ld",self->expanded->v[idx]->code); attribute=create_attribute("code",section,GRIB_TYPE_STRING,code,0,0); @@ -704,9 +707,15 @@ static grib_accessor* create_accessor_from_descriptor(grib_accessor* a,grib_sect accessor_bufr_data_element_set_numberOfSubsets(elementAccessor,self->numberOfSubsets); accessor_bufr_data_element_set_subsetNumber(elementAccessor,subset); + attribute=create_attribute("number",section,GRIB_TYPE_LONG,0,0,count); + grib_accessor_add_attribute(elementAccessor,attribute); + } else { elementAccessor = grib_accessor_factory(section, &operatorCreator, 0, NULL); accessor_variable_set_type(elementAccessor,GRIB_TYPE_LONG); + attribute=create_attribute("number",section,GRIB_TYPE_LONG,0,0,count); + grib_accessor_add_attribute(elementAccessor,attribute); + sprintf(code,"%06ld",self->expanded->v[idx]->code); attribute=create_attribute("code",section,GRIB_TYPE_STRING,code,0,0); grib_accessor_add_attribute(elementAccessor,attribute); @@ -795,7 +804,7 @@ static int create_keys(grib_accessor* a) { int incrementBitmapIndex=1; grib_accessor* elementFromBitmap=NULL; int reuseBitmap=0; - int i,dump=1;; + int i,dump=1,count=0; creatorGroup.op = "bufr_group"; creatorGroup.name="groupNumber"; @@ -871,6 +880,8 @@ static int create_keys(grib_accessor* a) { 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]; @@ -897,16 +908,16 @@ static int create_keys(grib_accessor* a) { dump=1; bitmapSize[bitmapIndex]++; bitmap.cursor=0; - } else if (descriptor->code == 222000 || descriptor->code == 224000) { + } 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; - extraElement=1; bitmap.cursor=0; reuseBitmap=1; + extraElement=1; dump=1; } else if (descriptor->code == 236000 || descriptor->code == 237000 ) { bitmap.referredElement=NULL; @@ -930,7 +941,8 @@ static int create_keys(grib_accessor* a) { dump=1; } - elementAccessor=create_accessor_from_descriptor(a,section,ide,iss,dump); + count++; + elementAccessor=create_accessor_from_descriptor(a,section,ide,iss,dump,count); if (elementFromBitmap && self->unpackMode==CODES_BUFR_UNPACK_STRUCTURE) { grib_accessor_add_attribute(elementFromBitmap,elementAccessor); } else if (elementAccessor) { diff --git a/src/grib_api_internal.h b/src/grib_api_internal.h index d850c4060..4dd480d00 100644 --- a/src/grib_api_internal.h +++ b/src/grib_api_internal.h @@ -507,7 +507,7 @@ struct grib_accessor grib_virtual_value* vvalue; /** < virtual value used when transient flag on **/ const char* set; grib_accessor *attributes[MAX_ACCESSOR_ATTRIBUTES]; /** < attributes are accessors */ - + grib_accessor* parent_as_attribute; }; #define GRIB_ACCESSOR_FLAG_READ_ONLY (1<<1) diff --git a/src/grib_dumper_class_json.c b/src/grib_dumper_class_json.c index 8f92eefe5..82ab2a94e 100644 --- a/src/grib_dumper_class_json.c +++ b/src/grib_dumper_class_json.c @@ -512,7 +512,7 @@ static void dump_attributes(grib_dumper* d,grib_accessor* a) { int i=0; grib_dumper_json *self = (grib_dumper_json*)d; FILE* out=self->dumper.out; - while (a->attributes[i] || i > MAX_ACCESSOR_ATTRIBUTES) { + while (a->attributes[i] && i < MAX_ACCESSOR_ATTRIBUTES) { self->isAttribute=1; self->isLeaf=a->attributes[i]->attributes[0]==NULL ? 1 : 0; fprintf(self->dumper.out,"\n%-*s",depth," "); @@ -529,7 +529,7 @@ static void dump_attributes(grib_dumper* d,grib_accessor* a) { break; } i++; - if (a->attributes[i] || i > MAX_ACCESSOR_ATTRIBUTES) + if (a->attributes[i] && i < MAX_ACCESSOR_ATTRIBUTES) fprintf(self->dumper.out,","); } self->isLeaf=0; diff --git a/tests/bufr_filter.sh b/tests/bufr_filter.sh index 13f0c0b8a..d0c8d980b 100755 --- a/tests/bufr_filter.sh +++ b/tests/bufr_filter.sh @@ -266,6 +266,59 @@ diff ${f}.ref ${f}.log rm -f ${f}.ref ${f}.log +#----------------------------------------------------------- +# Test: access marker operators 2 +#----------------------------------------------------------- +cat > $fRules <percentConfidence=[pressure->percentConfidence]"; +print "pressure->width=[pressure->width]"; +EOF + +f="temp_101.bufr" +echo "Test: access marker operators 2" >> $fLog +echo "file: $f" >> $fLog +${tools_dir}/bufr_filter $fRules $f 2>> $fLog 1>> $fLog + +${tools_dir}/bufr_filter $fRules $f 2>> ${f}.log 1>> ${f}.log +cat > ${f}.ref <percentConfidence=70 75 82 75 75 82 75 75 +75 75 82 75 75 75 75 75 +75 82 75 75 75 75 82 75 +82 75 75 75 82 75 82 79 +75 75 75 82 75 75 75 75 +75 82 75 75 75 75 75 75 +75 82 75 75 82 75 75 75 +75 82 75 75 75 75 82 75 +75 75 75 75 82 75 75 75 +75 75 75 70 +pressure->width=14 14 14 14 14 14 14 14 +14 14 14 14 14 14 14 14 +14 14 14 14 14 14 14 14 +14 14 14 14 14 14 14 14 +14 14 14 14 14 14 14 14 +14 14 14 14 14 14 14 14 +14 14 14 14 14 14 14 14 +14 14 14 14 14 14 14 14 +14 14 14 14 14 14 14 14 +14 14 14 14 +EOF + +diff ${f}.ref ${f}.log + +rm -f ${f}.ref ${f}.log + #----------------------------------------------------------- # Test: with nonexistent keys. #-----------------------------------------------------------