[ncl-talk] dynamic variable names
Rick Brownrigg
brownrig at ucar.edu
Thu Feb 4 05:43:45 MST 2016
Hi Sebastian,
As you point out, it can't be done directly with variables and $..$
notation. But it would work if your variables were made to be attributes
of some "hosting variable":
ncl 0> hostVar = True
ncl 1> hostVar at ALLindex = 3.14159
ncl 2> user_selection = "ALL"
ncl 3> dynvar = user_selection + "index"
ncl 4> var1 = hostVar@$dynvar$
ncl 5> print(var1)
Variable: var1
Type: float
Total Size: 4 bytes
1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
(0) 3.14159
I hope that helps...
Rick
On Thu, Feb 4, 2016 at 3:30 AM, Milinski, Sebastian <
sebastian.milinski at mpimet.mpg.de> wrote:
> Hi,
>
> I would like to access a variable. The name of the variable to be accessed
> is created from user input (string) and a suffix (string)
>
> user_selection = "ALL"
> dynvar = user_selection + "index"
> var1 = dynvar ;
> <- here I do not want the string ALLindex but the content of ALLindex.
> print(var1)
>
>
> The syntax var1 = $dynvar$ does not work. Is there an easy way to do this
> without several if-statements?
>
> Thanks,
> Sebastian
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> 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/20160204/65abd342/attachment.html
More information about the ncl-talk
mailing list