
round
Rounds a float or double variable to the nearest whole number.
Prototype
function round ( x : float, ; or double opt : integer ) return_val [dimsizes(x)] : (see below for type)
Arguments
xAn array of one or more values of any dimensionality.
opt
opt=0: return values of the same type as x
opt=1: return values of type float
opt=2: return values of type double
opt=3: return values of type integer
Description
This function returns results similar to the Fortran function "anint"; that is, it rounds the input to the nearest whole number. It differs in that it allows the user to specify the type of the return values. Also, missing values are ignored.
See Also
Examples
Example 1
The one caveat to using this function is that user must be aware that
if opt=3 is chosen, then the
Example 2
Here is an example where the _FillValue will change.
Like example 3, but assume you want a _FillValue equal to -99. There
are two approaches:
x = 5.7
q = round(x,0) ; ===> q=6.0 (type float)
r = round(x,1) ; ===> r=6.0 (type float)
d = round(x,2) ; ===> d=6.0 (type double)
i = round(x,3) ; ===> i=6 (type integer)
Example 2
x = (/-5. , -4.7, -4.5, -4.3, -0.8, -0.5, -0.2, -50.6 \
, 5. , 4.7, 4.5, 4.3, 0.8, 0.5, 0.2, 50.6 \
,-99. /)
x@_FillValue = -99.
q = round(x,0) ; ===> (/-5.,-5.,-5.,-4.,-1.,-1., 0.,-51. \
, 5., 5., 5., 4., 1., 1., 0., 51. \
,-99. /)
f = round(x,1) ; ===> (/-5.,-5.,-5.,-4.,-1.,-1., 0.,-51. \
, 5., 5., 5., 4., 1., 1., 0., 51. \
,-99. /)
d = round(x,2) ; ===> (/-5.,-5.,-5.,-4.,-1.,-1., 0.,-51. \
, 5., 5., 5., 4., 1., 1., 0., 51. \
,-99. /)
i = round(x,3) ; ===> (/-5 ,-5 ,-5 ,-4 ,-1 ,-1 , 0 ,-51 \
, 5 , 5 , 5 , 4 , 1 , 1 , 0 , 51 \
,-99 /)
Example 3
x = (/-5. , -4.7, -4.5, -4.3, -0.8, -0.5, -0.2, -50.6 \
, 5. , 4.7, 4.5, 4.3, 0.8, 0.5, 0.2, 50.6 \
,-99.9 /)
x@_FillValue = -99.9
i = round(x,3) ; ===> (/-5 ,-5 ,-5 ,-4 ,-1 ,-1 , 0 ,-51 \
, 5 , 5 , 5 , 4 , 1 , 1 , 0 , 51 \
,-100 /)
Example 4:
x = (/-5. , -4.7, -4.5, -4.3, -0.8, -0.5, -0.2, -50.6, \
5. , 4.7, 4.5, 4.3, 0.8, 0.5, 0.2, 50.6, \
-99.9 /)
x@_FillValue = -99.9 ; original _FillValue
x@_FillValue = -99. ; NCL will change all -99.9 to -99.
i = round(x,3) ; ===> (/-5 ,-5 ,-5 ,-4 ,-1 ,-1 , 0 ,-51, \
5 , 5 , 5 , 4 , 1 , 1 , 0 , 51, \
-99 /)
x = (/-5. , -4.7, -4.5, -4.3, -0.8, -0.5, -0.2, -50.6, \
5. , 4.7, 4.5, 4.3, 0.8, 0.5, 0.2, 50.6, \
-99.9 /)
x@_FillValue = -99.9 ; original _FillValue
x@_FillValue = 1234567. ; NCL will change all -99.9 to 1234567.
i = round(x,3) ; ===> (/-5 ,-5 ,-5 ,-4 ,-1 ,-1 , 0 ,-51, \
5 , 5 , 5 , 4 , 1 , 1 , 0 , 51, \
1234567 /)
Upon return, i@_FillValue = 1234567.