<div dir="ltr"><div class="gmail_default" style="font-size:small">AR,</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">You can't do dynamic variables the way you've written it, but there may be a way to do what you want, if I could know more about what you need to do with such a variable. The special "$...$" type of syntax can be used when referencing file variables, both reading and writing.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">For example, if you need to write the results of stat_dispersion to a NetCDF file, then you might do something like:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small"><div class="gmail_default"><font face="monospace, monospace">;------------------------------------------------------</font></div><div class="gmail_default"><font face="monospace, monospace">; OPEN NEW NETCDF FOR WRITING</font></div><div class="gmail_default"><font face="monospace, monospace">;------------------------------------------------------</font></div></div><div class="gmail_default" style="font-size:small"> <font face="monospace, monospace">output_filename = "<a href="http://test.nc">test.nc</a>"</font></div><div class="gmail_default" style="font-size:small"><font face="monospace, monospace"> system("rm -rf " + output_filename)</font></div><div class="gmail_default" style="font-size:small"><font face="monospace, monospace"> fout = addfile(output_filename,"c")</font></div><div class="gmail_default" style="font-size:small"><font face="monospace, monospace"><br></font></div><div class="gmail_default" style=""><div class="gmail_default" style=""><font face="monospace, monospace">;------------------------------------------------------</font></div><div class="gmail_default" style=""><font face="monospace, monospace">; STAT DISPERSION</font></div><div class="gmail_default" style=""><font face="monospace, monospace">;------------------------------------------------------</font></div><div class="gmail_default" style=""><font face="monospace, monospace"> opt = True</font></div><div class="gmail_default" style=""><font face="monospace, monospace"> opt@PrintStat = True</font></div><div class="gmail_default" style=""><font face="monospace, monospace"><br></font></div><div class="gmail_default" style=""><font face="monospace, monospace"> vars = (/"SNOWFALL","SNOWC","SWE","TSA"/)</font></div><div class="gmail_default" style=""><font face="monospace, monospace"> elev = (/"500","1000","1500","2000"/)</font></div><div class="gmail_default" style=""><font face="monospace, monospace"> nvars = dimsizes(vars)-1</font></div><div class="gmail_default" style=""><font face="monospace, monospace"> nelev = dimsizes(elev)-1</font></div><div class="gmail_default" style=""><font face="monospace, monospace"><br></font></div><div class="gmail_default" style=""><font face="monospace, monospace"> do n=0,nvars</font></div><div class="gmail_default" style=""><font face="monospace, monospace"> do k=0,nelev</font></div><div class="gmail_default" style=""><font face="monospace, monospace"> varname = "</font><span style="font-family:monospace,monospace">Sierra_STAT_VR_CESM_28_HIST_"</span><span style="font-family:monospace,monospace">+vars(n)+elev(k)</span></div><div class="gmail_default" style=""><font face="monospace, monospace"> print("VR-CESM28 - HISTORICAL - AVG DJF Sierra Nevada "+elev(k)+" "+vars(n)+"")</font></div><div class="gmail_default" style=""><font face="monospace, monospace"><br></font></div><div class="gmail_default" style=""><font face="monospace, monospace">;---Write calculation directly to NetCDF file</font></div><div class="gmail_default" style=""><font face="monospace, monospace"> fout->$varname$ = stat_dispersion(oned_+vars(n)+_VR_CESM_28_HIST_+elev(k)+,opt)</font></div><div class="gmail_default" style=""><font face="monospace, monospace"><br></font></div><div class="gmail_default" style=""><font face="monospace, monospace"> end do</font></div><div class="gmail_default" style=""><font face="monospace, monospace"> end do</font></div><div class="gmail_default" style=""><font face="arial, helvetica, sans-serif"><br></font></div><div class="gmail_default" style=""><font face="arial, helvetica, sans-serif">Note that this is a very inefficient way to write a NetCDF file. Mostly I just want to show how to use the $...$ syntax.</font></div><div class="gmail_default" style=""><font face="arial, helvetica, sans-serif"><br></font></div><div class="gmail_default" style=""><font face="arial, helvetica, sans-serif">If this doesn't answer your question, please post back to ncl-talk.</font></div><div class="gmail_default" style=""><font face="arial, helvetica, sans-serif"><br></font></div><div class="gmail_default" style=""><font face="arial, helvetica, sans-serif">--Mary</font></div><div class="gmail_default" style=""><font face="arial, helvetica, sans-serif"><br></font></div></div><div class="gmail_default" style="font-size:small"><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 20, 2015 at 12:33 PM, Alan Rhoades <span dir="ltr"><<a href="mailto:alan.m.rhoades@gmail.com" target="_blank">alan.m.rhoades@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hello,</div><div><br></div><div>I'm currently trying to make dynamic variable names within NCL (i.e., with unique prefix and/or suffix, but consistent patterns for each variable). I've tried to track down a solution for my current problem via the NCL archives, but can't seem to find it. A post in 2010 said that this type of NCL scripting wasn't yet possible, but I was curious if an update had occurred. </div><div><br></div><div><div>I'm trying to do the following...</div><div><br></div><div>Assess several different mountain ranges</div><div>With four different variables (SNOWFALL, SNOWC, SWE, TSA)</div><div>Across four different elevation classes (500 m, 1000 m, 1500 m, 2000 m)</div><div><br></div><div>This is my current stab at making the dynamic variable names within NCL, but of course, it isn't working (although the print statement is working, the NCL functions just don't like the syntax used to name the dynamic variable names). Here is a snippet of the code...</div></div><div><br></div><div>;------------------------------------------------------</div><div>; STAT DISPERSION</div><div>;------------------------------------------------------</div><div> opt = True</div><div> opt@PrintStat = True</div><div><br></div><div> vars = (/"SNOWFALL","SNOWC","SWE","TSA"/)</div><div> elev = (/"500","1000","1500","2000"/)</div><div> nvars = dimsizes(vars)-1</div><div> nelev = dimsizes(elev)-1</div><div><br></div><div> do n=0,nvars</div><div> do k=0,nelev</div><div> print("VR-CESM28 - HISTORICAL - AVG DJF Sierra Nevada "+elev(k)+" "+vars(n)+"")</div><div> Sierra_STAT_VR_CESM_28_HIST_+vars(n)+elev(k)+ = stat_dispersion(oned_+vars(n)+_VR_CESM_28_HIST_+elev(k)+,opt)</div><div><br></div><div> end do</div><div> end do</div><div><br></div><div>Do you have any advice on how to move forward on this? I have heard that it is possible to read in variable names via a shell script into NCL, but I can't track down an example of how to do this either.</div><div><br></div><div>Thanks in advance,</div><div><br></div><div>AR</div><span class="HOEnZb"><font color="#888888"><div><br></div>-- <br><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><font color="#006600"><div style="font-weight:bold"><br></div><div><font color="#006600" size="2"><b>Alan Rhoades</b></font></div></font><div><div><b><font color="#000000" size="1">PhD Student, Atmospheric Science Graduate Group</font></b></div><div><b><font color="#000000" size="1">Climate Change Water and Society (CCWAS) NSF IGERT Trainee</font></b></div><div><b><font color="#000000" size="1">University of California, Davis</font></b></div><div><span style="font-family:arial,sans-serif;background-color:rgb(255,255,255)"><u><b><a href="https://www.linkedin.com/pub/alan-rhoades/22/5bb/52a" target="_blank"><font color="#0000ff" size="1">LinkedIn</font></a></b></u></span></div><div><span style="font-family:arial,sans-serif;background-color:rgb(255,255,255)"><u><b><font size="1"><a href="mailto:alan.m.rhoades@gmail.com" target="_blank">alan.m.rhoades@gmail.com</a> </font></b></u></span></div><div><span style="font-family:arial,sans-serif;background-color:rgb(255,255,255)"><u><b><a href="mailto:amrhoades@ucdavis.edu" target="_blank"><font size="1">amrhoades@ucdavis.edu</font></a></b></u></span></div></div><div><font color="#003300" size="1"><b><br></b></font></div><div><b><i><font color="#006600" size="1">"It’s all really there. That’s what really gets you. But you gotta stop and think about it to really get the pleasure about the complexity, the inconceivable nature of nature."</font></i></b></div><div><b><i><font color="#006600" size="1">Richard Feynman</font></i></b></div></div></div></div></div></div></div>
</font></span></div>
<br>_______________________________________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>