NCL Home > Documentation > Functions > Array manipulators

onedtond

Converts a one-dimensional array to a multi-dimensional array.

Prototype

	function onedtond (
		val   ,           
		dims  : integer   
	)

	return_val [dims] :  typeof(val)

Arguments

val

A one-dimensional array of any type.

dims

A one-dimensional array of positive integer values that represent the desired output dimensionality.

Description

This function converts any one-dimensional array to a multi-dimensional array. If the product of the output dimension sizes is less than the number of elements in the input array, a warning is printed, but the output array is filled with as many values from the input as will fit. If the product of the output dimension sizes is greater than the input size, then the input is repeatedly copied as many times as will fit. If the fit is uneven, an error message is printed.

See Also

ndtooned

Examples

Example 1

	a = (/1,2,3,4,5,6,7,8/)
;
; Basic case where input and output have same number of elements
;
	a0 = onedtond(a,(/2,4/))
;
; Case where there are twice the number of elements in the output
; as the input. In this case the values of a are copied twice
;
	a1 = onedtond(a,(/2,8/))

;
; Case where there are half the number of elements in the output
; as the input. In this case only the first four values of a
; are copied to the output.
; The following case generates a WARNING.
;
	a2 = onedtond(a,(/2,2/))

;
; Case where there are more elements in output than input but 
; number_output % number_input is not 0
; The following case generates a WARNING.
;
	a3 = onedtond(a,(/2,7/))