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

Wesley Ebisuzaki - NOAA Federal wesley.ebisuzaki at noaa.gov
Fri Oct 14 08:44:56 EDT 2016


Gary,

On Thu, Oct 13, 2016 at 8:01 PM, Love, Mr. Gary, Contractor, Code 7542 <
gary.love.ctr at nrlmry.navy.mil> wrote:

> Wesley,
>
>
>
> Have you tried
>
>
>
> |     wgrib2 -v 2016101212.gfs.t12z.pgrb2f001 2>&1 | grep ERROR
>
>
>
> The redirect, 2>&1,  is supposed to add the results of STDERR to STDOUT.
>

You can do this but you need to check for two conditions

   1) error detected by wgrib2; for example, the grib message is incomplete
   2) file is short but wgrib2 doesn't find an incomplete grib message.
          for example; the server's copy of the file is missing fields
                  or the transmission fortuitously stopped at the end of a
message.

Condition 2 requires you to read stdout.  Adding stderr to stdout makes life
confusing.  Otherwise it is a good suggestion.

Wesley




>
>
> Gary Love
>
>
>
> *From:* gradsusr-bounces at gradsusr.org [mailto:gradsusr-bounces@
> gradsusr.org] *On Behalf Of *Wesley Ebisuzaki - NOAA Federal
> *Sent:* Thursday, October 13, 2016 6:02 AM
> *To:* GrADS Users Forum
> *Subject:* Re: [gradsusr] Use wgrib2 to check if grib2 file is valid
>
>
>
> 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
>
>
>
> _______________________________________________
> 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/20161014/4a456003/attachment-0001.html 


More information about the gradsusr mailing list