mirror of https://github.com/ecmwf/eccodes.git
added bufr_dump option -ja to print all the attributes. Default is now that only value and units will be printed. ECC-103
This commit is contained in:
parent
45fd92b0e4
commit
379bedaa1a
|
@ -70,6 +70,7 @@ Log mode for information for processing information
|
|||
#define CODES_DUMP_FLAG_HEXADECIMAL GRIB_DUMP_FLAG_HEXADECIMAL
|
||||
#define CODES_DUMP_FLAG_NO_DATA GRIB_DUMP_FLAG_NO_DATA
|
||||
#define CODES_DUMP_FLAG_ALL_DATA GRIB_DUMP_FLAG_ALL_DATA
|
||||
#define CODES_DUMP_FLAG_ALL_ATTRIBUTES GRIB_DUMP_FLAG_ALL_ATTRIBUTES
|
||||
|
||||
/* codes_nearest flags */
|
||||
#define CODES_NEAREST_SAME_GRID GRIB_NEAREST_SAME_GRID
|
||||
|
|
|
@ -594,13 +594,13 @@ static void push_zero_element(grib_accessor_bufr_data_array* self,grib_darray* d
|
|||
}
|
||||
}
|
||||
|
||||
static grib_accessor* create_attribute(char* name,grib_section* section,int type,char* sval,double dval,long lval) {
|
||||
static grib_accessor* create_attribute(char* name,grib_section* section,int type,char* sval,double dval,long lval,unsigned long flags) {
|
||||
grib_accessor* a=NULL;
|
||||
grib_action creator = {0, };
|
||||
size_t len;
|
||||
creator.op = "variable";
|
||||
creator.name_space = "";
|
||||
creator.flags = GRIB_ACCESSOR_FLAG_READ_ONLY | GRIB_ACCESSOR_FLAG_DUMP ;
|
||||
creator.flags = GRIB_ACCESSOR_FLAG_READ_ONLY | flags ;
|
||||
creator.set = 0;
|
||||
|
||||
creator.name=name;
|
||||
|
@ -692,6 +692,7 @@ static grib_accessor* create_accessor_from_descriptor(grib_accessor* a,grib_sect
|
|||
grib_accessor_bufr_data_array *self =(grib_accessor_bufr_data_array*)a;
|
||||
char code[10]={0,};
|
||||
int idx=0;
|
||||
unsigned long flags=0;
|
||||
grib_accessor* operatorAccessor=NULL;
|
||||
grib_action operatorCreator = {0, };
|
||||
grib_accessor* elementAccessor=NULL;
|
||||
|
@ -731,23 +732,23 @@ 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("index",section,GRIB_TYPE_LONG,0,0,count);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
attribute=create_attribute("width",section,GRIB_TYPE_LONG,0,0,self->expanded->v[idx]->width,flags);
|
||||
grib_accessor_add_attribute(elementAccessor,attribute);
|
||||
break;
|
||||
case 2:
|
||||
|
@ -764,17 +765,17 @@ 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("index",section,GRIB_TYPE_LONG,0,0,count);
|
||||
attribute=create_attribute("index",section,GRIB_TYPE_LONG,0,0,count,flags);
|
||||
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("index",section,GRIB_TYPE_LONG,0,0,count);
|
||||
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);
|
||||
attribute=create_attribute("code",section,GRIB_TYPE_STRING,code,0,0,flags);
|
||||
grib_accessor_add_attribute(elementAccessor,attribute);
|
||||
}
|
||||
self->expanded->v[idx]->a=elementAccessor;
|
||||
|
@ -830,6 +831,12 @@ static grib_accessor* get_element_from_bitmap(grib_accessor* a,bitmap_s* bitmap)
|
|||
return bitmap->referredElement->prev->accessor;
|
||||
}
|
||||
|
||||
static GRIB_INLINE void reset_qualifiers(grib_accessor* significanceQualifierGroup[]) {
|
||||
int i;
|
||||
for (i=0;i<number_of_qualifiers;i++)
|
||||
significanceQualifierGroup[i]=0;
|
||||
}
|
||||
|
||||
static int create_keys(grib_accessor* a) {
|
||||
grib_accessor_bufr_data_array *self =(grib_accessor_bufr_data_array*)a;
|
||||
int err=0;
|
||||
|
@ -863,6 +870,7 @@ static int create_keys(grib_accessor* a) {
|
|||
grib_accessor* elementFromBitmap=NULL;
|
||||
int reuseBitmap=0;
|
||||
int i,dump=1,count=0;
|
||||
int forceGroupClosure=0;
|
||||
|
||||
creatorGroup.op = "bufr_group";
|
||||
creatorGroup.name="groupNumber";
|
||||
|
@ -893,10 +901,10 @@ static int create_keys(grib_accessor* a) {
|
|||
|
||||
for (iss=0;iss<end;iss++) {
|
||||
qualityPresent=0;
|
||||
forceGroupClosure=0;
|
||||
elementsInSubset= self->compressedData ? grib_iarray_used_size(self->elementsDescriptorsIndex->v[0]) :
|
||||
grib_iarray_used_size(self->elementsDescriptorsIndex->v[iss]);
|
||||
for (ide=0;ide<elementsInSubset;ide++) {
|
||||
/* printf("++++++++++++++%ld\n",ide); */
|
||||
idx = self->compressedData ? self->elementsDescriptorsIndex->v[0]->v[ide] :
|
||||
self->elementsDescriptorsIndex->v[iss]->v[ide] ;
|
||||
|
||||
|
@ -912,12 +920,17 @@ static int create_keys(grib_accessor* a) {
|
|||
depth=significanceQualifierDepth[sidx];
|
||||
reset_deeper_qualifiers(significanceQualifierGroup,significanceQualifierDepth,depth);
|
||||
} else {
|
||||
groupSection=section;
|
||||
depth++;
|
||||
/* if (forceGroupClosure) { */
|
||||
/* groupSection=sectionUp; */
|
||||
/* forceGroupClosure=0; */
|
||||
/* depth=0; */
|
||||
/* } else { */
|
||||
groupSection=section;
|
||||
depth++;
|
||||
/* } */
|
||||
}
|
||||
|
||||
gaGroup = grib_accessor_factory(groupSection, &creatorGroup, 0, NULL);
|
||||
/* a->parent->h->groups[groupNumber]=gaGroup; */
|
||||
gaGroup->sub_section=grib_section_create(a->parent->h,gaGroup);
|
||||
gaGroup->bufr_group_number=groupNumber;
|
||||
accessor_constant_set_type(gaGroup,GRIB_TYPE_LONG);
|
||||
|
@ -950,7 +963,6 @@ static int create_keys(grib_accessor* a) {
|
|||
depth++;
|
||||
}
|
||||
gaGroup = grib_accessor_factory(groupSection, &creatorGroup, 0, NULL);
|
||||
/* a->parent->h->groups[groupNumber]=gaGroup; */
|
||||
gaGroup->sub_section=grib_section_create(a->parent->h,gaGroup);
|
||||
gaGroup->bufr_group_number=groupNumber;
|
||||
accessor_constant_set_type(gaGroup,GRIB_TYPE_LONG);
|
||||
|
@ -997,11 +1009,13 @@ static int create_keys(grib_accessor* a) {
|
|||
}
|
||||
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); */
|
||||
}
|
||||
|
||||
count++;
|
||||
elementAccessor=create_accessor_from_descriptor(a,section,ide,iss,dump,count);
|
||||
/* printf("++++++count=%d\n",count); */
|
||||
if (elementFromBitmap && self->unpackMode==CODES_BUFR_UNPACK_STRUCTURE) {
|
||||
grib_accessor_add_attribute(elementFromBitmap,elementAccessor);
|
||||
} else if (elementAccessor) {
|
||||
|
|
|
@ -102,6 +102,7 @@ Log mode for information for processing information
|
|||
#define GRIB_DUMP_FLAG_HEXADECIMAL (1<<7)
|
||||
#define GRIB_DUMP_FLAG_NO_DATA (1<<8)
|
||||
#define GRIB_DUMP_FLAG_ALL_DATA (1<<9)
|
||||
#define GRIB_DUMP_FLAG_ALL_ATTRIBUTES (1<<10)
|
||||
|
||||
/* grib_nearest flags */
|
||||
#define GRIB_NEAREST_SAME_GRID (1<<0)
|
||||
|
|
|
@ -180,7 +180,7 @@ static void dump_values(grib_dumper* d,grib_accessor* a)
|
|||
|
||||
depth-=2;
|
||||
fprintf(self->dumper.out,"\n%-*s]",depth," ");
|
||||
if (a->attributes[0]) fprintf(self->dumper.out,",");
|
||||
/* if (a->attributes[0]) fprintf(self->dumper.out,","); */
|
||||
grib_context_free(a->parent->h->context,values);
|
||||
} else {
|
||||
if (self->isLeaf==0) {
|
||||
|
@ -191,7 +191,6 @@ static void dump_values(grib_dumper* d,grib_accessor* a)
|
|||
fprintf(self->dumper.out,"null");
|
||||
else
|
||||
fprintf(self->dumper.out,"%g",value);
|
||||
if (a->attributes[0]) fprintf(self->dumper.out,",");
|
||||
}
|
||||
|
||||
if (self->isLeaf==0) {
|
||||
|
@ -259,7 +258,7 @@ static void dump_long(grib_dumper* d,grib_accessor* a,const char* comment)
|
|||
|
||||
depth-=2;
|
||||
fprintf(self->dumper.out,"\n%-*s]",depth," ");
|
||||
if (a->attributes[0]) fprintf(self->dumper.out,",");
|
||||
/* if (a->attributes[0]) fprintf(self->dumper.out,","); */
|
||||
grib_context_free(a->parent->h->context,values);
|
||||
} else {
|
||||
if (self->isLeaf==0) {
|
||||
|
@ -270,7 +269,7 @@ static void dump_long(grib_dumper* d,grib_accessor* a,const char* comment)
|
|||
fprintf(self->dumper.out,"null");
|
||||
else
|
||||
fprintf(self->dumper.out,"%ld",value);
|
||||
if (a->attributes[0]) fprintf(self->dumper.out,",");
|
||||
/* if (a->attributes[0]) fprintf(self->dumper.out,","); */
|
||||
}
|
||||
|
||||
if (self->isLeaf==0) {
|
||||
|
@ -314,7 +313,7 @@ static void dump_double(grib_dumper* d,grib_accessor* a,const char* comment)
|
|||
else
|
||||
fprintf(self->dumper.out,"%g",value);
|
||||
|
||||
if (a->attributes[0]) fprintf(self->dumper.out,",");
|
||||
/* if (a->attributes[0]) fprintf(self->dumper.out,","); */
|
||||
|
||||
if (self->isLeaf==0) {
|
||||
dump_attributes(d,a);
|
||||
|
@ -378,7 +377,7 @@ static void dump_string_array(grib_dumper* d,grib_accessor* a,const char* commen
|
|||
depth-=2;
|
||||
fprintf(self->dumper.out,"\n%-*s]",depth," ");
|
||||
|
||||
if (a->attributes[0]) fprintf(self->dumper.out,",");
|
||||
/* if (a->attributes[0]) fprintf(self->dumper.out,","); */
|
||||
|
||||
if (self->isLeaf==0) {
|
||||
dump_attributes(d,a);
|
||||
|
@ -430,7 +429,7 @@ static void dump_string(grib_dumper* d,grib_accessor* a,const char* comment)
|
|||
}
|
||||
fprintf(self->dumper.out,"\"%s\"",value);
|
||||
|
||||
if (a->attributes[0]) fprintf(self->dumper.out,",");
|
||||
/* if (a->attributes[0]) fprintf(self->dumper.out,","); */
|
||||
|
||||
if (self->isLeaf==0) {
|
||||
dump_attributes(d,a);
|
||||
|
@ -494,7 +493,14 @@ static void dump_attributes(grib_dumper* d,grib_accessor* a) {
|
|||
FILE* out=self->dumper.out;
|
||||
while (a->attributes[i] && i < MAX_ACCESSOR_ATTRIBUTES) {
|
||||
self->isAttribute=1;
|
||||
if ( (d->option_flags & GRIB_DUMP_FLAG_ALL_ATTRIBUTES ) == 0
|
||||
&& (a->attributes[i]->flags & GRIB_ACCESSOR_FLAG_DUMP)==0)
|
||||
{
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
self->isLeaf=a->attributes[i]->attributes[0]==NULL ? 1 : 0;
|
||||
fprintf(self->dumper.out,",");
|
||||
fprintf(self->dumper.out,"\n%-*s",depth," ");
|
||||
fprintf(out,"\"%s\" : ",a->attributes[i]->name);
|
||||
switch (grib_accessor_get_native_type(a->attributes[i])) {
|
||||
|
@ -509,8 +515,6 @@ static void dump_attributes(grib_dumper* d,grib_accessor* a) {
|
|||
break;
|
||||
}
|
||||
i++;
|
||||
if (a->attributes[i] && i < MAX_ACCESSOR_ATTRIBUTES)
|
||||
fprintf(self->dumper.out,",");
|
||||
}
|
||||
self->isLeaf=0;
|
||||
self->isAttribute=0;
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
|
||||
grib_option grib_options[]={
|
||||
/* {id, args, help}, on, command_line, value*/
|
||||
{"j:","s/f","\n\t\tJSON mode (JavaScript Object Notation)."
|
||||
"\n\t\tOptions: s->structure, f->flat (only data)\n",1,1,"s"},
|
||||
{"j:","s/f/a","\n\t\tJSON mode (JavaScript Object Notation)."
|
||||
"\n\t\tOptions: s->structure, f->flat (only data), a->all attributes\n",1,1,"s"},
|
||||
{"S",0,0,1,0,0},
|
||||
{"O",0,"Octet mode. WMO documentation style dump.\n",0,1,0},
|
||||
{"D",0,0,0,1,0},
|
||||
|
@ -26,6 +26,7 @@ grib_option grib_options[]={
|
|||
{"u",0,"Print only some values.\n",0,1,0},
|
||||
/* {"C",0,0,0,1,0}, */
|
||||
{"t",0,0,0,1,0},
|
||||
{"f",0,0,0,1,0},
|
||||
{"H",0,0,0,1,0},
|
||||
{"a",0,0,0,1,0},
|
||||
{"w:",0,0,0,1,0},
|
||||
|
@ -75,7 +76,7 @@ int grib_tool_init(grib_runtime_options* options)
|
|||
if (grib_options_on("j:")) {
|
||||
options->dump_mode = "json";
|
||||
json_option=grib_options_get_option("j:");
|
||||
if (strlen(json_option)>1 || ( json_option[0] != 's' && json_option[0]!= 'f')) {
|
||||
if (strlen(json_option)>1 || ( json_option[0] != 's' && json_option[0]!= 'f' && json_option[0]!= 'a')) {
|
||||
printf("wrong json option %s\n",json_option);
|
||||
exit(1);
|
||||
}
|
||||
|
@ -174,6 +175,11 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
|
|||
grib_set_long(h,"unpack",1);
|
||||
grib_dump_content(h,stdout,options->dump_mode,options->dump_flags,0);
|
||||
break;
|
||||
case 'a':
|
||||
grib_set_long(h,"unpack",1);
|
||||
options->dump_flags=GRIB_DUMP_FLAG_ALL_ATTRIBUTES;
|
||||
grib_dump_content(h,stdout,options->dump_mode,options->dump_flags,0);
|
||||
break;
|
||||
default :
|
||||
printf("unknown json option %s\n",json_option);
|
||||
exit(1);
|
||||
|
|
|
@ -273,6 +273,7 @@ char iobuf[1024*1024];
|
|||
static int grib_tool_without_orderby(grib_runtime_options* options)
|
||||
{
|
||||
int err=0;
|
||||
int nofail=0;
|
||||
grib_failed *failed=NULL,*p=NULL;
|
||||
grib_handle* h=NULL;
|
||||
grib_context* c=NULL;
|
||||
|
@ -316,10 +317,11 @@ static int grib_tool_without_orderby(grib_runtime_options* options)
|
|||
infile->filter_handle_count=0;
|
||||
|
||||
grib_tool_new_file_action(options,infile);
|
||||
nofail=grib_options_on("f");
|
||||
|
||||
while(!options->skip_all && ((h = grib_handle_new_from_file_x(c,infile->file,options->mode,
|
||||
options->headers_only,&err))
|
||||
!= NULL || err != GRIB_SUCCESS ) ) {
|
||||
!= NULL || ( err != GRIB_SUCCESS && nofail==0 )) ) {
|
||||
infile->handle_count++;
|
||||
options->handle_count++;
|
||||
options->error=err;
|
||||
|
|
Loading…
Reference in New Issue