fixed ECC-73

This commit is contained in:
Enrico Fucile 2015-02-26 18:28:42 +00:00
parent d2219ebf55
commit cedda25bf9
6 changed files with 95 additions and 8 deletions

View File

@ -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;id<MAX_ACCESSOR_ATTRIBUTES;id++) {
if (a->attributes[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);
}

View File

@ -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] && i<MAX_ACCESSOR_ATTRIBUTES) {
bAttribute=_grib_accessor_get_attribute(b,a->attributes[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) {

View File

@ -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) {

View File

@ -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)

View File

@ -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;

View File

@ -266,6 +266,59 @@ diff ${f}.ref ${f}.log
rm -f ${f}.ref ${f}.log
#-----------------------------------------------------------
# Test: access marker operators 2
#-----------------------------------------------------------
cat > $fRules <<EOF
set unpack=1;
print "pressure=[pressure]";
print "pressure->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 <<EOF
pressure=102000 101800 100000 98500 96400 92500 92100 89700
88100 86100 85000 84400 79400 79000 78300 77300
71900 70000 69400 65100 61200 53400 50000 43900
40000 39900 37800 31600 30000 27500 25000 21200
21000 20600 20400 20000 19300 18400 17000 16600
15100 15000 14600 14000 13400 13200 12900 11100
10800 10000 8960 7630 7000 6420 6190 5770
5320 5000 3970 3570 3190 3090 3000 2820
2630 2400 2340 2050 2000 1680 1530 1500
1380 1300 1210 31600
pressure->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.
#-----------------------------------------------------------