Re: String reference to variable

From: David Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Mon Mar 12 2012 - 14:18:26 MDT

Hi Daniel,
If you are using NCL 6.0.0, you can use the list type:

varlist = [/ a, b, c /]
do i = 0, ListCount(varlist) -1
    plot = plot_function(varlist[i])
end do

Note this capability is still experimental in 6.0.0. The ListCount function is not documented yet. List elements appear in the opposite order from the written order in the literal list definition. This is fixed in 6.1.0. Note the square brackets instead of parentheses.

On Mar 12, 2012, at 1:34 PM, Daniel Adriaansen wrote:

> Hello,
> I have a question that I've been unable to answer myself. I wrote a
> script where I have calculated several variables, lets call them a, b,
> and c. I wish to make a contour plot of a, b, and c but prefer to do it
> in a loop instead of writing out the code three separate times. (For
> this simple example there are only three variables, when in reality I
> have many more than that in my application). I am attempting to do the
> following:
> (1) varlist = (/"a","b","c"/)
> (2) do i=0,dimsizes(varlist)-1,1
> (3) currvar = varlist(i)
> (4) plot = contour(currvar)
> (5) delete([/"currvar","plot"/])
> (6) end do
> After some investigating, it looks like the code is doing exactly what
> I'm telling it to- plot the variable currvar which is of type string.
> The problem is, I don't want to contour the string, I want to contour
> the actual variable varlist(i). I am familiar with the fin->$varlist(i)$
> syntax when reading variables from a file, but I tried something similar
> with no luck. I also found some old ncl-talk archives about attaching
> attributes and then referencing them in a loop but I'm not certain how
> that applies here. I would greatly appreciate any tips that anyone might
> have. Thanks in advance.
> -Dan
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:

ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
Received on Mon Mar 12 10:18:34 2012

This archive was generated by hypermail 2.1.8 : Tue Mar 13 2012 - 14:00:14 MDT