GRIB-389: Provide option to process the input file after a given offset

This commit is contained in:
Shahram Najm 2013-06-17 17:53:16 +01:00
parent 6f46ef11d7
commit 3af99a8309
8 changed files with 63 additions and 24 deletions

View File

@ -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

View File

@ -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}
};

View File

@ -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;

View File

@ -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}
};

View File

@ -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}
};

View File

@ -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; i<grib_options_count; i++) {
if (!strcmp(id,grib_options[i].id))
return grib_options[i].value;
@ -131,9 +133,9 @@ char* grib_options_get_option(const char* id) {
return NULL;
}
int grib_options_command_line(const char* id) {
int grib_options_command_line(const char* id)
{
int i=0;
for (i=0; i<grib_options_count; i++) {
if (!strcmp(id,grib_options[i].id))
return grib_options[i].command_line;
@ -141,9 +143,9 @@ int grib_options_command_line(const char* id) {
return 0;
}
int grib_options_on(const char* id) {
int grib_options_on(const char* id)
{
int i=0;
for (i=0; i<grib_options_count; i++) {
if (!strcmp(id,grib_options[i].id))
return grib_options[i].on;
@ -151,7 +153,8 @@ int grib_options_on(const char* id) {
return 0;
}
int grib_get_runtime_options(int argc,char** argv,grib_runtime_options* options) {
int grib_get_runtime_options(int argc,char** argv,grib_runtime_options* options)
{
int i=0,c=0;
char* optstr=(char*)calloc(1,2*grib_options_count*sizeof(char));
@ -174,7 +177,8 @@ int grib_get_runtime_options(int argc,char** argv,grib_runtime_options* options)
return 0;
}
int grib_process_runtime_options(grib_context* context,int argc,char** argv,grib_runtime_options* options) {
int grib_process_runtime_options(grib_context* context,int argc,char** argv,grib_runtime_options* options)
{
int i=0,ret=0;
int has_output=0;int has_input_extra=0,nfiles=0;
char *karg=NULL,*warg=NULL,*sarg=NULL,*barg=NULL;
@ -212,6 +216,9 @@ int grib_process_runtime_options(grib_context* context,int argc,char** argv,grib
if (grib_options_on("l:"))
options->latlon=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);

View File

@ -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));

View File

@ -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[];