
NCL Home >
Documentation >
Functions >
General applied math
ceil
Returns the smallest integral value greater than or equal to each input value.
Prototype
function ceil ( values : numeric ) return_val [dimsizes(values)] : float or double
Arguments
valuesOne or more numeric values of any dimension.
Return value
Returns an array dimensioned the same as values. The return type is double if the input is double, and float otherwise.
Description
This function returns the smallest integral value greater than or equal to each value in values. Missing values are ignored.
Note that the values returned will be float or double. If you want integers, convert them with toint. See example below.
See Also
Examples
Example 1
f = 6.4 floor_f = floor(f) ceil_ f = ceil(ceil_f) print(floor_f) ; Should be 6 print(ceil_f) ; Should be 7Example 2
A common use of both ceil and floor is to return 'nice' values so you can use them to create integer ranges for contour levels, labeling X/Y axes, time arrays, etc:
years = (/1985.2,1986.8,1990.5,1993.2,1995.0,1997.9,1998.3/) min_year = toint(floor(min(years))) max_year = toint(ceil(max(years))) years_int = ispan(min_year,max_year,1) print(years_int)
Output:
(0) 1985 (1) 1986 (2) 1987 (3) 1988 (4) 1989 (5) 1990 (6) 1991 (7) 1992 (8) 1993 (9) 1994 (10) 1995 (11) 1996 (12) 1997 (13) 1998 (14) 1999