NCL Home > Documentation > Functions > Array manipulators

conform_dims

Expands an array or scalar so that it conforms to the shape of the given dimension sizes.

Available in version 5.0.1 or later.

Prototype

	function conform_dims (
		dims  : integer,  
		r     ,           
		ndim  : integer   
	)

	return_val [dims] :  typeof(r)

Arguments

dims

An array of dimension sizes of which r will be conformed to.

r

A scalar or an array whose dimensions must be a subset of dims.

ndim

An array of dimension indexes to indicate which dimension sizes indicated by dims match the dimensions in r. Dimension numbering starts at the left and must be increasing. The leftmost dimension index is 0, the next dimension index is 1, and so on. If r is a scalar, then ndim can have the special value of -1 (see below).

Description

This function will create a new variable that has dimensions dims and the same type as r. The values of r will be copied to all of the other dimensions.

If r is a scalar and ndims is -1, then the scalar value will be copied to all elements of a new array of the same size as indicated by dims.

One use of this function is to create a new (and often temporary) variable so that it can be used for something like multiplication between two variables.

This function is identical to conform, except you pass in the dimension sizes of the new array size that you want to conform to, rather than the array itself. This method is preferable because you don't need to create the array before using this function.

See Also

conform

Examples

For more examples, see the conform examples section.

Example 1

If you have a 3D array x with sizes ntim x nlat x mlon and an array t of length ntim, then the following line:

    tConform = conform_dims (dimsizes(x),t,0) 

will yield an array tConform that is dimensioned ntim x nlat x mlon where the contents of t are propagated to all dimensions of x.

Example 2

Assume T is a 4D array with dimensions ntim x klvl x nlat x mlon and dp is an array of length klvl. If you want to compute the column pressure weighted mean temperature at all times, then use:

  dpC = conform_dims(dimsizes(T), dp, 1)  ; => (ntim,klvl,nlat,mlon)
  T_wgtAve = dim_sum(T*dpC)/dim_sum(dpC)