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

Micah Sklut micahs2005 at gmail.com
Thu Nov 12 12:04:25 MST 2020


Great, thanks Adam for the tip on the isfilevar function.

On Thu, Nov 12, 2020 at 1:49 PM Adam Phillips <asphilli at ucar.edu> wrote:

> HI Micah,
> You could use isfilevar to check for a variable on a file before
> attempting to read it:
> http://www.ncl.ucar.edu/Document/Functions/Built-in/isfilevar.shtml
> Adam
>
> On Thu, Nov 12, 2020 at 11:44 AM Micah Sklut via ncl-talk <
> ncl-talk at mailman.ucar.edu> wrote:
>
>> 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
>>
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at mailman.ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> https://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
>
> --
> Adam Phillips
> Associate Scientist,  Climate and Global Dynamics Laboratory, NCAR
> www.cgd.ucar.edu/staff/asphilli/   303-497-1726
>
> <http://www.cgd.ucar.edu/staff/asphilli>
>


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


More information about the ncl-talk mailing list