<div dir="ltr"><div>Thanks, Dave, but even if addfile fails, g3d is still "defined" so this doesn't do the trick.</div><div>If I try to print the file handle variable after the failure I get this:</div><div>ncl 3> print(g3d)<br><br>Variable: g3d<br>(0) File Missing Value : -1</div><div>So, maybe there is a way to interrogate this status, but I'm not sure how to do that.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Dec 12, 2019 at 2:22 PM Dave Allured - NOAA Affiliate <<a href="mailto:dave.allured@noaa.gov">dave.allured@noaa.gov</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">Try this (untested):</div><div dir="ltr"><br></div><div dir="ltr">g3d = addfile (...)</div><div dir="ltr">if (.not. isdefined ("g3d")) then</div><div dir="ltr">   [print error message and exit]</div><div dir="ltr">end if<div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Dec 12, 2019 at 1:12 PM Jennifer Krauel via ncl-talk <<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">


















<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt"><span style="font-family:"times new roman",serif"><span style="font-size:11pt;color:black"><font size="2">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:</font><br></span></span></p><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-family:"Times New Roman",serif"><font size="1"><span style="font-family:Menlo;color:black">warning:_NclOpenFile: Can not open file
<NARR3D_201811_0103.subset>; file format
not supported or file is corrupted</span></font></p><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-family:"Times New Roman",serif"><font size="2">Despite this warning, the function isfile returns true. Later when I try to access a variable in the file I get these errors:</font><br></p><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-family:"Times New Roman",serif"><font size="1"><span style="font-family:Menlo;color:black"><span></span></span></font></p><font size="1">

</font><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-family:"Times New Roman",serif"><font size="1"><span style="font-family:Menlo;color:black">fatal:file (g3d) isn't defined<span></span></span></font></p><font size="1">

</font><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Times New Roman",serif"><span style="font-size:11pt;font-family:Menlo;color:black"><font size="1">fatal:["Execute.c":8637]:Execute: Error
occurred at or near line 35 in file read3D.ncl</font></span></p><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Times New Roman",serif"><font size="2">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?</font></p><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Times New Roman",serif"><font size="2">Thanks,</font></p><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:"Times New Roman",serif"><font size="2">Jennifer</font></p></div></blockquote></div></div>
</blockquote></div>