short2flt_hdf
Converts values of type short to values of type float using the "scale" and "offset" attributes (if present).
Prototype
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" ; This library is automatically loaded ; from NCL V6.2.0 onward. ; No need for user to explicitly load. function short2flt_hdf ( x : short ) return_val [dimsizes(x)] : float
Arguments
xAn array of type short of any dimensionality.
Return value
The results are returned in a float array of the same type dimensionality as x. Metadata is preserved.
Description
This function converts short data to float using the "scale" and "offset" attributes (if present), and preserves metadata. It assumes that the "offset" is subtracted from the "scale" prior to application to the data.
x_float = scale*(x_short - offset)
Other attributes similar to "scale" and "offset" will be recognized:
- offset:
- "add_offset", "OFFSET", "Offset", "_offset", "Intercept", "intercept"
- scale:
- "SCALE", "Scale", "_scale", "scale_factor", "Scale_factor", "Slope" , "slope"
Note2: A separate function, short2flt, must be used if the following approach is to be applied:
x_float = x_short*scale + offset
See Also
short2flt, dble2flt, flt2dble, byte2flt, typeof, getfilevartypes
Examples
Note: This is a snippet of code from binning_1.ncl.
tStrt = systemfunc("date") ; time the loop (wall clock)
do nf=0,nfil-1
print(nf+" "+fili(nf))
f = addfile(diri+fili(nf), "r")
; read data
lat2d = short2flt_hdf( f->Latitude )
lon2d = short2flt_hdf( f->Longitude)
x = short2flt_hdf( f->$vNam$ )
nx = product(dimsizes(x))
bin_sum(GBIN,GKNT,lon,lat \
,ndtooned(lon2d), ndtooned(lat2d),ndtooned(x) )
delete( x ) ; size may change
delete(lat2d)
delete(lon2d)
end do
wallClockElapseTime(tStrt, "Main Sum Loop", 0)