NCL system interactions
NCL can interact with the system via the systemfunc and getenv functions and the system procedure. These functions provide users with the ability to retrieve system related information and to execute shell commands or other software tools (i.e. netCDF operators).The following illustrates using NCL in a manner commonly accomplished via shell scripts:
- Retrieve an environment variable (getenv).
- For each year, (a) retrieve the time via
systemfunc, and (b) create a string containing a
command to be executed by system. The
command "msrcp" results in 12 monthly files being retrieved from the
NCAR Mass Storage Systen (MSS) for each year.
- Create a string that results in the netCDF operator "ncrcat" being
invoked to select one variable from each file and create a new file.
- Create a string to delete the the original 12 files.
begin nyrStrt = 300 nyrLast = 999 mssi= getenv("MSS_PATH") ; retrieve MSS environment variable fili= "b20.007.pop.h.0" ; first part of file name diri= "/ptmp/foo/" ; where to put msrcp data (input) diro= "/ptmp/foo/output/" ; where to put ncrcat data (outout) filo= "b20.TEMP." ; rename output files (root name) do nyear=nyrStrt,nyrLast ; each year has 12 files wallClock = systemfunc("date") ; retrieve wall clock time print("year="+nyear+" time="+wallClock) msscmd= "msrcp -n 'mss:" + mssi + fili + nyear + "-[0-1][0-9].nc' "+ diri+"." print (" msscmd= "+ msscmd) system (msscmd) ncocmd= "ncrcat -v TEMP " + diri + fili + "*.nc "+diro+filo+nyear+".nc" print ("ncocmd = "+ncocmd) system (ncocmd) rmcmd = "'rm' "+diri+fili+nyear+"*.nc" print ("rmcmd ="+ rmcmd) system (rmcmd) end do endBe sure to also see the Command Line Options section in the NCL Reference Manual.