[ncl-talk] dynamic variable names

Milinski, Sebastian sebastian.milinski at mpimet.mpg.de
Thu Feb 4 07:59:28 MST 2016


Hi Rick,

That helped a lot, thank you!

Sebastian


> On 04 Feb 2016, at 13:43, Rick Brownrigg <brownrig at ucar.edu> wrote:
> 
> 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 <mailto: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 <mailto:ncl-talk at ucar.edu>
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk <http://mailman.ucar.edu/mailman/listinfo/ncl-talk>
> 
> 
> _______________________________________________
> 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/c8fa50e7/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 842 bytes
Desc: Message signed with OpenPGP using GPGMail
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160204/c8fa50e7/attachment.bin 


More information about the ncl-talk mailing list