[ncl-talk] Trapping warnings for corrupted files

Dave Allured - NOAA Affiliate dave.allured at noaa.gov
Thu Dec 12 13:22:29 MST 2019


Try this (untested):

g3d = addfile (...)
if (.not. isdefined ("g3d")) then
   [print error message and exit]
end if


On Thu, Dec 12, 2019 at 1:12 PM Jennifer Krauel via ncl-talk <
ncl-talk at ucar.edu> wrote:

> I'm running a script that opens a NARR GRIB file, reads data, and writes a
> .csv file. It seems to work fine if the data is valid, but sometimes the
> GRIB file is bad. I would like to trap this and handle it gracefully but I
> can't figure out how to do this. When I call addfile I get this warning:
>
> warning:_NclOpenFile: Can not open file <NARR3D_201811_0103.subset>; file
> format not supported or file is corrupted
>
> Despite this warning, the function isfile returns true. Later when I try
> to access a variable in the file I get these errors:
>
> fatal:file (g3d) isn't defined
>
> fatal:["Execute.c":8637]:Execute: Error occurred at or near line 35 in
> file read3D.ncl
>
> What I'd like to do is just quit the script if I get that initial warning.
> What is the best way to handle this?
>
> Thanks,
>
> Jennifer
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20191212/56ac1580/attachment.html>


More information about the ncl-talk mailing list