<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Rick,<div class=""><br class=""></div><div class="">That helped a lot, thank you!</div><div class=""><br class=""></div><div class="">Sebastian</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div><blockquote type="cite" class=""><div class="">On 04 Feb 2016, at 13:43, Rick Brownrigg <<a href="mailto:brownrig@ucar.edu" class="">brownrig@ucar.edu</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class=""><div class=""><div class="">Hi Sebastian,<br class=""><br class=""></div>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":<br class=""><br class="">ncl 0> hostVar = True<br class="">ncl 1> hostVar@ALLindex = 3.14159<br class="">ncl 2> user_selection = "ALL"<br class="">ncl 3> dynvar = user_selection + "index"<br class="">ncl 4> var1 = hostVar@$dynvar$<br class="">ncl 5> print(var1)<br class=""><br class="">Variable: var1<br class="">Type: float<br class="">Total Size: 4 bytes<br class=""> 1 values<br class="">Number of Dimensions: 1<br class="">Dimensions and sizes: [1]<br class="">Coordinates:<br class="">(0) 3.14159<br class=""><br class=""></div>I hope that helps...<br class=""></div>Rick<br class=""><br class=""></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Thu, Feb 4, 2016 at 3:30 AM, Milinski, Sebastian <span dir="ltr" class=""><<a href="mailto:sebastian.milinski@mpimet.mpg.de" target="_blank" class="">sebastian.milinski@mpimet.mpg.de</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br class="">
<br class="">
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)<br class="">
<br class="">
user_selection = "ALL"<br class="">
dynvar = user_selection + "index"<br class="">
var1 = dynvar ; <- here I do not want the string ALLindex but the content of ALLindex.<br class="">
print(var1)<br class="">
<br class="">
<br class="">
The syntax var1 = $dynvar$ does not work. Is there an easy way to do this without several if-statements?<br class="">
<br class="">
Thanks,<br class="">
Sebastian<br class="">
<br class="">
<br class="">_______________________________________________<br class="">
ncl-talk mailing list<br class="">
<a href="mailto:ncl-talk@ucar.edu" class="">ncl-talk@ucar.edu</a><br class="">
List instructions, subscriber options, unsubscribe:<br class="">
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank" class="">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br class="">
<br class=""></blockquote></div><br class=""></div>
_______________________________________________<br class="">ncl-talk mailing list<br class=""><a href="mailto:ncl-talk@ucar.edu" class="">ncl-talk@ucar.edu</a><br class="">List instructions, subscriber options, unsubscribe:<br class="">http://mailman.ucar.edu/mailman/listinfo/ncl-talk<br class=""></div></blockquote></div><br class=""></div></body></html>