NCL Home> Application examples> Data Analysis || Data files for some examples

Example pages containing: tidbits | resources | functions/procedures

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:

  1. Retrieve an environment variable (getenv).

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

  3. Create a string that results in the netCDF operator "ncrcat" being invoked to select one variable from each file and create a new file.

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

end
Be sure to also see the Command Line Options section in the NCL Reference Manual.