Re: String reference to variable

From: David Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Mon Mar 12 2012 - 15:28:14 MDT

Hi Dan,
I don't think we have such a function currently. It's a good idea though.
 -dave

On Mar 12, 2012, at 3:22 PM, Daniel Adriaansen wrote:

> Hi Dave,
>
> That does exactly what I need. One additional question for you-
>
> Say I'd like each of the variables to plot in a separate figure, so that
> inside the loop I will also call gsn_open_wks(). When I do that, I'd
> like to supply the current variable name as the workstation name. Is
> there an undocumented function such as ListCount that extracts just the
> variable name and not the value stored in the variable from the list?
> For example, I'd like the following:
>
> imgname = tostring(varlist(i))
> wks = gsn_open_wks("png",imgname)
>
> but now varlist(i) only works for i=0 (no big deal, I can control this),
> but I don't know how to access the variable name. I somehow need to
> "unlist" the list you just helped me create! I think I might be asking
> too much...
>
> -Dan
>
> On 03/12/2012 02:18 PM, David Brown wrote:
>> 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.
>> -dave
>>
>>
>> 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:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Mar 12 11:28:24 2012

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