[ncl-talk] determine success of ncl script via bash

Micah Sklut micahs2005 at gmail.com
Thu Nov 12 11:44:19 MST 2020


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.

function ncl_error_check() {
  if grep -q 'fatal' $1; then
    echo 'an NCL error has occurred'
  fi
}

ncl command.ncl > ncl_output.txt
ncl_error_check ncl_output.txt

On Thu, Nov 12, 2020 at 1:32 PM Dave Allured - NOAA Affiliate <
dave.allured at noaa.gov> wrote:

> The NCL function *status_exit* 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.
>
> I can think of four kinds of NCL fatal errors:
>
> * 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.
> * NCL internally detects some kind of fatal error, and exits to the shell.
> * NCL has an uncontrolled crash and exits to the shell.
> * An NCL user program detects a problem and exits to the shell using the
> *status_exit* function.
>
> 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
> *isfilepresent* before blindly trying to open them with *addfile*,
> *cbinread*, etc.
>
> Also I usually use an *if* 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.
>
>
> On Thu, Nov 12, 2020 at 10:57 AM Micah Sklut via ncl-talk <
> ncl-talk at mailman.ucar.edu> wrote:
>
>> Hi,
>>
>> 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?
>>
>> I've tried this without success:
>>
>> ncl nam_file.ncl || {
>>     echo 'failure'
>>     exit
>>   }
>>
>> Thanks.
>> --
>> Micah Sklut
>>
>

-- 
Micah Sklut
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20201112/5ebc3bd6/attachment.html>


More information about the ncl-talk mailing list