<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 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 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;meier-fleischer@dkrz.de&gt;, wrote:<br />
<blockquote type="cite" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #1abc9c;">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="moz-cite-prefix">Am 19.01.17 um 12:53 schrieb Marston Johnston:<br /></div>
<blockquote cite="mid:e6ab4f50-3a7b-42ee-ac0e-84045de61c9c@Spark" type="cite" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #e67e22;">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<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)),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)+"/"+day+"/NSS*.nc"</div>
<div>&#160; &#160; &#160; &#160; dayfile = idir+years(y)+"/"+months(m)+"/"+day+"/daymean.nc"</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="mimeAttachmentHeader"></fieldset>
<br />
<pre wrap="">
_______________________________________________
ncl-talk mailing list
<a class="moz-txt-link-abbreviated" href="mailto:ncl-talk@ucar.edu">ncl-talk@ucar.edu</a>
List instructions, subscriber options, unsubscribe:
<a class="moz-txt-link-freetext" href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a>
</pre></blockquote>
_______________________________________________<br />
ncl-talk mailing list<br />
ncl-talk@ucar.edu<br />
List instructions, subscriber options, unsubscribe:<br />
http://mailman.ucar.edu/mailman/listinfo/ncl-talk<br /></blockquote>
</div>
</body>
</html>