Re: dynamic variable names

From: Adam Phillips <asphilli_at_nyahnyahspammersnyahnyah>
Date: Wed Feb 09 2011 - 10:22:45 MST

Hi Hannah,
Jonathan's idea to write dynamic names as attributes is a great one. One
other possible way to get around this:

You can dynamically name arrays to be written to a netCDF file:
do gg = 0,1
    ......................
    if (gg.eq.0) then
       a = addfile("file."+time+".nc","c")
       a@source = systemfunc("pwd")+"/"+get_script_name()
    end if
    vname = "SLP_"+time
    a->$vname$ = arr
    delete(arr)
end do

On 02/09/2011 10:16 AM, Jonathan Vigh wrote:
> 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.
>
> Jonathan
>
>
>
>
>
>
> 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:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
> --
> ------------------------------------------------------
> 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:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

-- 
__________________________________________________
Adam Phillips 
asphilli@ucar.edu
National Center for Atmospheric Research   tel: (303) 497-1726
Climate and Global Dynamics Division         fax: (303) 497-1333
P.O. Box 3000				
Boulder, CO 80307-3000    http://www.cgd.ucar.edu/cas/asphilli
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Feb 9 10:22:50 2011

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