ECC-160 ECC-162

This commit is contained in:
Enrico Fucile 2015-10-14 10:22:00 +01:00
parent 7a888cfd0d
commit 5b30fa1283
8 changed files with 98 additions and 32 deletions

View File

@ -499,7 +499,10 @@ void grib_accessor_delete(grib_context *ct, grib_accessor* a)
while(c)
{
grib_accessor_class *s = c->super ? *(c->super) : NULL;
if(c->destroy) c->destroy(ct,a);
grib_context_log(ct,GRIB_LOG_DEBUG,"destroy %s ==> %s",c->name,a->name);
if(c->destroy) {
c->destroy(ct,a);
}
c = s;
}
grib_context_free(ct,a);
@ -637,6 +640,14 @@ const char* grib_get_type_name(int type)
return "unknown";
}
int grib_accessor_clear_attributes(grib_accessor* a) {
int id;
for (id=0;id<MAX_ACCESSOR_ATTRIBUTES;id++) {
a->attributes[id]=NULL;
}
return 0;
}
int grib_accessor_add_attribute(grib_accessor* a,grib_accessor* attr) {
int id=0;
int idx=0;
@ -648,6 +659,7 @@ int grib_accessor_add_attribute(grib_accessor* a,grib_accessor* attr) {
if (a->same)
attr->same=_grib_accessor_get_attribute(a->same,attr->name,&idx);
grib_context_log(a->parent->h->context,GRIB_LOG_DEBUG,"added attribute %s->%s",a->name,attr->name);
return GRIB_SUCCESS;
}
}

View File

@ -777,6 +777,7 @@ static int decode_replication(grib_context* c,grib_accessor_bufr_data_array* sel
if (err) return err;
*numberOfRepetitions=grib_decode_unsigned_long(data,pos,descriptors[i]->width)+
descriptors[i]->reference*descriptors[i]->factor;
grib_context_log(c, GRIB_LOG_DEBUG,"BUFR data decoding: \tdelayed replication value=%ld",*numberOfRepetitions);
}
if (self->compressedData) {
dval=grib_darray_new(c,1,100);
@ -1110,22 +1111,25 @@ static void set_creator_name(grib_action* creator,int code)
case 243255:
creator->name="cancelCategoricalForecastValuesFollow";
break;
case 999999:
creator->name="associatedField";
break;
default :
creator->name="operator";
break;
}
}
static grib_accessor* create_accessor_from_descriptor(grib_accessor* a,grib_section* section,long ide,long subset,int dump,int count)
static grib_accessor* create_accessor_from_descriptor(grib_accessor* a,grib_accessor* attribute,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[10]={0,};
int idx=0;
int i;
unsigned long flags=0;
grib_accessor* operatorAccessor=NULL;
grib_action operatorCreator = {0, };
grib_accessor* elementAccessor=NULL;
grib_accessor* attribute=NULL;
grib_action creator = {0, };
creator.op = "bufr_data_element";
creator.name_space = "";
@ -1148,7 +1152,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;
creator.name=grib_context_strdup(a->parent->h->context,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;
accessor_bufr_data_element_set_index(elementAccessor,ide);
@ -1162,6 +1166,15 @@ 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;
if (attribute) {
attribute->parent=elementAccessor->parent;
for (i=0;i<MAX_ACCESSOR_ATTRIBUTES;i++) {
if (attribute->attributes[i]) attribute->attributes[i]->parent=elementAccessor->parent;
}
grib_accessor_add_attribute(elementAccessor,attribute);
}
attribute=create_attribute("index",section,GRIB_TYPE_LONG,0,0,count,flags);
grib_accessor_add_attribute(elementAccessor,attribute);
@ -1202,6 +1215,7 @@ static grib_accessor* create_accessor_from_descriptor(grib_accessor* a,grib_sect
} else {
elementAccessor = grib_accessor_factory(section, &operatorCreator, 0, NULL);
accessor_variable_set_type(elementAccessor,GRIB_TYPE_LONG);
attribute=create_attribute("index",section,GRIB_TYPE_LONG,0,0,count,flags);
grib_accessor_add_attribute(elementAccessor,attribute);
@ -1211,6 +1225,38 @@ static grib_accessor* create_accessor_from_descriptor(grib_accessor* a,grib_sect
}
self->expanded->v[idx]->a=elementAccessor;
break;
case 9:
set_creator_name(&creator,self->expanded->v[idx]->code);
elementAccessor = grib_accessor_factory(section, &creator, 0, NULL);
accessor_bufr_data_element_set_index(elementAccessor,ide);
accessor_bufr_data_element_set_descriptors(elementAccessor,self->expanded);
accessor_bufr_data_element_set_elementsDescriptorsIndex(elementAccessor,self->elementsDescriptorsIndex);
accessor_bufr_data_element_set_numericValues(elementAccessor,self->numericValues);
accessor_bufr_data_element_set_stringValues(elementAccessor,self->stringValues);
accessor_bufr_data_element_set_compressedData(elementAccessor,self->compressedData);
accessor_bufr_data_element_set_type(elementAccessor,self->expanded->v[idx]->type);
accessor_bufr_data_element_set_numberOfSubsets(elementAccessor,self->numberOfSubsets);
accessor_bufr_data_element_set_subsetNumber(elementAccessor,subset);
attribute=create_attribute("index",section,GRIB_TYPE_LONG,0,0,count,flags);
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,flags);
grib_accessor_add_attribute(elementAccessor,attribute);
attribute=create_attribute("units",section,GRIB_TYPE_STRING,self->expanded->v[idx]->units,0,0,GRIB_ACCESSOR_FLAG_DUMP);
grib_accessor_add_attribute(elementAccessor,attribute);
attribute=create_attribute("scale",section,GRIB_TYPE_LONG,0,0,self->expanded->v[idx]->scale,flags);
grib_accessor_add_attribute(elementAccessor,attribute);
attribute=create_attribute("reference",section,GRIB_TYPE_DOUBLE,0,self->expanded->v[idx]->reference,0,flags);
grib_accessor_add_attribute(elementAccessor,attribute);
attribute=create_attribute("width",section,GRIB_TYPE_LONG,0,0,self->expanded->v[idx]->width,flags);
grib_accessor_add_attribute(elementAccessor,attribute);
break;
}
return elementAccessor;
@ -1280,6 +1326,7 @@ static int create_keys(grib_accessor* a)
grib_accessor_bufr_data_array *self =(grib_accessor_bufr_data_array*)a;
int err=0;
grib_accessor* elementAccessor=0;
grib_accessor* associatedFieldAccessor=0;
long iss,end,elementsInSubset,ide;
grib_section* section=NULL;
grib_section* rootSection=NULL;
@ -1345,6 +1392,7 @@ static int create_keys(grib_accessor* a)
forceGroupClosure=0;
elementsInSubset= self->compressedData ? grib_iarray_used_size(self->elementsDescriptorsIndex->v[0]) :
grib_iarray_used_size(self->elementsDescriptorsIndex->v[iss]);
associatedFieldAccessor=NULL;
for (ide=0;ide<elementsInSubset;ide++) {
idx = self->compressedData ? self->elementsDescriptorsIndex->v[0]->v[ide] :
self->elementsDescriptorsIndex->v[iss]->v[ide] ;
@ -1456,12 +1504,18 @@ static int create_keys(grib_accessor* a)
}
count++;
elementAccessor=create_accessor_from_descriptor(a,section,ide,iss,dump,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) {
grib_push_accessor(elementAccessor,section->block);
grib_accessors_list_push(self->dataAccessors,elementAccessor);
if (descriptor->code == 999999) {
associatedFieldAccessor=elementAccessor;
} else {
grib_push_accessor(elementAccessor,section->block);
grib_accessors_list_push(self->dataAccessors,elementAccessor);
}
}
}
}

View File

@ -23,7 +23,7 @@
IMPLEMENTS = init;dump
IMPLEMENTS = unpack_string;unpack_string_array;unpack_long; unpack_double
IMPLEMENTS = pack_long; pack_double ; pack_string_array; pack_string
IMPLEMENTS = value_count; destroy; get_native_type;
IMPLEMENTS = value_count; get_native_type;
MEMBERS = long index
MEMBERS = int type
MEMBERS = long compressedData
@ -58,7 +58,6 @@ static int unpack_long(grib_accessor*, long* val,size_t *len);
static int unpack_string (grib_accessor*, char*, size_t *len);
static int unpack_string_array (grib_accessor*, char**, size_t *len);
static int value_count(grib_accessor*,long*);
static void destroy(grib_context*,grib_accessor*);
static void dump(grib_accessor*, grib_dumper*);
static void init(grib_accessor*,const long, grib_arguments* );
static void init_class(grib_accessor_class*);
@ -88,7 +87,7 @@ static grib_accessor_class _grib_accessor_class_bufr_data_element = {
&init_class, /* init_class */
&init, /* init */
0, /* post_init */
&destroy, /* free mem */
0, /* free mem */
&dump, /* describes himself */
0, /* get length of section */
0, /* get length of string */
@ -473,10 +472,6 @@ static int value_count(grib_accessor* a,long* count)
return ret;
}
static void destroy(grib_context* context,grib_accessor* a)
{
}
static int get_native_type(grib_accessor* a){
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
int ret=GRIB_TYPE_DOUBLE;

View File

@ -338,6 +338,20 @@ static size_t __expand(grib_accessor* a,bufr_descriptors_array* unexpanded,bufr_
case 0:
u=grib_bufr_descriptors_array_pop_front(unexpanded);
size=1;
if (ccp->associatedFieldWidth && u->X!=31) {
bufr_descriptor* au=grib_bufr_descriptor_new(self->tablesAccessor,999999,err);
au->width=ccp->associatedFieldWidth;
au->shortName=grib_context_strdup(c,"associatedField");
au->name=grib_context_strdup(c,"associated field");
au->units=grib_context_strdup(c,"associated units");
#if MYDEBUG
for (idepth=0;idepth<depth;idepth++) printf("\t");
printf("+++ push %06ld (%ld %g %ld)",au->code,au->scale,au->reference,au->width);
#endif
grib_bufr_descriptors_array_push(expanded,au);
size++;
}
#if MYDEBUG
for (idepth=0;idepth<depth;idepth++) printf("\t");
printf("+++ pop %06ld\n",u->code);
@ -365,19 +379,6 @@ static size_t __expand(grib_accessor* a,bufr_descriptors_array* unexpanded,bufr_
printf("->(%ld %g %ld)\n",u->scale,u->reference,u->width);
#endif
grib_bufr_descriptors_array_push(expanded,u);
size=1;
if (ccp->associatedFieldWidth) {
bufr_descriptor* au=grib_bufr_descriptor_new(self->tablesAccessor,999999,err);
au->width=ccp->associatedFieldWidth;
#if MYDEBUG
for (idepth=0;idepth<depth;idepth++) printf("\t");
printf("+++ push %06ld (%ld %g %ld)",au->code,au->scale,au->reference,au->width);
#endif
grib_bufr_descriptors_array_push(expanded,au);
size++;
/* bufrdc bug!!*/
ccp->associatedFieldWidth=0;
}
break;
case 2:

View File

@ -489,8 +489,11 @@ static void destroy(grib_context* ct, grib_accessor* a)
grib_context_free(ct,a->vvalue);
a->vvalue=NULL;
}
while (a->attributes[i]) {
grib_context_log(a->parent->h->context,GRIB_LOG_DEBUG,"address=%p",a);
while (i<MAX_ACCESSOR_ATTRIBUTES && a->attributes[i]) {
grib_context_log(a->parent->h->context,GRIB_LOG_DEBUG,"deleting attribute %s->%s",a->name,a->attributes[i]->name);
grib_accessor_delete(a->parent->h->context,a->attributes[i]);
a->attributes[i]=NULL;
i++;
}
}

View File

@ -93,7 +93,7 @@ int grib_recompose_name(grib_handle* h, grib_accessor *observer, const char* una
case GRIB_TYPE_DOUBLE:
replen=1;
ret = grib_unpack_double(a,&dval,&replen);
sprintf(val,"%g",dval);
sprintf(val,"%.12g",dval);
break;
case GRIB_TYPE_LONG:
replen=1;
@ -154,7 +154,7 @@ int grib_accessor_print(grib_accessor* a,const char* name,int type,const char* f
int ret=0;
char* myformat=NULL;
char* myseparator=NULL;
char double_format[]="%g"; /* default format for printing double keys */
char double_format[]="%.12g"; /* default format for printing double keys */
char long_format[]="%ld"; /* default format for printing integer keys */
char default_separator[]=" ";
grib_handle* h=a->parent->h;
@ -266,7 +266,7 @@ int grib_accessors_list_print(grib_accessors_list* al,const char* name,int type,
int ret=0;
char* myformat=NULL;
char* myseparator=NULL;
char double_format[]="%g"; /* default format for printing double keys */
char double_format[]="%.12g"; /* default format for printing double keys */
char long_format[]="%ld"; /* default format for printing integer keys */
char default_separator[]=" ";
grib_handle* h=al->accessor->parent->h;

View File

@ -31,7 +31,7 @@ cat > w.filter <<EOF
EOF
cat > r.filter <<EOF
print "[values]";
print "[values%g]";
EOF
${tools_dir}grib_filter -o $outsimple w.filter $infile

View File

@ -178,6 +178,7 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
}
a=grib_find_accessor(h,"numericValues");
al=accessor_bufr_data_array_get_dataAccessors(a);
options->dump_flags=GRIB_DUMP_FLAG_ALL_ATTRIBUTES;
grib_dump_bufr_flat(al,h,stdout,options->dump_mode,options->dump_flags,0);
break;
case 's':