String reference to variable

From: Daniel Adriaansen <dadriaan_at_nyahnyahspammersnyahnyah>
Date: Mon Mar 12 2012 - 13:34:57 MDT

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:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Mar 12 09:35:11 2012

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