diff --git a/tests/ls.sh b/tests/ls.sh index cb61b78d8..400e4c436 100755 --- a/tests/ls.sh +++ b/tests/ls.sh @@ -73,5 +73,15 @@ if [ -f "sst_globus0083.grib" ]; then ${tools_dir}grib_ls sst_globus0083.grib > /dev/null fi +# GRIB-387 printing key of type byte +${tools_dir}grib_ls -p uuidOfVGrid test_uuid.grib2 > /dev/null + +# GRIB-389 test for -X switch +result=`${tools_dir}grib_get -wcount=1 -p typeOfLevel,level,shortName tigge_pf_ecmwf.grib2` +[ "$result" = "heightAboveGround 10 10u" ] +# Fast-forward to 3rd message +result=`${tools_dir}grib_get -X 3000 -wcount=1 -p typeOfLevel,level,shortName tigge_pf_ecmwf.grib2` +[ "$result" = "entireAtmosphere 0 cape" ] + cd $workdir diff --git a/tools/grib_dump.c b/tools/grib_dump.c index 0d8fd5a08..c7273d69d 100644 --- a/tools/grib_dump.c +++ b/tools/grib_dump.c @@ -32,6 +32,7 @@ grib_option grib_options[]={ {"7",0,0,0,1,0}, {"V",0,0,0,1,0}, {"q",0,0,1,0,0}, + {"X:",0,0,0,1,0}, {"x",0,0,0,1,0} }; diff --git a/tools/grib_get.c b/tools/grib_get.c index d21f49ba0..f1ae12934 100644 --- a/tools/grib_get.c +++ b/tools/grib_get.c @@ -35,6 +35,7 @@ grib_option grib_options[]={ {"T:",0,0,0,1,0}, {"7",0,0,0,1,0}, {"v",0,0,1,0,0}, + {"X:",0,0,0,1,0}, {"i:",0,0,0,1,0} }; @@ -52,12 +53,14 @@ grib_nearest* n=NULL; int main(int argc, char *argv[]) { return grib_tool(argc,argv);} -int grib_tool_before_getopt(grib_runtime_options* options) { +int grib_tool_before_getopt(grib_runtime_options* options) +{ options->print_keys_count=-1; return 0; } -int grib_tool_init(grib_runtime_options* options) { +int grib_tool_init(grib_runtime_options* options) +{ char *theEnd = NULL, *end1=NULL; size_t size=4; int ret=0; @@ -147,16 +150,20 @@ 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 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) +{ size_t size=4; int err = 0; @@ -186,23 +193,24 @@ int grib_tool_new_handle_action(grib_runtime_options* options,grib_handle* h) { options->latlon_idx=i; } } - } return 0; } -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) +{ if (n) grib_nearest_delete(n); return 0; diff --git a/tools/grib_get_data.c b/tools/grib_get_data.c index 46c595075..4c7b622a3 100644 --- a/tools/grib_get_data.c +++ b/tools/grib_get_data.c @@ -32,6 +32,7 @@ grib_option grib_options[]={ {"f",0,0,0,1,0}, {"G",0,0,0,1,0}, {"7",0,0,0,1,0}, + {"X:",0,0,0,1,0}, {"V",0,0,0,1,0} }; diff --git a/tools/grib_ls.c b/tools/grib_ls.c index 84d20747b..b3f439209 100644 --- a/tools/grib_ls.c +++ b/tools/grib_ls.c @@ -38,6 +38,7 @@ grib_option grib_options[]={ {"T:",0,0,0,1,0}, {"7",0,0,0,1,0}, {"v",0,0,1,0,0}, + {"X:",0,0,0,1,0}, {"x",0,0,0,1,0} }; diff --git a/tools/grib_options.c b/tools/grib_options.c index 4536d0410..28ae9279f 100644 --- a/tools/grib_options.c +++ b/tools/grib_options.c @@ -97,6 +97,7 @@ grib_options_help grib_options_help_list[] ={ {"T:","T | B","Message type. T->GTS, B->BUFR. The input file is interpreted according the message type.\n"}, {"V",0,"Version.\n"}, {"W:","width","\n\t\tMinimum width of each column in output. Default is 10.\n"}, + {"X:","offset","\n\t\tInput file offset in bytes. Processing of the input file will start from \"offset\".\n"}, {"x",0,"Fast parsing option, only headers are loaded.\n"}, {"k:","key1,key2,...","\n\t\tSpecify a list of keys to index on. By default the input files are indexed on the MARS keys.\n"} @@ -105,7 +106,8 @@ grib_options_help grib_options_help_list[] ={ int grib_options_help_count=sizeof(grib_options_help_list)/sizeof(grib_options_help); -void usage() { +void usage() +{ int i=0; printf("\nNAME \t%s\n\n",grib_tool_name); printf("DESCRIPTION\n\t%s\n\n",grib_tool_description); @@ -121,9 +123,9 @@ void usage() { exit(1); } -char* grib_options_get_option(const char* id) { +char* grib_options_get_option(const char* id) +{ int i=0; - for (i=0; ilatlon=grib_options_get_option("l:"); + if (grib_options_on("X:")) + options->infile_offset=atol(grib_options_get_option("X:")); + has_output=grib_options_on("U"); has_input_extra=grib_options_on("I"); options->repack=grib_options_on("r"); @@ -347,8 +354,8 @@ int grib_process_runtime_options(grib_context* context,int argc,char** argv,grib return GRIB_SUCCESS; } - -char* grib_options_get_help(char* id) { +char* grib_options_get_help(char* id) +{ int i=0; char msg[]="ERROR: help not found for option "; char* err=(char*)calloc(1,sizeof(msg)+3); @@ -367,7 +374,8 @@ char* grib_options_get_help(char* id) { return err; } -char* grib_options_get_args(char* id) { +char* grib_options_get_args(char* id) +{ int i=0; char empty[]=""; char msg[]="ERROR: help not found for option -"; @@ -389,7 +397,8 @@ char* grib_options_get_args(char* id) { return err; } -void usage_doxygen() { +void usage_doxygen() +{ int i=0; printf("/*! \\page %s %s\n",grib_tool_name,grib_tool_name); printf("\\section DESCRIPTION \n %s\n\n",grib_tool_description); diff --git a/tools/grib_tools.c b/tools/grib_tools.c index c2a43b44f..6a3c3eb3d 100644 --- a/tools/grib_tools.c +++ b/tools/grib_tools.c @@ -98,7 +98,8 @@ grib_runtime_options options={ 0, /* mode */ 0, /* headers_only */ 0, /* skip_all */ - {{0,},} /* grib_values tolerance[MAX_KEYS] */ + {{0,},}, /* grib_values tolerance[MAX_KEYS] */ + 0 /* infile_offset */ }; @@ -282,6 +283,13 @@ static int grib_tool_without_orderby(grib_runtime_options* options) { perror(infile->name); exit(1); } + if (options->infile_offset) { + err=fseeko(infile->file, options->infile_offset, SEEK_SET); + if (err) { + fprintf(stderr, "Invalid file offset: %ld\n", options->infile_offset); + exit(1); + } + } setvbuf(infile->file,iobuf,_IOFBF,sizeof(iobuf)); diff --git a/tools/grib_tools.h b/tools/grib_tools.h index b7c3dabeb..fa82ccfcc 100644 --- a/tools/grib_tools.h +++ b/tools/grib_tools.h @@ -155,6 +155,7 @@ typedef struct grib_runtime_options { int headers_only; int skip_all; grib_values tolerance[MAX_KEYS]; + off_t infile_offset; } grib_runtime_options; extern grib_option grib_options[];