<div dir="ltr"><div>Tabish, David:</div><div><br></div><div>I see David has already replied regarding string references and file variables. Another thought I was working on was to use Lists. It's probably overkill for your example; something like:</div><div><br></div><div>l = NewList("fifo")<br><br>ListPush(l, ispan(0,1000,1))<br>ListPush(l, ispan(1000,2000,1))<br>ListPush(l, ispan(2000,3000,1))<br><br>numl = ListCount(l)<br>do i = 1,numl<br> var := ListPop(l)<br> M = max(var)<br> m = min(var)<br> print(M+" "+m)<br>end do</div><div><br></div><div>Rick</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jan 26, 2023 at 7:15 AM Dave Allured - NOAA Affiliate via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu">ncl-talk@mailman.ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Tabish, for your example, you could use a simple array instead of individually named variables.<br><br>y = new (20, integer)<br>y(1) = ispan(0,1000,1)<br>y(2) = ispan(1000,2000,1)<br>y(3) = ispan(2000,3000,1)</div><div>--- etc. ---<br><br>do i = 1,19<br> M = max(y(i))<br> m = min(y(i))<br>--- etc. ---</div><div><br></div><div>Note that NCL uses zero-based arrays, so this example ignores y(0) to keep your original indexing scheme from 1 to 19.</div><div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jan 26, 2023 at 9:09 AM Dave Allured - NOAA Affiliate <<a href="mailto:dave.allured@noaa.gov" target="_blank">dave.allured@noaa.gov</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Tabish, NCL string references work for file variables, but not for in-memory variables. See NCL reference manual, section "String references".</div><div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jan 26, 2023 at 8:46 AM Tabish Ansari via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank">ncl-talk@mailman.ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div style="font-family:"trebuchet ms",sans-serif">Hi</div><div style="font-family:"trebuchet ms",sans-serif"><br></div><div style="font-family:"trebuchet ms",sans-serif">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.</div><div style="font-family:"trebuchet ms",sans-serif"><br></div><div style="font-family:"trebuchet ms",sans-serif">Here's my code:</div><div style="font-family:"trebuchet ms",sans-serif"><br></div><div style="font-family:"trebuchet ms",sans-serif">begin</div><div style="font-family:"trebuchet ms",sans-serif">y1 = ispan(0,1000,1)<br>y2 = ispan(1000,2000,1)<br>y3 = ispan(2000,3000,1)<br>y4 = ispan(3000,4000,1)<br>y5 = ispan(4000,5000,1)<br>y6 = ispan(5000,6000,1)<br>y7 = ispan(6000,7000,1)<br>y8 = ispan(7000,8000,1)<br>y9 = ispan(8000,9000,1)<br>y10 = ispan(9000,10000,1)<br>y11 = ispan(10000,11000,1)<br>y12 = ispan(11000,12000,1)<br>y13 = ispan(12000,13000,1)<br>y14 = ispan(13000,14000,1)<br>y15 = ispan(14000,15000,1)<br>y16 = ispan(15000,16000,1)<br>y17 = ispan(16000,17000,1)<br>y18 = ispan(17000,18000,1)<br>y19 = ispan(18000,19000,1)<br><br>do i = 1,19<br> var = "y"+tostring(i)<br> M = max($var$)<br> m = min($var$)<br> print(M+" "+m)<br>end do<br></div><div style="font-family:"trebuchet ms",sans-serif"><br></div><div style="font-family:"trebuchet ms",sans-serif">end</div><div style="font-family:"trebuchet ms",sans-serif"><br></div><div style="font-family:"trebuchet ms",sans-serif">I get a syntax error with this. Is it possible to achieve the same thing through some other syntax in an efficient way?</div><div style="font-family:"trebuchet ms",sans-serif"><br></div><div style="font-family:"trebuchet ms",sans-serif">Thanks a lot.</div><div style="font-family:"trebuchet ms",sans-serif"><br></div><div style="font-family:"trebuchet ms",sans-serif">Tabish</div><div style="font-family:"trebuchet ms",sans-serif"><br></div><div style="font-family:"trebuchet ms",sans-serif"><br></div><div><div dir="ltr"><div dir="ltr"><div><font face="trebuchet ms, sans-serif" color="#666666">-------------------------------<br><span style="background-color:rgb(255,255,255)">Dr Tabish Ansari</span></font></div><div><font face="trebuchet ms, sans-serif" color="#666666">Research Associate </font></div><div><font face="trebuchet ms, sans-serif" color="#666666">Air Quality Modelling Group</font></div><div><span style="background-color:rgb(255,255,255)"><span style="font-weight:normal"><font face="trebuchet ms, sans-serif" color="#666666">IASS-Potsdam </font></span></span></div><div><font face="trebuchet ms, sans-serif" color="#666666">Germany</font></div></div></div></div></div>
</blockquote></div></div>
</blockquote></div></div>
_______________________________________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank">ncl-talk@mailman.ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="https://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">https://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
</blockquote></div>