<div dir="ltr"><div>Try this:<br><br>do y=1,1000<br><br>if (y.lt.10) then<br>  year=&quot;000&quot;+y<br>else if (y.ge.10.and.y.lt.100)<br>  year=&quot;00&quot;+y<br>else if (y.ge.100.and.y.le.999)<br>  year=&quot;0&quot;+y<br>else<br>  year=y<br>end if<br>end if<br>end if<br><br>input=&quot;/dir/data&quot;+year+&quot;.nc&quot;<br>.<br>.<br>.<br><br>end do<br><br></div><div>Cheers,<br></div>Thomas<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jul 12, 2016 at 3:54 PM, Alexander Schaefer <span dir="ltr">&lt;<a href="mailto:aschae11@uncc.edu" target="_blank">aschae11@uncc.edu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Just use an If statement.<div><br></div><div>do t = 1,1<br><div><br></div><div>if (t .lt. 10) then </div><div>  <font face="Times New Roman">input=&quot;/dir/data.000”+t +”.nc”</font></div><div><font face="Times New Roman">else if (t .lt. 100) then</font></div><div><font face="Times New Roman">  input=&quot;/dir/data.00”+t +”.nc&quot;</font></div><div>else if (t .lt. 1000) then</div><div>   <font face="Times New Roman">input=&quot;/dir/data.0&quot;+t +”.nc”</font></div><div><font face="Times New Roman">else </font></div><div>  <font face="Times New Roman">input=&quot;/dir/data.” + t +”.nc&quot;</font></div><div>end if</div><div>end if</div><div>end if</div><div><br></div><div>file = addfile(input,”r”)</div><div><br></div><div>end do</div><div><br></div><div>I would set the filename in the if statements and load the file after them; all done within the loop</div><div><br></div><div>Other option is </div><div><br></div><div>ifiles = systemfunc( “ls /dir/data.*.nc”) ; This gets all of your data file names</div><div><br></div><div>nfiles = dimsizes(ifiles)</div><div><br></div><div>do t = 0, nfiles-1</div><div><br></div><div>  ifile = addfile(ifiles(t), “r”)</div><div>  </div><div> ; Now do your work</div><div><br></div><div>end do</div><div><br></div><div><br></div><div>the latter option is smoother but either should work for the purpose.</div><div><br></div><div>-Alex</div><div><br></div><div><br></div><div><br></div><div><br><div><blockquote type="cite"><div><div class="h5"><div>On Jul 12, 2016, at 9:44 AM, Kacie Shourd &lt;<a href="mailto:Kacie.Shourd@dri.edu" target="_blank">Kacie.Shourd@dri.edu</a>&gt; wrote:</div><br></div></div><div><div><div class="h5"><div style="font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;direction:ltr;font-family:Tahoma;font-size:10pt">Hi, Chang<div><br></div><div>I have yet to figure out how to loop through files in such a way using purely NCL. There is the &quot;addfiles&quot; function, but I don&#39;t believe that loops through files -- it just pulls in the variables from all files and I&#39;m not sure how to keep things separate. </div><div><br></div><div>I have handled this problem in the past by using a wrapper in an external language (Python, for example), and running things directly from the shell. Looping in other languages is much more straight forward (in my opinion), and shouldn&#39;t be too difficult to accomplish. <span style="font-size:10pt"> </span></div><div><span style="font-size:10pt"><br></span></div><div><span style="font-size:10pt">If you need assistance doing this, I would be happy to lend a hand/provide an example. </span></div><div><span style="font-size:10pt"><br></span></div><div><span style="font-size:10pt">Best,</span></div><div><span style="font-size:10pt">Kacie</span></div><div><span style="font-size:10pt"><br></span></div><div><span style="font-size:10pt">---</span></div><div><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif;background-color:white"><span style="font-size:10pt;font-family:&#39;Courier New&#39;">Kacie N. Shourd</span><span style="font-size:9.5pt;font-family:Arial,sans-serif;color:rgb(34,34,34)"></span></div><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif;background-color:white"><span style="font-size:10pt;font-family:&#39;Malgun Gothic&#39;,sans-serif">드림</span><span style="font-size:9.5pt;font-family:Arial,sans-serif;color:rgb(34,34,34)"></span></div><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif;background-color:white;background-position:initial initial;background-repeat:initial initial"><span style="font-size:9.5pt;font-family:Arial,sans-serif;color:rgb(34,34,34)"> </span></p><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif;background-color:white"><span style="font-size:10pt;font-family:&#39;Courier New&#39;;color:rgb(34,34,34)">Graduate Research Assistant</span><span style="font-size:9.5pt;font-family:Arial,sans-serif;color:rgb(34,34,34)"></span></div><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif;background-color:white"><span style="font-size:10pt;font-family:&#39;Courier New&#39;;color:rgb(34,34,34)">Desert Research Institute</span><span style="font-size:9.5pt;font-family:Arial,sans-serif;color:rgb(34,34,34)"></span></div><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif;background-color:white"><span style="font-size:10pt;font-family:&#39;Courier New&#39;;color:rgb(34,34,34)"><a href="mailto:Kacie.Shourd@dri.edu" style="color:rgb(149,79,114)" target="_blank"><span style="color:blue">Kacie.Shourd@dri.edu</span></a></span><span style="font-size:9.5pt;font-family:Arial,sans-serif;color:rgb(34,34,34)"></span></div><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif;background-color:white"><span style="font-size:10pt;font-family:&#39;Courier New&#39;;color:rgb(34,34,34)">Work: <a href="tel:%28775%29%20674-7049" value="+17756747049" target="_blank">(775) 674-7049</a></span></div><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif;background-color:white"><span style="font-size:10pt;font-family:&#39;Courier New&#39;;color:rgb(34,34,34)"><br></span></div></div><div><div style="font-family:&#39;Times New Roman&#39;;font-size:16px"><hr><div style="direction:ltr"><font face="Tahoma" size="2"><b>From:</b><span> </span><a href="mailto:ncl-talk-bounces@ucar.edu" target="_blank">ncl-talk-bounces@ucar.edu</a><span> </span>[<a href="mailto:ncl-talk-bounces@ucar.edu" target="_blank">ncl-talk-bounces@ucar.edu</a>] on behalf of Xi Chang [<a href="mailto:xi.chang01@gmail.com" target="_blank">xi.chang01@gmail.com</a>]<br><b>Sent:</b><span> </span>Tuesday, July 12, 2016 6:34 AM<br><b>To:</b><span> </span><a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><br><b>Subject:</b><span> </span>[ncl-talk] loop over a unique filename<br></font><br></div><div></div><div><div dir="ltr">Dear NCL,<div><br></div><div>I have a unique *nc file like this (with increment 1):</div><div><br></div><div><a href="http://data.0001.nc/" target="_blank">data.0001.nc</a></div><div><a href="http://data.0002.nc/" target="_blank">data.0002.nc</a><br></div><div><a href="http://data.0003.nc/" target="_blank">data.0003.nc</a><br></div><div>.</div><div>.</div><div><a href="http://data.0010.nc/" target="_blank">data.0010.nc</a></div><div><a href="http://data.0011.nc/" target="_blank">data.0011.nc</a><br></div><div><a href="http://data.0012.nc/" target="_blank">data.0012.nc</a><br></div><div>.</div><div>.</div><div>.</div><div><a href="http://data.0101.nc/" target="_blank">data.0101.nc</a><br></div><div><a href="http://data.0102.nc/" target="_blank">data.0102.nc</a><br></div><div><br></div><div>I want to call this data using a loop, something like this:</div><div><br></div><div>t=1,1</div><div><br></div><div>input=&quot;/dir/data.000+&quot;t&quot;.nc</div><div><br></div><div>but it doesnt work when then zero is reduced infront of the filename.</div><div>anys suggestion how to call this files on a loop?</div><div><br></div><div>Thanks</div><div><br></div><div>Chang</div><div><br></div></div></div></div></div></div><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"></div></div><font style="font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" face="Arial" size="2">PUBLIC RECORDS NOTICE: In accordance with NRS Chapter 239, this email and responses, unless otherwise made confidential by law, may be subject to the Nevada Public Records laws and may be disclosed to the public upon request.</font><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important"><span> </span></span><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">_______________________________________________</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">ncl-talk mailing list</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="mailto:ncl-talk@ucar.edu" style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">ncl-talk@ucar.edu</a><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">List instructions, subscriber options, unsubscribe:</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"></div></blockquote></div><br></div></div></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>