[gradsusr] Use wgrib2 to check if grib2 file is valid

Wesley Ebisuzaki - NOAA Federal wesley.ebisuzaki at noaa.gov
Thu Oct 13 09:02:24 EDT 2016


Ivan,

|     wgrib2 -v 2016101212.gfs.t12z.pgrb2f001 | grep ERROR

does not work because the error message is sent to STDERR.
It depends on the shell but in bash,

      wgrib2 -v 2016101212.gfs.t12z.pgrb2f00 2>stderr.txt

will send the error messages to stderr.txt

My (bash) suggestion is

wgrib2 2016101212.gfs.t12z.pgrb2f001 > tmp.inv
# now to check the return code
if ["$?" -ne 0 ] ; then
  echo "ERROR"
  do_something
fi

# since is is possible that you got no file or a smaller but complete file
# check the number of lines in the inventory .. see if you got what you want

N_REC=22
if [ "$N_REC" -ne `wc -n <tmp.inv` ] ; then
   echo "ERROR2"
   do_something
fi
rm tmp.inv

Wesley


On Wed, Oct 12, 2016 at 5:48 PM, Ivan Toman <ivtoman at inet.hr> wrote:

> Hello Jeff,
>
> I do compare file sizes currently, but as they change little bit, it is
> still not too robust. I'm trying to find fail proof solution.
>
> So as I said, I can't capture response from wgrib2 into variable for
> some reason. See these two examples:
>
> Example 1) Capturing date output to variable:
> $ response=`date`
> $ echo $response
> Wed Oct 12 20:50:46 UTC 2016
>
> Works just fine.
>
>
> Wgrib2 error:
> wgrib2 -v 2016101212.gfs.t12z.pgrb2f001 | grep ERROR
>
> *** FATAL ERROR: rd_grib2_msg_seq_file, read outside of file, bad grib
> file ***
>
>
> Example 2) Trying to capture ERROR from wgrib2:
> $ response=`wgrib2 -v 2016101212.gfs.t12z.pgrb2f001 | grep ERROR`
>
> *** FATAL ERROR: rd_grib2_msg_seq_file, read outside of file, bad grib
> file ***
> $ echo $response
>
>
> Nothing is returned. Empty variable. That is what I try to fix..
>
> Thank you,
> Ivan Toman
>
> _______________________________________________
> gradsusr mailing list
> gradsusr at gradsusr.org
> http://gradsusr.org/mailman/listinfo/gradsusr
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20161013/91faa837/attachment.html 


More information about the gradsusr mailing list