<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hi Marston,<br>
<br>
you can use NCLs 'systemfunc' function with the shell function
'test' to check if a directory exists.<br>
<br>
<tt><font color="#3333ff">test -d <i>directory</i></font></tt><font
color="#3333ff"><tt>; echo $?</tt></font> returns 0 if
directory exist or 1 if not<br>
<br>
E.g.<br>
<br>
<font color="#3333ff"><tt> dirnames = (/"/tmp", "dirB", "$HOME"/)<br>
ndirs = dimsizes(dirnames)<br>
<br>
do i=0,ndirs-1</tt><tt><br>
</tt><tt> ret = systemfunc("test -d "+dirnames(i)+"; echo $?")</tt><tt><br>
</tt><tt> if(ret .eq. 0) then</tt><tt><br>
</tt><tt> print("--> "+dirnames(i)+":
exists") ;-- do what you want to do</tt><tt><br>
</tt><tt> else if(ret .eq.1) then</tt><tt><br>
</tt><tt> print("--> "+dirnames(i)+": doesn't
exists") ;-- just continue<br>
continue<br>
</tt><tt></tt><tt> end if</tt><tt><br>
</tt><tt> end if</tt><tt><br>
</tt><tt> 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">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<title></title>
<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. </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 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>; ******* Code *************</div>
<div>
<div>do y = 0, nyears - 1</div>
<div> print("Processing year: "+years(y))</div>
<div> do m = 0, nmonths - 1</div>
<div> print("Processing month: "+months(m))</div>
<div> ndays :=
days_in_month(toint(years(y)),toint(months(m)))</div>
<div> days := ispan(1,ndays,1)</div>
<div> ;print(days)</div>
<div> do d = 0, ndays - 1</div>
<div> print("Processing day: "+(d+1))</div>
<div> day = sprinti("%0.2i",days(d))</div>
<div> cmd :=
idir+years(y)+"/"+months(m)+"/"+day+"/NSS*.nc"</div>
<div> dayfile =
idir+years(y)+"/"+months(m)+"/"+day+"/daymean.nc"</div>
<div> ;print(dayfile)</div>
<div> ;exit</div>
<div> files := systemfunc ("ls "+cmd)</div>
<div> ;print(files)</div>
<div> 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>
</body>
</html>