<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div name="messageBodySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;">Hi Dennis,
<div><br /></div>
<div>Thanks. I missed that example when I first looked at the doc :-)</div>
<div><br /></div>
<div>/M</div>
</div>
<div name="messageReplySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;"><br />
On 19 Jan 2017, 16:29 +0100, Dennis Shea &lt;shea@ucar.edu&gt;, wrote:<br />
<blockquote type="cite" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #1abc9c;">
<div dir="ltr">
<div><br />
<a target="_blank" href="http://www.ncl.ucar.edu/Document/Functions/Built-in/systemfunc.shtml">http://www.ncl.ucar.edu/<wbr />Document/Functions/Built-in/<wbr />systemfunc.shtml</a><br />
<br /></div>
See the last example<br /></div>
<div class="gmail_extra"><br />
<div class="gmail_quote">On Thu, Jan 19, 2017 at 7:43 AM, GMAIL <span dir="ltr">&lt;<a href="mailto:shejo284@gmail.com" target="_blank">shejo284@gmail.com</a>&gt;</span> wrote:<br />
<blockquote class="gmail_quote" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #e67e22;">
<div>
<div name="messageBodySection" style="font-size:14px;font-family:-apple-system,BlinkMacSystemFont,sans-serif">Hi Karin!
<div><br /></div>
<div>That is an elegant solution. I was was close to something like that but I didn’t use “test”.</div>
<div>Thanks for the help :-)</div>
<div><br /></div>
<div>Best regards,</div>
<div>/M</div>
</div>
<div>
<div class="h5">
<div name="messageReplySection" style="font-size:14px;font-family:-apple-system,BlinkMacSystemFont,sans-serif"><br />
On 19 Jan 2017, 13:34 +0100, Karin Meier-Fleischer &lt;<a href="mailto:meier-fleischer@dkrz.de" target="_blank">meier-fleischer@dkrz.de</a>&gt;, wrote:<br />
<blockquote type="cite" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #3498db;">Hi Marston,<br />
<br />
you can use NCLs 'systemfunc' function with the shell function 'test' to check if a directory exists.<br />
<br />
&#160; <tt><font color="#3333FF">test -d <i>directory</i></font></tt><font color="#3333FF"><tt>; echo $?</tt></font> &#160;&#160;&#160;&#160;&#160;&#160; returns 0 if directory exist or 1 if not<br />
<br />
E.g.<br />
<br />
<font color="#3333FF"><tt>&#160; dirnames = (/"/tmp", "dirB", "$HOME"/)<br />
&#160; ndirs = dimsizes(dirnames)<br />
<br />
&#160; do i=0,ndirs-1</tt><tt><br /></tt> <tt>&#160;&#160;&#160;&#160; ret = systemfunc("test -d "+dirnames(i)+"; echo $?")</tt><tt><br /></tt> <tt>&#160;&#160;&#160;&#160; if(ret .eq. 0) then</tt><tt><br /></tt> <tt>&#160;&#160;&#160;&#160;&#160; &#160; print("--&gt; "+dirnames(i)+": exists")&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ;-- do what you want to do</tt><tt><br /></tt> <tt>&#160;&#160;&#160;&#160; else if(ret .eq.1) then</tt><tt><br /></tt> <tt>&#160;&#160;&#160;&#160;&#160; &#160; print("--&gt; "+dirnames(i)+": doesn't exists")&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ;-- just continue<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160; continue<br /></tt> <tt>&#160;&#160;&#160;&#160; end if</tt><tt><br /></tt> <tt>&#160;&#160;&#160;&#160; end if</tt><tt><br /></tt> <tt>&#160; end do</tt></font><br />
<br />
Bye,<br />
Karin<br />
<br />
<br />
<div class="m_-1951690061443768131moz-cite-prefix">Am 19.01.17 um 12:53 schrieb Marston Johnston:<br /></div>
<blockquote type="cite" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #d35400;">
<div name="messageBodySection" style="font-size:14px;font-family:-apple-system,BlinkMacSystemFont,sans-serif">Hi,
<div><br /></div>
<div>I’m checking to see if there is a way for NCL to check if a directory is present before running a systemfunc for files to process? For example, I’m trying to process a series of MHS satellite granules but some satellites, e.g., metopa, noaa19, etc. have different record lengths for various reasons. Some records overlap and some do not.&#160;</div>
<div>So I will parallel process the satellite data with a single script with the satellite name as a command-line argument and loop over the years, months, and days available (see code snip below). I would like to check the presence of the directory before calling &#160;files := systemfunc ("ls "+cmd) so that if the record does not exist, NCL will not crash. I’ve looked at isfilepresent, file exist, but these will cause NCL to crash or return something that I’m not easily checked, i.e., e.g., an empty array of length 0. I did a search for this FAQ in NCL but there does not seem to be one. Any clever ideas out there?</div>
<div><br /></div>
<div>Thanks in advance!</div>
<div>/M</div>
<div><br /></div>
<div>; ******* &#160;Code *************</div>
<div>
<div>do y = 0, nyears - 1</div>
<div>&#160; &#160; print("Processing year: "+years(y))</div>
<div>&#160; &#160; do m = 0, nmonths - 1</div>
<div>&#160; &#160; &#160; print("Processing month: "+months(m))</div>
<div>&#160; &#160; &#160; ndays := days_in_month(toint(years(y)),<wbr />toint(months(m)))</div>
<div>&#160; &#160; &#160; days := ispan(1,ndays,1)</div>
<div>&#160; &#160; &#160; ;print(days)</div>
<div>&#160; &#160; &#160; do d = 0, ndays - 1</div>
<div>&#160; &#160; &#160; &#160; print("Processing day: "+(d+1))</div>
<div>&#160; &#160; &#160; &#160; day = sprinti("%0.2i",days(d))</div>
<div>&#160; &#160; &#160; &#160; cmd := idir+years(y)+"/"+months(m)+"/<wbr />"+day+"/NSS*.nc"</div>
<div>&#160; &#160; &#160; &#160; dayfile = idir+years(y)+"/"+months(m)+"/<wbr />"+day+"/<a href="http://daymean.nc" target="_blank">daymean.nc</a>"</div>
<div>&#160; &#160; &#160; &#160; ;print(dayfile)</div>
<div>&#160; &#160; &#160; &#160; ;exit</div>
<div>&#160; &#160; &#160; &#160; files := systemfunc ("ls "+cmd)</div>
<div>&#160; &#160; &#160; &#160; ;print(files)</div>
<div>&#160; &#160; &#160; &#160; nfiles = dimsizes(files)</div>
</div>
<div>snip</div>
</div>
<div name="messageSignatureSection" style="font-size:14px;font-family:-apple-system,BlinkMacSystemFont,sans-serif"><br />
;****************** End of Code snip *************************</div>
<br />
<fieldset class="m_-1951690061443768131mimeAttachmentHeader"></fieldset>
<br />
<pre>
______________________________<wbr />_________________
ncl-talk mailing list
<a class="m_-1951690061443768131moz-txt-link-abbreviated" href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a>
List instructions, subscriber options, unsubscribe:
<a class="m_-1951690061443768131moz-txt-link-freetext" href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" target="_blank">http://mailman.ucar.edu/<wbr />mailman/listinfo/ncl-talk</a>
</pre></blockquote>
______________________________<wbr />_________________<br />
ncl-talk mailing list<br />
<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><br />
List instructions, subscriber options, unsubscribe:<br />
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" target="_blank">http://mailman.ucar.edu/<wbr />mailman/listinfo/ncl-talk</a><br /></blockquote>
</div>
</div>
</div>
</div>
<br />
______________________________<wbr />_________________<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/<wbr />mailman/listinfo/ncl-talk</a><br />
<br /></blockquote>
</div>
<br /></div>
</blockquote>
</div>
</body>
</html>