[ncl-talk] check if a directory exists

Marston Johnston marston.johnston at gu.se
Thu Jan 19 04:53:03 MST 2017


Hi,

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.
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?

Thanks in advance!
/M

; *******  Code *************
do y = 0, nyears - 1
    print("Processing year: "+years(y))
    do m = 0, nmonths - 1
      print("Processing month: "+months(m))
      ndays := days_in_month(toint(years(y)),toint(months(m)))
      days := ispan(1,ndays,1)
      ;print(days)
      do d = 0, ndays - 1
        print("Processing day: "+(d+1))
        day = sprinti("%0.2i",days(d))
        cmd := idir+years(y)+"/"+months(m)+"/"+day+"/NSS*.nc"
        dayfile = idir+years(y)+"/"+months(m)+"/"+day+"/daymean.nc"
        ;print(dayfile)
        ;exit
        files := systemfunc ("ls "+cmd)
        ;print(files)
        nfiles = dimsizes(files)
snip

;****************** End of Code snip *************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170119/5a594238/attachment.html 


More information about the ncl-talk mailing list