NCL Website header
NCL Home > Documentation > Functions > Meteorology

grad_latlon_cfd

Compute the meridional and zonal gradients of a variable on a global or limited area rectilinear grid.

Available in version 6.4.0 and later.

Prototype

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"

	function grad_latlon_cfd (
		z          : numeric,  ; float, double, integer only
		lat    [*] : numeric,  
		lon    [*] : numeric,  
		cyclic [1] : logical,  
		opt    [1] : logical   
	)

	return_val [dimsizes(z)] :  float or double

Arguments

z

Variable of 2-to-4 dimensions. The two rightmost dimensions must ve (...,lat,lon). Some examples: (lat,lon), (time,lat,lon), (lev,lat,lon), (time,lev,lat,lon). Missing values are allowed.

lat

A one-dimensional array containing the latitudes in degrees north. These need not be equally spaced. For example they can be gaussian latitudes.

lon

A one-dimensional array containing the longitudes in degrees east. These must be in increasing order and must be equally spaced.

cyclic

True: z treated as cyclic in lon and the end values and all the returned values will be calculated via centered differences. False: q NOT treated as cyclic in lon and the end values will use a one-sided difference scheme for the end points. z should not include a cyclic point.

opt

Currently not used. Set to False.

Return value

A variable of type list. It contains two arrays. Element [0] contains the meridional gradient and element [1] contains the zonal gradient. These elements will be the same size and shape as z. The output will be double if z is of type double. If present, meta data will be returned.

Description

See Also

gradsg, gradsf, center_finite_diff_n, advect_variable

Examples

A 'worked' example which compares the results between gradients using "spherical harmonics and centered finite differences is available here.

Example 1

Given a scalar array T on a global rectilinear grid, compute the latitudinal and longitudinal derivatives. The returned variable contains two components: [0]=meridional; [1] zonal.

                                
  gradLatLon  = grad_latlon_cfd (T, T&lat T&lon, True, False)
                               
  T_grad_lat  = gradLatLon[0]    ; for clarity; explicitly extract variables from returned 'list' 
  T_grad_lon  = gradLatLon[1]
  delete(gradLatLon)

; replace the generic attributes with more specific attributes

  T_grad_lon@long_name = "longitudinal gradient (derivative)"
  T_grad_lat@long_name = "latitudinal gradient (derivative)"
  T_grad_lat@units     = "K/m"
  T_grad_lon@units     = "K/m"

Example 2

Given a scalar array SST on a global rectilinear grid, compute the latitudinal and longitudinal derivatives. The returned variable contains two components: [0]=meridional; [1] zonal. Here, the SST have missing values over land.

                                
  gradLatLon  = grad_latlon_cfd (SST, SST&lat SST&lon, True, False)
                               
  SS_grad_lat  = gradLatLon[0]    ; for clarity; explicitly extract variables from returned 'list' 
  SS_grad_lon  = gradLatLon[1]
  delete(gradLatLon)

; replace the generic attributes with more specific attributes

  SST_grad_lon@long_name = "longitudinal gradient"
  SST_grad_lat@long_name = "latitudinal gradient"
  if (isatt(SST,"units")) then
      SST_grad_lat@units = SST@units+"/m"
  else
      SST_grad_lat@units = "C/km"
  end if