Re: dynamic variable names

From: Jonathan Vigh <jvigh_at_nyahnyahspammersnyahnyah>
Date: Wed Feb 09 2011 - 10:16:47 MST

Hi Hannah,
     You can attach a variety of attribute arrays to one data object, in
effect creating dynamic variables:

DATA = True

do i = 0, imax-1
<get time data>
<read in new data or whatever, store it as "newdata">
    array_name = <time>.imax
    DATA@$array_name$ = newdata
end do

So all your dynamic arrays would live on the DATA object and could be
retrieved or destroyed later. They would not all have to have the same
dimensions, types, and can be named whatever you want. Advantages are
that this is a handy quick way to read in lots of data with different
dimensions, and NCL currently doesn't have a way to dynamically create
and work with variables without knowing their names in advance.
Disadvantages of this method are that you can't attach additional
attributes to the attribute arrays, so things like _FillValue might have
to be added explicitly later on. Another disadvantage is that processing
could get exponentially slower for certain operations if the total
number of attached elements becomes too large (maybe a million, or a
hundred million?). And finally, to store all the dynamic variables as a
netCDF file, you'd need to basically unpack the attribute arrays into
real variables, add the dimensions, _FillValues, etc. It's possible
using NCL to write it's own NCL code dynamically, but it's not pretty.
Things would get a lot easier if NCL had an "eval" statement.


On 02/09/2011 10:01 AM, Nissan, Hannah wrote:
> Hello,
> I am looking for a way to dynamically name an array in NCL. I am
> running a loop through time and creating an array which I need to name
> according to the time period or loop. Can anyone help?
> Thanks very much,
> Hannah
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:

Jonathan Vigh	
Postdoctoral Fellow, Advanced Study Program
National Center for Atmospheric Research
Mesoscale&  Microscale Meteorology Division
Foothills Lab 3 - Rm. 3081
Office: 303-497-8205
Cell:   720-347-9337

ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
Received on Wed Feb 9 10:17:02 2011

This archive was generated by hypermail 2.1.8 : Fri Feb 11 2011 - 16:11:42 MST