NCL Home > Documentation > Functions > Array query

cla_sq

Create a string that uses single quotes (sq) to enclose command line assignment statements (CLAs) for later use by NCL's system procedure.

Available in version 6.4.0 and later.

Prototype

	function cla_sq (
		strLeft  [1] : string,  
		strRight [1] : string   
	)

	return_val [1] :  a string with single quaotes at the beginning and end

Arguments

strLeft

A string that is the left-hand-side (lhs) of an assignment statement.

strRight

A string that is the right-hand-side (rhs) of an assignment statement. This string could include strings with double quotes or other unix/linux sensitive characters.

Return value

A scalar of type string.

Description

Executing external NCL scripts from within an NCL script requires that the classic unix/linux command line be passed to the operating sustem via NCL's system procedure. Sometimes these assignment contain characters that the unix command line interpreter would intercept. This behavior can be avoided by enclosing the segment within single quotes (').

See Also

str_get_sq, str_get_dq, str_get_tab, str_get_nl, system

Examples

Example 1: From within an NCL script, execute the following:


        ncl year=2015 'f="test.nc"' 'p=(/850,500,200/)' 'var=(/"T","Q"/)' foo.ncl

This can be tedious to create because each segment containing a (, ), /, " contains a character which has some 'meaning' to the unix/linux command line interpreter. To escape this behavior the affected components must be bracketed by single quotes. Note: The equal sign (=) is not a *nix sensitive character.

  asgn1 = cla_sq(  "f", "test.nc")             ; asgn1= 'f="test.nc"'
  asgn2 = cla_sq(  "p", "(/850,500,200/)")     ; asgn2= 'p=(/850,500,200/)'
  asgn3 = cla_sq("var", "(/"T","Q"/)")         ; asgn3= 'var=(/"T","Q"/)'

  cmd   = "ncl year=2015 "+asgn1+" "+asgn2+" "+asgn3+" foo.ncl"
  print("cmd: " + cmd)
  system(cmd)  

The output from the print command is:

  Variable: cmd
  Type: string
  Total Size: 8 bytes
              1 values
  Number of Dimensions: 1
  Dimensions and sizes:	[1]
  Coordinates: 
  (0)	ncl year=2015 'f=test.nc' 'p=(/850,500,200/)' 'var=(/"T","Q"/)' foo.ncl

Example 2: From within an NCL script, execute the following:


%>  ncl year=2012 'plvl=(/850,200/)' 'diri="/Data/NCEP/"' 'fili="uwnd.ncep.nc"' 'var=(/"uwnd"/)' foo.ncl

  asgn0 = "year=2015"                                           ; no need for function
  asgn1 = cla_sq("fili","data.1900-2015.nc") ; asgn1: 'fili="data.1900-2015.nc"'
  asgn2 = cla_sq("diri","/Data/NCEP/")       ; asgn2: 'diri="/Data/NCEP/"'
  asgn3 = cla_sq("plvl","(/850,500,200/)")   ; asgn3: 'plvl=(/850,500,200/)'
  asgn4 = cla_sq("var" ,"(/"T","Q"/)")       ; asgn4: 'var=(/"T","Q"/)'

  cmd   = "ncl "+asgn0+" "+asgn1+" "+asgn2+" "+asgn3+" "+asgn4+" foo.ncl"
  print("cmd="+cmd)   
  system(cmd)

The output from the print command is:

   ncl year=2012 'diri=/Data/NCEP/' 'fili=uwnd.ncep.nc' 'plvl=(/850,500,200/)' foo.ncl