ECC-419: Simple bufr_dump

This commit is contained in:
Shahram Najm 2017-09-25 14:08:42 +01:00
parent 4950f4a8ac
commit 3947f5e632
2 changed files with 45 additions and 29 deletions

View File

@ -189,18 +189,19 @@ static void dump_values(grib_dumper* d, grib_accessor* a)
fprintf(self->dumper.out, "%g",values[i]);
depth-=2;
fprintf(self->dumper.out,"};\n");
fprintf(self->dumper.out,"}\n");
grib_context_free(c,values);
} else {
r=compute_bufr_key_rank(h,self->keys,a->name);
if( !grib_is_missing_double(a,value) ) {
if (r!=0)
fprintf(self->dumper.out,"#%d#%s=",r,a->name);
else
fprintf(self->dumper.out,"%s=",a->name);
fprintf(self->dumper.out,"%g;\n",value);
if (!grib_is_missing_double(a,value)) {
fprintf(self->dumper.out,"%g\n",value);
} else {
fprintf(self->dumper.out,"MISSING\n");
}
}
@ -260,12 +261,14 @@ static void dump_values_attribute(grib_dumper* d,grib_accessor* a, const char* p
fprintf(self->dumper.out,"%g", values[i]);
depth-=2;
fprintf(self->dumper.out,"};\n");
fprintf(self->dumper.out,"}\n");
grib_context_free(c,values);
} else {
/* int r=compute_bufr_key_rank(h,self->keys,a->name); */
if( !grib_is_missing_double(a,value) ) {
fprintf(self->dumper.out,"%s->%s = %g;\n", prefix, a->name, value);
fprintf(self->dumper.out,"%s->%s = %g\n", prefix, a->name, value);
} else {
fprintf(self->dumper.out,"%s->%s = MISSING\n", prefix, a->name);
}
}
@ -349,17 +352,19 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment)
fprintf(self->dumper.out,"%ld ",values[i]);
depth-=2;
fprintf(self->dumper.out,"};\n");
fprintf(self->dumper.out,"}\n");
grib_context_free(a->context,values);
} else {
r=compute_bufr_key_rank(h,self->keys,a->name);
if( !grib_is_missing_long(a,value) ) {
if (r!=0)
fprintf(self->dumper.out,"#%d#%s=",r,a->name);
else
fprintf(self->dumper.out,"%s=",a->name);
fprintf(self->dumper.out,"%ld;\n",value);
if( !grib_is_missing_long(a,value) ) {
fprintf(self->dumper.out,"%ld\n",value);
} else {
fprintf(self->dumper.out,"MISSING\n");
}
}
@ -417,14 +422,16 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr
if (icount>cols || i==0) {fprintf(self->dumper.out,"\n ");icount=0;}
fprintf(self->dumper.out,"%ld ",values[i]);
depth-=2;
fprintf(self->dumper.out,"};\n");
fprintf(self->dumper.out,"}\n");
grib_context_free(a->context,values);
} else {
/* int r=compute_bufr_key_rank(h,self->keys,a->name); */
if( !grib_is_missing_long(a,value) ) {
fprintf(self->dumper.out,"%s->%s = ",prefix,a->name);
fprintf(self->dumper.out,"%ld ;\n",value);
fprintf(self->dumper.out,"%ld\n",value);
} else {
fprintf(self->dumper.out,"%s->%s = MISSING\n",prefix,a->name);
}
}
@ -463,13 +470,15 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment)
self->empty=0;
r=compute_bufr_key_rank(h,self->keys,a->name);
if( !grib_is_missing_double(a,value) ) {
if (r!=0)
fprintf(self->dumper.out,"#%d#%s=",r,a->name);
else
fprintf(self->dumper.out,"%s=",a->name);
fprintf(self->dumper.out,"%g;\n",value);
if( !grib_is_missing_double(a,value) ) {
fprintf(self->dumper.out,"%g\n",value);
} else {
fprintf(self->dumper.out,"MISSING\n");
}
if (self->isLeaf==0) {
@ -538,7 +547,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm
depth-=2;
fprintf(self->dumper.out, "};\n");
fprintf(self->dumper.out, "}\n");
if (self->isLeaf==0) {
char* prefix;
@ -601,7 +610,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment)
else
fprintf(self->dumper.out,"%s=",a->name);
}
fprintf(self->dumper.out,"\"%s\";\n",value);
fprintf(self->dumper.out,"\"%s\"\n",value);
if (self->isLeaf==0) {
char* prefix;
@ -647,7 +656,7 @@ static void _dump_long_array(grib_handle* h, FILE* f, const char* key, const cha
icount++;
}
if (icount>cols) {fprintf(f,"\n ");}
fprintf(f,"%ld};\n",val[size-1]);
fprintf(f,"%ld}\n",val[size-1]);
grib_context_free(h->context,val);
}

View File

@ -35,8 +35,10 @@ grib_option grib_options[]={
"\n\t\t C -> C program to encode the input BUFR"
"\n\t\tDefault mode is filter.\n",
0,1,"filter"},
{"S",0,0,1,0,0},
{"O",0,"Octet mode. WMO documentation style dump.\n",0,1,0},
{"p",0,"Plain dump.\n",0,1,0},
/* {"D",0,0,0,1,0}, */ /* See ECC-215 */
{"d",0,"Print all data values.\n",1,1,0},
{"u",0,"Print only some values.\n",0,1,0},
@ -110,6 +112,11 @@ int grib_tool_init(grib_runtime_options* options)
| GRIB_DUMP_FLAG_READ_ONLY;
}
if (grib_options_on("p")) {
options->dump_mode = "bufr_simple";
json=0;
}
if (grib_options_on("D:")) {
options->dump_mode = grib_options_get_option("D:");
json=0;
@ -171,7 +178,7 @@ int grib_tool_new_file_action(grib_runtime_options* options,grib_tools_file* fil
else {
char tmp[1024];
sprintf(tmp,"FILE: %s ",options->current_infile->name);
if (!grib_options_on("C"))
if (!grib_options_on("p"))
fprintf(stdout,"***** %s\n",tmp);
}