ECC-629: grib_ls and grib_count to read standard input instead of a filename

This commit is contained in:
Shahram Najm 2018-02-01 11:00:58 +00:00
parent 61373165a0
commit ea977d738a
4 changed files with 23 additions and 4 deletions

View File

@ -36,7 +36,11 @@ set -e
[ $status -ne 0 ]
# With -f should count the valid messages
count=`${tools_dir}/bufr_count -f $temp`
[ "$count" = "2" ]
vcount=`${tools_dir}/bufr_count -f $temp`
[ "$vcount" = "2" ]
# Reading from stdin
count2=`cat $input | ${tools_dir}/bufr_count -`
[ $count -eq $count2 ]
rm -f $temp

View File

@ -48,5 +48,14 @@ ${tools_dir}/bufr_ls -p totalLength,bufrHeaderCentre,bufrHeaderSubCentre,masterT
awk NR==3 $fTmp | awk '{split($0,a," "); for (i=1; i<=8; i++) print a[i]}' > $res_ls
diff $ref_ls $res_ls
#-------------------------------------------
# Test reading from stdin
#-------------------------------------------
f="aaen_55.bufr"
cat $f | ${tools_dir}/bufr_ls -
result1=`${tools_dir}/bufr_get -p numberOfSubsets $f`
result2=`cat $f | ${tools_dir}/bufr_get -p numberOfSubsets -`
[ "$result1" = "$result2" ]
rm -f $fLog $res_ls
rm -f $fTmp

View File

@ -88,7 +88,10 @@ int main(int argc,char* argv[])
continue;
}
filename=argv[i];
infh=fopen(filename,"r");
if (strcmp(filename,"-")==0)
infh=stdin;
else
infh=fopen(filename,"r");
if (!infh) {
perror(filename);
exit(1);

View File

@ -286,7 +286,10 @@ static int grib_tool_without_orderby(grib_runtime_options* options)
while (infile!=NULL && infile->name!=NULL) {
if (options->print_statistics && options->verbose) fprintf(dump_file,"%s\n",infile->name);
infile->file = fopen(infile->name,"r");
if (strcmp(infile->name,"-")==0)
infile->file = stdin;
else
infile->file = fopen(infile->name,"r");
if(!infile->file) {
perror(infile->name);
exit(1);