Re: How can I do such a manipulation in NCL?

From: Cheung <zuibeidemei_at_nyahnyahspammersnyahnyah>
Date: Tue Nov 26 2013 - 18:59:14 MST

Thanks, brilliant!

At 2013-11-27 00:54:12,"Rick Brownrigg" <brownrig@ucar.edu> wrote:
Hi,

Maybe not as directly as the python example. But depending on your application-needs, perhaps the following might work. You could create a variable "global" and then attach your "variables" as "attributes" to it; the attributes can then be referenced indirectly using "string references". So something like:

global = True
global@one = 0
global@two = 0
global@three = 0
print(global)

varNames = (/ "one", "two", "three" /)

count = 1
do i=0, dimsizes(varNames)-1
  global@$varNames(i)$ = count
  count = count + 1
end do

print(global)

Hope that helpsĄ­
Rick

On Nov 26, 2013, at 4:29 AM, Cheung <zuibeidemei@126.com> wrote:

 Dear all:
 I need all variables' names be stored in an array, then I loop the array to insert the value for each var.
 More specifically, like what the following python code can do:
 Can anyone tell me if this could be done in NCL?

var_names = ["one", "two", "three"]
count = 1
for name in var_names:
        globals()[name] = count
        count += 1
print one
print two

_______________________________________________
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 Tue Nov 26 18:59:29 2013

This archive was generated by hypermail 2.1.8 : Wed Dec 04 2013 - 20:42:38 MST