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

Dave Allured - NOAA Affiliate dave.allured at noaa.gov
Thu Nov 12 12:16:43 MST 2020


Yes, *isfilevar*, 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.

Correction to my previous reply, the most general purpose function to check
for missing files is *fileexists*.  "*isfilepresent*" should not be used
with text or pure binary input formats.


On Thu, Nov 12, 2020 at 12:04 PM Micah Sklut <micahs2005 at gmail.com> wrote:

> 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
>>>>>
>>>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20201112/26630b5e/attachment.html>


More information about the ncl-talk mailing list