ECC-323: bufr_dump should fail if decoding fails

This commit is contained in:
Shahram Najm 2016-08-30 13:45:02 +01:00
parent e46bce1dea
commit 556104df42
37 changed files with 249 additions and 203 deletions

View File

@ -1280,7 +1280,7 @@ static int compare_handles(grib_handle* handle1, grib_handle* handle2, grib_runt
return err;
}
int grib_no_handle_action(int err)
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;

View File

@ -115,7 +115,7 @@ int grib_tool_finalise_action(grib_runtime_options* options)
return 0;
}
int grib_no_handle_action(int err)
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;

View File

@ -136,12 +136,14 @@ int grib_tool_new_filename_action(grib_runtime_options* options,const char* file
int grib_tool_new_file_action(grib_runtime_options* options,grib_tools_file* file)
{
char tmp[1024];
if (!options->current_infile->name) return 0;
if (json) return 0;
if (grib_options_on("E:")) {
} else {
/* No action */
}
else {
char tmp[1024];
sprintf(tmp,"FILE: %s ",options->current_infile->name);
if (!grib_options_on("C"))
fprintf(stdout,"***** %s\n",tmp);
@ -153,7 +155,6 @@ int grib_tool_new_file_action(grib_runtime_options* options,grib_tools_file* fil
int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
{
long length=0;
char tmp[1024];
int i,err=0;
grib_accessor* a=NULL;
grib_accessors_list* al=NULL;
@ -182,10 +183,16 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
case 'f':
err=grib_set_long(h,"unpack",2);
if (err) {
if (options->fail) {
fprintf(stderr, "ERROR: unable to unpack data section: %s (message=%d)\n",
grib_get_error_message(err), options->handle_count);
exit(err);
} else {
fprintf(stdout,"\"ERROR: unable to unpack data section\"");
options->error=err;
return err;
}
}
a=grib_find_accessor(h,"numericValues");
al=accessor_bufr_data_array_get_dataAccessors(a);
options->dump_flags=GRIB_DUMP_FLAG_ALL_ATTRIBUTES;
@ -194,19 +201,31 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
case 's':
err=grib_set_long(h,"unpack",1);
if (err) {
if (options->fail) {
fprintf(stderr, "ERROR: unable to unpack data section: %s (message=%d)\n",
grib_get_error_message(err), options->handle_count);
exit(err);
} else {
fprintf(stdout,"\"ERROR: unable to unpack data section\"");
options->error=err;
return err;
}
}
grib_dump_content(h,stdout,options->dump_mode,options->dump_flags,0);
break;
case 'a':
err=grib_set_long(h,"unpack",1);
if (err) {
if (options->fail) {
fprintf(stderr, "ERROR: unable to unpack data section: %s (message=%d)\n",
grib_get_error_message(err), options->handle_count);
exit(err);
} else {
fprintf(stdout,"\"ERROR: unable to unpack data section\"");
options->error=err;
return err;
}
}
options->dump_flags=GRIB_DUMP_FLAG_ALL_ATTRIBUTES;
grib_dump_content(h,stdout,options->dump_mode,options->dump_flags,0);
break;
@ -214,26 +233,38 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
printf("Unknown JSON option %s\n",json_option);
exit(1);
}
if (!strcmp(options->dump_mode,"default"))
if (!strcmp(options->dump_mode,"default")) {
printf("}\n");
}
} else if (grib_options_on("O")) {
char tmp[1024];
sprintf(tmp,"MESSAGE %d ( length=%ld )",options->handle_count,length);
if (!grib_options_on("C"))
fprintf(stdout,"#============== %-38s ==============\n",tmp);
err=grib_set_long(h,"unpack",1);
if (err) {
if (options->fail) {
fprintf(stderr, "ERROR: unable to unpack data section: %s\n",grib_get_error_message(err));
exit(err);
} else {
fprintf(stdout,"\"ERROR: unable to unpack data section\"");
options->error=err;
return err;
}
}
grib_dump_content(h,stdout,options->dump_mode,options->dump_flags,0);
} else {
err=grib_set_long(h,"unpack",1);
if (err) {
if (options->fail) {
fprintf(stderr, "ERROR: unable to unpack data section: %s\n",grib_get_error_message(err));
exit(err);
} else {
fprintf(stdout,"\"ERROR: unable to unpack data section\"");
options->error=err;
return err;
}
}
dumper=grib_dump_content_with_dumper(h,dumper,stdout,options->dump_mode,options->dump_flags,0);
if (!dumper) exit(1);
}
@ -277,7 +308,8 @@ int grib_tool_finalise_action(grib_runtime_options* options)
return 0;
}
int grib_no_handle_action(int err) {
int grib_no_handle_action(grib_runtime_options* options, int err)
{
if (json ){
if (first_handle) {
fprintf(dump_file,"{ \"messages\" : [ \n");
@ -287,5 +319,8 @@ int grib_no_handle_action(int err) {
}
}
fprintf(dump_file,"\"ERROR: unreadable message\"\n");
if (options->fail) {
exit(1);
}
return 0;
}

View File

@ -114,8 +114,8 @@ int grib_tool_finalise_action(grib_runtime_options* options)
return 0;
}
int grib_no_handle_action(int err) {
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;
}

View File

@ -214,7 +214,8 @@ int grib_tool_finalise_action(grib_runtime_options* options)
return 0;
}
int grib_no_handle_action(int err) {
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;
}

View File

@ -148,8 +148,8 @@ int grib_tool_finalise_action(grib_runtime_options* options)
return 0;
}
int grib_no_handle_action(int err) {
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;
}

View File

@ -374,8 +374,8 @@ int grib_tool_finalise_action(grib_runtime_options* options)
return 0;
}
int grib_no_handle_action(int err) {
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;
}

View File

@ -168,8 +168,8 @@ int grib_tool_finalise_action(grib_runtime_options* options)
return 0;
}
int grib_no_handle_action(int err) {
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;
}

View File

@ -1126,7 +1126,7 @@ static int compare_handles(grib_handle* h1,grib_handle* h2,grib_runtime_options*
return err;
}
int grib_no_handle_action(int err)
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;

View File

@ -142,7 +142,7 @@ int grib_tool_finalise_action(grib_runtime_options* options)
return 0;
}
int grib_no_handle_action(int err)
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;

View File

@ -211,7 +211,7 @@ int grib_tool_finalise_action(grib_runtime_options* options)
return 0;
}
int grib_no_handle_action(int err)
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;

View File

@ -118,8 +118,8 @@ int grib_tool_finalise_action(grib_runtime_options* options)
return 0;
}
int grib_no_handle_action(int err) {
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;
}

View File

@ -217,7 +217,7 @@ int grib_tool_finalise_action(grib_runtime_options* options)
return 0;
}
int grib_no_handle_action(int err)
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;

View File

@ -285,9 +285,8 @@ static grib_values* get_key_values(grib_runtime_options* options,grib_handle* h)
}
int grib_no_handle_action(int err)
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;
}

View File

@ -148,7 +148,7 @@ int grib_tool_finalise_action(grib_runtime_options* options)
return 0;
}
int grib_no_handle_action(int err)
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;

View File

@ -390,7 +390,7 @@ int grib_tool_finalise_action(grib_runtime_options* options)
return 0;
}
int grib_no_handle_action(int err)
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;

View File

@ -52,29 +52,35 @@ grib_option grib_options[]={
int grib_options_count=sizeof(grib_options)/sizeof(grib_option);
int main(int argc, char *argv[]) {
int main(int argc, char *argv[])
{
int ret=grib_tool(argc,argv);
return ret;
}
int grib_tool_before_getopt(grib_runtime_options* options) {
int grib_tool_before_getopt(grib_runtime_options* options)
{
return 0;
}
int grib_tool_init(grib_runtime_options* options) {
int grib_tool_init(grib_runtime_options* options)
{
return 0;
}
int grib_tool_new_filename_action(grib_runtime_options* options,const char* file) {
int grib_tool_new_filename_action(grib_runtime_options* options,const char* file)
{
return 0;
}
int grib_tool_new_file_action(grib_runtime_options* options,grib_tools_file* file) {
int grib_tool_new_file_action(grib_runtime_options* options,grib_tools_file* file)
{
return 0;
}
int idx(double lat,double lon,double latFirst,double lonFirst,double latLast,double lonLast,
long Ni,double di,double dj) {
long Ni,double di,double dj)
{
long ilon,ilat;
if ((ilon=(lon-lonFirst)/di) < 0 ) return -1;
if ((ilat=(latFirst-lat)/dj) < 0 ) return -1;
@ -90,7 +96,8 @@ int idx(double lat,double lon,double latFirst,double lonFirst,double latLast,dou
return ilon+ilat*Ni;
}
grib_handle* merge(grib_handle* h1,grib_handle* h2) {
grib_handle* merge(grib_handle* h1,grib_handle* h2)
{
char s1[100]={0,};
size_t len1;
char s2[100]={0,};
@ -284,7 +291,8 @@ grib_handle* merge(grib_handle* h1,grib_handle* h2) {
return h;
}
int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h) {
int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
{
int err=0;
grib_handle* hm=0;
char md5[200]={0,};
@ -309,16 +317,19 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h) {
return err;
}
int grib_tool_skip_handle(grib_runtime_options* options, grib_handle* h) {
int grib_tool_skip_handle(grib_runtime_options* options, grib_handle* h)
{
grib_handle_delete(h);
return 0;
}
void grib_tool_print_key_values(grib_runtime_options* options,grib_handle* h) {
void grib_tool_print_key_values(grib_runtime_options* options,grib_handle* h)
{
grib_print_key_values(options,h);
}
int grib_tool_finalise_action(grib_runtime_options* options) {
int grib_tool_finalise_action(grib_runtime_options* options)
{
grib_tools_write_message(options,hh);
if (options->outfile->file) {
fclose(options->outfile->file);
@ -326,8 +337,8 @@ int grib_tool_finalise_action(grib_runtime_options* options) {
return 0;
}
int grib_no_handle_action(int err) {
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;
}

View File

@ -169,7 +169,7 @@ int grib_tool_finalise_action(grib_runtime_options* options)
return 0;
}
int grib_no_handle_action(int err)
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;

View File

@ -4243,7 +4243,7 @@ int grib_tool_finalise_action(grib_runtime_options* options)
return 0;
}
int grib_no_handle_action(int err)
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;

View File

@ -228,7 +228,7 @@ static int grib_tool_with_orderby(grib_runtime_options* options)
options->error=err;
if (!h) {
grib_no_handle_action(err);
grib_no_handle_action(options, err);
failed=(grib_failed*)grib_context_malloc_clear(c,sizeof(grib_failed));
failed->count=infile->handle_count;
@ -327,7 +327,7 @@ static int grib_tool_without_orderby(grib_runtime_options* options)
if (!h) {
/* fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n"); */
grib_no_handle_action(err);
grib_no_handle_action(options, err);
failed=(grib_failed*)grib_context_malloc_clear(c,sizeof(grib_failed));
failed->count=infile->handle_count;

View File

@ -194,7 +194,7 @@ int grib_get_runtime_options(int argc,char** argv,grib_runtime_options* options)
int grib_process_runtime_options(grib_context* c,int argc,char** argv,grib_runtime_options* options);
void grib_tools_write_message(grib_runtime_options* options, grib_handle* h);
int grib_tool_new_filename_action(grib_runtime_options* options,const char* file);
int grib_no_handle_action(int err);
int grib_no_handle_action(grib_runtime_options* options,int err);
#endif

View File

@ -951,7 +951,7 @@ static int compare_handles(grib_handle* h1,grib_handle* h2,grib_runtime_options*
return err;
}
int grib_no_handle_action(int err)
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;

View File

@ -111,7 +111,7 @@ int grib_tool_finalise_action(grib_runtime_options* options)
return 0;
}
int grib_no_handle_action(int err)
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;

View File

@ -152,7 +152,7 @@ int grib_tool_finalise_action(grib_runtime_options* options)
return 0;
}
int grib_no_handle_action(int err)
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;

View File

@ -102,7 +102,7 @@ int grib_tool_finalise_action(grib_runtime_options* options)
return 0;
}
int grib_no_handle_action(int err)
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;

View File

@ -98,7 +98,7 @@ int grib_tool_finalise_action(grib_runtime_options* options)
return 0;
}
int grib_no_handle_action(int err)
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;

View File

@ -119,7 +119,7 @@ int grib_tool_finalise_action(grib_runtime_options* options)
return 0;
}
int grib_no_handle_action(int err)
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;

View File

@ -1166,7 +1166,7 @@ static int compare_handles(grib_handle* h1,grib_handle* h2,grib_runtime_options*
return err;
}
int grib_no_handle_action(int err)
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;

View File

@ -111,7 +111,7 @@ int grib_tool_finalise_action(grib_runtime_options* options)
return 0;
}
int grib_no_handle_action(int err)
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;

View File

@ -157,8 +157,8 @@ int grib_tool_finalise_action(grib_runtime_options* options) {
return 0;
}
int grib_no_handle_action(int err) {
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;
}

View File

@ -100,7 +100,7 @@ int grib_tool_finalise_action(grib_runtime_options* options)
return 0;
}
int grib_no_handle_action(int err)
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;

View File

@ -101,7 +101,7 @@ int grib_tool_finalise_action(grib_runtime_options* options)
return 0;
}
int grib_no_handle_action(int err)
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;

View File

@ -349,8 +349,8 @@ int grib_tool_finalise_action(grib_runtime_options* options) {
return 0;
}
int grib_no_handle_action(int err) {
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;
}

View File

@ -158,7 +158,7 @@ int grib_tool_finalise_action(grib_runtime_options* options)
return 0;
}
int grib_no_handle_action(int err)
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;

View File

@ -102,7 +102,7 @@ int grib_tool_finalise_action(grib_runtime_options* options)
return 0;
}
int grib_no_handle_action(int err)
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;

View File

@ -212,7 +212,7 @@ int grib_tool_finalise_action(grib_runtime_options* options)
return 0;
}
int grib_no_handle_action(int err)
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;

View File

@ -269,7 +269,7 @@ int grib_tool_finalise_action(grib_runtime_options* options)
return 0;
}
int grib_no_handle_action(int err)
int grib_no_handle_action(grib_runtime_options* options, int err)
{
fprintf(dump_file,"\t\t\"ERROR: unreadable message\"\n");
return 0;