[ncl-talk] An "2d" Attribute Array Conundrum

Philippe Papin ppapin at albany.edu
Wed May 13 15:01:26 MDT 2015


Hi David,

Thanks for the detailed reply and suggestions. I can easily assign the
attribute values to a local variable! Also good to know that 2d arrays are
allowed in attributes even if the are not fully supported!

Have a great day!
-Philippe

On Wed, May 13, 2015 at 2:17 PM, David Brown <dbrown at ucar.edu> wrote:

> Hi Phillipe,
> That's a good question. Actually the error message, as you discovered,
> is a bit misleading. NCL was originally designed to only allow 1D
> attributes in keeping with the NetCDF data model. Later, however, when
> we needed the ability to transmit 2D coordinate information to the
> graphics routines (mainly), we loosened the restriction to allow NCL
> variables to have multi-d attributes as a convenience. However, as you
> have found, we did not implement full support for this feature. Partly
> this is because you cannot write such an attribute to any of the
> output file formats we support -- so it can never be truly integrated
> into the data model.
> Practically speaking, if you wanted to have a routine that handles
> subscripting of 2D attributes, I'm guessing you could do it by
> assigning the attribute value to a local variable, subscripting the
> variable, and using the 'reassign' syntax to give the attribute its
> new subscripted value.
> We will try to make the error message a little more informative.
> Eventually maybe we can make subscripting work in this situation.
>  -dave
>
> On Wed, May 13, 2015 at 10:56 AM, Philippe Papin <ppapin at albany.edu>
> wrote:
> > Hi NCL-talk,
> >
> > I came across a strange conundrum today when testing some code. I use
> > attributes in my code to send 1d variables through attributes into
> > subroutines without explicitly defining it in the new subroutine. This
> > practice is limited to 1d arrays since attributes in theory can only be
> 1d.
> > However, if this is the case, why can you "create" a 2d attribute array
> and
> > then print this attribute array without error?
> >
> > Here is a code snippet of an example of what I am talking about. I'm
> using
> > NCL version 6.2.1
> >
> > opt = True
> > array2d = (/ (/1,2,3/) , (/4,5,6/) /)
> > opt at array2d = array2d
> > print(opt at array2d) ;;; output below seem to print out array correctly
> in 2d
> >
> > (0,0) 1
> >
> > (0,1) 2
> >
> > (0,2) 3
> >
> > (1,0) 4
> >
> > (1,1) 5
> >
> > (1,2) 6
> >
> > However if you try to actually subscript the data, you get an error
> message
> > that attributes only have one dimension.
> >
> > subarray2d = opt at array2d(0,1)
> >
> > fatal:Attributes only have one dimension, 2 subscripts used
> >
> > fatal:["Execute.c":8576]:Execute: Error occurred at or near line 6
> >
> > This is a bit counterintuitive to me. Perhaps the 2d attribute array I
> > created is really 1d, but just gives the appearance of a 2d array when
> > printed. Sorry if this is a trivial question, but hopefully that means it
> > won't take much to figure out what is going on here.
> >
> > Thanks for any additional information!
> >
> > -Philippe
> >
> >
> > --
> > -------------------------------------
> > Philippe P. Papin
> > Dept. of Atmospheric and Environmental Sciences
> > University at Albany, SUNY
> > 1400 Washington Ave, Albany, NY 12222
> > http://www.atmos.albany.edu/student/ppapin/
> >
> > _______________________________________________
> > ncl-talk mailing list
> > List instructions, subscriber options, unsubscribe:
> > http://mailman.ucar.edu/mailman/listinfo/ncl-talk
> >
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>



-- 
-------------------------------------
Philippe P. Papin
Dept. of Atmospheric and Environmental Sciences
University at Albany, SUNY
1400 Washington Ave, Albany, NY 12222
http://www.atmos.albany.edu/student/ppapin/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150513/8d8e676a/attachment.html 


More information about the ncl-talk mailing list