[ncl-talk] Looping through strings to build new variable names

Alan Brammer abrammer at albany.edu
Fri Jan 30 07:52:56 MST 2015


Mike,

You may be better looking into the list functionality.   Take a look at the
ncl-talk email from k griffin a few days back, and the echo function that
was posted.  You could push the variable into a list and add the station
name to it as well.   Then retrieve it back out of the list based on the
station name.

The other way would be rather than having new variables, add the data as an
attribute to another variable.

alldata = True
alldata@$station+"_MaxT"$ = new((/dimsizes(dates(i*k:i*k+i))/), "float")

however you can't have attributes on attributes so not all of that would be
transferable.

Why do you want uniquely and logically named variables inside the code?

Good luck buddy.




On Thu, Jan 29, 2015 at 10:48 AM, Michael Ventrice <mventrice at wsi.com>
wrote:

>
> Hi all,
>
> Is it possible to call in a string from an array in order to build a new
> variable name using part of the string that was called in? I put a mock
> example at the bottom that I'd think would be a way to do it... but
> obviously it doesn't work :)
>
> Thanks in advance,
> Mike V.
>
>
>
>   statID_array = (/"KALB","KLGA"/)
>
>
> do i = 0, dimsizes(statID_array)-1
> station = statID(i)
>
>   k = 294
>
>   station+"_MaxT" = new((/dimsizes(dates(i*k:i*k+i))/), "float")
>   station+"_MaxT"!0 = "time"
>   station+"_MaxT"&time = dates(i*k:i*k+i)
>   station+"_MaxT"&time at units = dates at units
>   station+"_MaxT" = (/maxT(i*k:i*k+i)/)
>
> end do
>
> ;-----------------------------
> ; for i=0:
> ;KALB_MaxT = new((/dimsizes(dates(i*k:i*k+i))/), "float")
> ;KALB_MaxT!0 = "time"
> ;KALB_MaxT&time = dates(i*k:i*k+i)
> ;KALB_MaxT&time at units = dates at units
> ;KALB__MaxT" = (/maxT(i*k:i*k+i)/)
>
> ; for i=1:
> ;KLGA_MaxT = new((/dimsizes(dates(i*k:i*k+i))/), "float")
> ;KLGA_MaxT!0 = "time"
> ;KLGA_MaxT&time = dates(i*k:i*k+i)
> ;KLGA_MaxT&time at units = dates at units
> ;KLGA__MaxT" = (/maxT(i*k:i*k+i)/)
>
>
> etc...
>
> --
> * Michael **Ventrice, Ph.D.  **|* *Operational Scientist*
> * w:* 978-983-6786      *e:* michael.ventrice at weather.com
>
>
> _______________________________________________
> 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/20150130/976177e3/attachment.html 


More information about the ncl-talk mailing list