[ncl-talk] converting string into a variable name

Tabish Ansari tabishumaransari at gmail.com
Thu Jan 26 06:45:51 MST 2023


Hi

I have several systematically named variables that I want to refer to by
generating the corresponding string via a loop. I'm able to generate a
string that exactly matches the variable name but I'm unable to perform any
operations over the variables by referring to the string.

Here's my code:

begin
y1 = ispan(0,1000,1)
y2 = ispan(1000,2000,1)
y3 = ispan(2000,3000,1)
y4 = ispan(3000,4000,1)
y5 = ispan(4000,5000,1)
y6 = ispan(5000,6000,1)
y7 = ispan(6000,7000,1)
y8 = ispan(7000,8000,1)
y9 = ispan(8000,9000,1)
y10 = ispan(9000,10000,1)
y11 = ispan(10000,11000,1)
y12 = ispan(11000,12000,1)
y13 = ispan(12000,13000,1)
y14 = ispan(13000,14000,1)
y15 = ispan(14000,15000,1)
y16 = ispan(15000,16000,1)
y17 = ispan(16000,17000,1)
y18 = ispan(17000,18000,1)
y19 = ispan(18000,19000,1)

do i = 1,19
 var = "y"+tostring(i)
 M = max($var$)
 m = min($var$)
 print(M+"       "+m)
end do

end

I get a syntax error with this. Is it possible to achieve the same thing
through some other syntax in an efficient way?

Thanks a lot.

Tabish


-------------------------------
Dr Tabish Ansari
Research Associate
Air Quality Modelling Group
IASS-Potsdam
Germany
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20230126/1ad61f8c/attachment.htm>


More information about the ncl-talk mailing list