[ncl-talk] Trapping warnings for corrupted files
Rick Brownrigg
brownrig at ucar.edu
Tue Dec 17 09:51:49 MST 2019
How about something like:
if (ismissing(g3d)) then
exit
end if
On Tue, Dec 17, 2019 at 9:40 AM Jennifer Krauel via ncl-talk <
ncl-talk at ucar.edu> wrote:
> Thanks, Dave, but even if addfile fails, g3d is still "defined" so this
> doesn't do the trick.
> If I try to print the file handle variable after the failure I get this:
> ncl 3> print(g3d)
>
> Variable: g3d
> (0) File Missing Value : -1
> So, maybe there is a way to interrogate this status, but I'm not sure how
> to do that.
>
> On Thu, Dec 12, 2019 at 2:22 PM Dave Allured - NOAA Affiliate <
> dave.allured at noaa.gov> wrote:
>
>> 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
>>>
>> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20191217/6fb3edca/attachment.html>
More information about the ncl-talk
mailing list