[ncl-talk] Fatal error with running plotgrids_new.ncl

Mary Haley haley at ucar.edu
Mon Aug 11 09:00:02 MDT 2014


Ashwin,

I'm posting this back to ncl-talk so they know there was a resolution to
this problem, and also because I think people will be interested in your
error handling question.

I have to be honest and say that NCL doesn't have the best error handling,
but it does provide quite a few "query" functions to try to catch things
that might be an issue.

For example, in the case of your issue with all missing values, you could
have caught this issue before calling gsn_polyxxxx by using a combination
of the "all" and "ismissing" functions:

  if(all(ismissing(x)).or.all(ismissing(y))) then
     print("Error encountered, either x and/or y is all missing")
  else
     gsn_polyxxxx(wks,plot,x,y,res)
  end if

The URL you pointed to is a bit old, but I believe it could still apply.
The basic gist is that if you write your own NCL function to calculate
something, then you can add your own error checking by creating, say, an
"error" attribute that will allow the code that's calling this function to
know whether the function was successful.

For example, if the above code was going to be put in a function, then you
can create your own "error" attribute and attach it to the return value:

; Assume "ret" is the return value for this function
  if(all(ismissing(x)).or.all(ismissing(y))) then
     print("Error encountered, either x and/or y is all missing")
     ret at error = 1   ; Anything not equal to 0 implies an error
  else
     gsn_polyxxxx(wks,plot,x,y,res)
     ret at error = 0
  end if

If you have a procedure instead, then you can attach "error" as an
attribute of one of the input arguments, but this is a bit kludgy.

In general, to catch errors:

   - Use "if statements" along with the "any", "all", and "ismissing"
   functions to catch "bad" data before you call a function.

   - Use "isnan_ieee" and "replace_ieeenan" to catch and fix NaNs in your
   data ("ismissing" won't work on these).

   - Use "isfilepresent" to test for a valid supported file before trying
   to open it with "addfile".

   - Use "typeof" or one of the "isxxxx" (isfloat, isdouble, etc) functions
   if you need to check the type of a variable before passing it to a function
   that might be strict about the type of variable being passed to it.

   - Use "dimsizes" to check the dimension sizes and/or rank of a variable
   before passing it to a function.

   - Use "isatt" to check for the presence of a required attribute, like
   "units" before calling a routine that might expect data to come in with a
   particular units, like "mb".

This is a good question, and I'll try to see that this information gets
added somewhere in our documentation. We have plans to overhaul the very
old "Getting Started Using NCL" document, and this would be a good
candidate for that.

--Mary



On Sun, Aug 10, 2014 at 4:33 AM, ashwinD12 . <winash12 at gmail.com> wrote:

> Thanks Mary for your response. As soon as I printed out what the values
> were  I knew where I went wrong.
>
> As a general NCL question - what are best practices for error handling
> other than printVarSummary(); ?
>
> Is this a template ?
>
> https://www.ncl.ucar.edu/Support/talk_archives/2006/0799.html
>
> Regards,
> Ashwin.
>
>
> On Sun, Aug 10, 2014 at 10:46 AM, Mary Haley <haley at ucar.edu> wrote:
>
>> Ashwin,
>>
>> You were correct to post this kind of question to ncl-talk and not
>> wrfhelp, because this is indeed an NCL error.
>>
>> The error is coming out of some internal code that attaches primitives to
>> a plot, like polylines, polygons, or polymarkers.  From what I can see from
>> the internal code, it looks like you might be passing an array of all
>> missing values to a routine like gsn_polyline, gsn_polymarker, or similar.
>>
>> What is on line 200 of your util/plotgrids_new.ncl file?  If it is a call
>> to one of these routines, then I suggest that you print out the x and y
>> arrays that you are passing to it to make sure they are valid values.
>>
>> --Mary
>>
>>
>>
>> On Fri, Aug 8, 2014 at 6:02 AM, ashwinD12 . <winash12 at gmail.com> wrote:
>>
>>>  Hello,
>>>            Although this is a file you encounter in WRF it is still a
>>> NCL error so I thought I would post here first.
>>>
>>> NCL version is 6.2.0. I used the following binary
>>> ncl_ncarg-6.2.0.Linux_Debian7.4_x86_64_nodap_gcc472.tar
>>>
>>> I get this error when I type ncl util/plotgrids_new.ncl
>>> fatal:Subscript out of range, error in subscript #0
>>>  fatal:An error occurred reading xf
>>>  fatal:["Execute.c":8567]:Execute: Error occurred at or near line 4363
>>> in file $NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl
>>>
>>>  fatal:["Execute.c":8567]:Execute: Error occurred at or near line 4578
>>> in file $NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl
>>>
>>> fatal:["Execute.c":8567]:Execute: Error occurred at or near line 200 in
>>> file util/plotgrids_new.ncl
>>>
>>> I also tried with the plotgrids_old.ncl and got similar errors.
>>>
>>> There was a posting on a earlier message related to the setting of the
>>> DISPLAY variable. When I unset that I get OS related errors.
>>>
>>> Any suggestions would be appreciated.
>>> Regards,
>>> Ashwin.
>>>
>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> 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/20140811/186613b2/attachment.html 


More information about the ncl-talk mailing list