NCL Home > Documentation > Functions > Type converters


Converts values of type short to values of type float using the "scale" and "offset" attributes (if present).


load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"

	function short2flt_hdf (
		x  : short   

	return_val [dimsizes(x)] :  float



An 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.


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:

"add_offset", "OFFSET", "Offset", "_offset", "Intercept", "intercept"
"SCALE", "Scale", "_scale", "scale_factor", "Scale_factor", "Slope" , "slope"
Note1: This function is slightly different than the built-in set of conversion functions (like floattointeger and shorttobyte), because it requires loading the "contributed.ncl" script and it preserves metadata. It has a slightly different naming style than the built-in functions, just to set it apart from these other functions.

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


Example 1

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)