<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">dave.allured@noaa.gov</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid 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:1px solid 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><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature">Micah Sklut<br><br></div></div></div>