<div dir="ltr">Gary,<br><div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 13, 2016 at 8:01 PM, Love, Mr. Gary, Contractor, Code 7542 <span dir="ltr"><<a href="mailto:gary.love.ctr@nrlmry.navy.mil" target="_blank">gary.love.ctr@nrlmry.navy.mil</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div link="blue" vlink="purple" lang="EN-US"><div class="m_-6117770940686539107WordSection1"><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Wesley,<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Have you tried<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">| wgrib2 -v <a href="tel:2016101212" value="+12016101212" target="_blank">2016101212</a>.gfs.t12z.pgrb2f001 2>&1 | grep ERROR<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">The redirect, 2>&1, is supposed to add the results of STDERR to STDOUT.</span></p></div></div></blockquote><div><br></div><div>You can do this but you need to check for two conditions<br><br></div><div> 1) error detected by wgrib2; for example, the grib message is incomplete<br></div><div> 2) file is short but wgrib2 doesn't find an incomplete grib message.<br></div><div> for example; the server's copy of the file is missing fields<br></div><div> or the transmission fortuitously stopped at the end of a message.<br><br></div><div>Condition 2 requires you to read stdout. Adding stderr to stdout makes life<br></div><div>confusing. Otherwise it is a good suggestion.<br><br></div><div>Wesley<br><br></div><div> <br></div><div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div link="blue" vlink="purple" lang="EN-US"><div class="m_-6117770940686539107WordSection1"><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Gary Love<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> <a href="mailto:gradsusr-bounces@gradsusr.org" target="_blank">gradsusr-bounces@gradsusr.org</a> [mailto:<a href="mailto:gradsusr-bounces@gradsusr.org" target="_blank">gradsusr-bounces@<wbr>gradsusr.org</a>] <b>On Behalf Of </b>Wesley Ebisuzaki - NOAA Federal<br><b>Sent:</b> Thursday, October 13, 2016 6:02 AM<br><b>To:</b> GrADS Users Forum<br><b>Subject:</b> Re: [gradsusr] Use wgrib2 to check if grib2 file is valid<u></u><u></u></span></p><p class="MsoNormal"><u></u> <u></u></p><div><p class="MsoNormal" style="margin-bottom:12.0pt">Ivan,<u></u><u></u></p><div><div><p class="MsoNormal" style="margin-bottom:12.0pt">| wgrib2 -v <a href="tel:2016101212" value="+12016101212" target="_blank">2016101212</a>.gfs.t12z.pgrb2f001 | grep ERROR<u></u><u></u></p></div><div><p class="MsoNormal">does not work because the error message is sent to STDERR. <u></u><u></u></p></div><div><p class="MsoNormal" style="margin-bottom:12.0pt">It depends on the shell but in bash,<br><br> wgrib2 -v <a href="tel:2016101212" value="+12016101212" target="_blank">2016101212</a>.gfs.t12z.pgrb2f00 2>stderr.txt<u></u><u></u></p></div><div><p class="MsoNormal" style="margin-bottom:12.0pt">will send the error messages to stderr.txt <u></u><u></u></p></div><div><p class="MsoNormal" style="margin-bottom:12.0pt">My (bash) suggestion is<u></u><u></u></p></div><div><p class="MsoNormal">wgrib2 <a href="tel:2016101212" value="+12016101212" target="_blank">2016101212</a>.gfs.t12z.pgrb2f001 > tmp.inv<u></u><u></u></p></div><div><p class="MsoNormal"># now to check the return code<u></u><u></u></p></div><div><p class="MsoNormal">if ["$?" -ne 0 ] ; then<u></u><u></u></p></div><div><p class="MsoNormal"> echo "ERROR"<u></u><u></u></p></div><div><p class="MsoNormal"> do_something<u></u><u></u></p></div><div><p class="MsoNormal" style="margin-bottom:12.0pt">fi<u></u><u></u></p></div><div><p class="MsoNormal"># since is is possible that you got no file or a smaller but complete file<u></u><u></u></p></div><div><p class="MsoNormal" style="margin-bottom:12.0pt"># check the number of lines in the inventory .. see if you got what you want<u></u><u></u></p></div><div><p class="MsoNormal">N_REC=22<u></u><u></u></p></div><div><p class="MsoNormal">if [ "$N_REC" -ne `wc -n <tmp.inv` ] ; then<u></u><u></u></p></div><div><p class="MsoNormal"> echo "ERROR2"<u></u><u></u></p></div><div><p class="MsoNormal"> do_something<u></u><u></u></p></div><div><p class="MsoNormal">fi<u></u><u></u></p></div><div><p class="MsoNormal" style="margin-bottom:12.0pt">rm tmp.inv<u></u><u></u></p></div><div><p class="MsoNormal">Wesley<u></u><u></u></p></div><div><p class="MsoNormal" style="margin-bottom:12.0pt"><u></u> <u></u></p><div><p class="MsoNormal">On Wed, Oct 12, 2016 at 5:48 PM, Ivan Toman <<a href="mailto:ivtoman@inet.hr" target="_blank">ivtoman@inet.hr</a>> wrote:<u></u><u></u></p><p class="MsoNormal">Hello Jeff,<br><br>I do compare file sizes currently, but as they change little bit, it is<br>still not too robust. I'm trying to find fail proof solution.<br><br>So as I said, I can't capture response from wgrib2 into variable for<br>some reason. See these two examples:<br><br>Example 1) Capturing date output to variable:<br>$ response=`date`<br>$ echo $response<br>Wed Oct 12 20:50:46 UTC 2016<br><br>Works just fine.<br><br><br>Wgrib2 error:<br>wgrib2 -v <a href="tel:2016101212" value="+12016101212" target="_blank">2016101212</a>.gfs.t12z.pgrb2f001 | grep ERROR<br><br>*** FATAL ERROR: rd_grib2_msg_seq_file, read outside of file, bad grib<br>file ***<br><br><br>Example 2) Trying to capture ERROR from wgrib2:<br>$ response=`wgrib2 -v <a href="tel:2016101212" value="+12016101212" target="_blank">2016101212</a>.gfs.t12z.pgrb2f001 | grep ERROR`<br><br>*** FATAL ERROR: rd_grib2_msg_seq_file, read outside of file, bad grib<br>file ***<br>$ echo $response<br><br><br>Nothing is returned. Empty variable. That is what I try to fix..<br><br>Thank you,<br>Ivan Toman<br><br>______________________________<wbr>_________________<br>gradsusr mailing list<br><a href="mailto:gradsusr@gradsusr.org" target="_blank">gradsusr@gradsusr.org</a><br><a href="http://gradsusr.org/mailman/listinfo/gradsusr" target="_blank">http://gradsusr.org/mailman/<wbr>listinfo/gradsusr</a><u></u><u></u></p></div><p class="MsoNormal"><u></u> <u></u></p></div></div></div></div></div><br>______________________________<wbr>_________________<br>
gradsusr mailing list<br>
<a href="mailto:gradsusr@gradsusr.org">gradsusr@gradsusr.org</a><br>
<a href="http://gradsusr.org/mailman/listinfo/gradsusr" rel="noreferrer" target="_blank">http://gradsusr.org/mailman/<wbr>listinfo/gradsusr</a><br>
<br></blockquote></div><br></div></div></div>