<div dir="ltr"><div dir="ltr">Yes, <b>isfilevar</b>, as Adam just said. There are several useful NCL functions to safely test the various components of structured input files like Netcdf and Grib. Dimensions, attributes, etc. Find these inquiry functions under the file I/O category in the NCL function indexes.<br><br>Correction to my previous reply, the most general purpose function to check for missing files is <b>fileexists</b>. "<b>isfilepresent</b>" should not be used with text or pure binary input formats.</div><div dir="ltr"><br></div><div dir="ltr"><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Nov 12, 2020 at 12:04 PM Micah Sklut <<a href="mailto:micahs2005@gmail.com">micahs2005@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">Great, thanks Adam for the tip on the isfilevar function. </div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Nov 12, 2020 at 1:49 PM Adam Phillips <<a href="mailto:asphilli@ucar.edu" target="_blank">asphilli@ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">HI Micah,<div>You could use isfilevar to check for a variable on a file before attempting to read it:</div><div><a href="http://www.ncl.ucar.edu/Document/Functions/Built-in/isfilevar.shtml" target="_blank">http://www.ncl.ucar.edu/Document/Functions/Built-in/isfilevar.shtml</a><br></div><div>Adam</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Nov 12, 2020 at 11:44 AM Micah Sklut via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank">ncl-talk@mailman.ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">Thank you for that comprehensive answer Dave. In the specific case that I am encountering, there was an issue on the NCEP data, where variables were not included in the file. Perhaps there are ncl functions for this type of error check? The solution that I started to work with is checking the output from the ncl command, and using grep to determine if the string 'fatal' exists. <br><br><div>function ncl_error_check() {<br> if grep -q 'fatal' $1; then<br> echo 'an NCL error has occurred'<br> fi<br>}</div></div><div><br></div>ncl command.ncl > ncl_output.txt<div>ncl_error_check ncl_output.txt </div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Nov 12, 2020 at 1:32 PM Dave Allured - NOAA Affiliate <<a href="mailto:dave.allured@noaa.gov" target="_blank">dave.allured@noaa.gov</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>The NCL function <b>status_exit</b> allows the user program to set the integer exit status code, which can be read by the shell. This is probably what you want. See the example and discussion on that function's doc page.</div><div><br></div><div>I can think of four kinds of NCL fatal errors:</div><div><br></div><div>* NCL reports a "fatal error" to the console, but the program keeps running and does not exit. This happens more often than I would like.</div><div>* NCL internally detects some kind of fatal error, and exits to the shell.</div><div>* NCL has an uncontrolled crash and exits to the shell.</div><div>* An NCL user program detects a problem and exits to the shell using the <b>status_exit</b> function.</div><div><br></div><div>Unfortunately the exit status code is undefined in the first three cases. This is why it is best for user programs to manually check for predictable errors, and handle their own error exits in an intelligent way. One example is to check for missing input files with functions like <b>isfilepresent</b> before blindly trying to open them with <b>addfile</b>, <b>cbinread</b>, etc.</div><div><br></div><div>Also I usually use an <b>if</b> statement in C shell to check the exit code. Not being a bash expert, I do not understand the double pipe syntax in your example. If you think your NCL program is emitting proper exit codes, you might check your bash code to make sure it is doing what you think.</div><div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Nov 12, 2020 at 10:57 AM Micah Sklut via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank">ncl-talk@mailman.ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi, <div><br></div><div>I run a bunch of ncl script operationally in bash scripts. I'd like to be able to detect if NCL encounters a fatal error. Any suggestions on this? </div><div><br></div><div>I've tried this without success: </div><div><br></div><div>
ncl nam_file.ncl || {<br> echo 'failure'<br> exit<br> }<br><div><br></div><div>Thanks. </div>-- <br><div dir="ltr">Micah Sklut</div></div></div></blockquote></div></div></blockquote></div></div></div></blockquote></div></blockquote></div>
</blockquote></div></div></div>