NCL Website header
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"  ; This library is automatically loaded
                                                             ; from NCL V6.2.0 onward.
                                                             ; No need for user to explicitly load.

	function short2flt (
		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.

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"
Note: 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.

See Also

dble2flt, flt2dble, byte2flt, typeof, getfilevartypes


Example 1

The file "" contains temperatures at 2 meters. The data are stored as type "short" with a scale_factor and add_offset:

        short air(time, level, lat, lon) ;
                air@long_name = "Daily Forecast of Air temperature at 2 m" ;
                air@units = "degK" ;
                air@add_offset = 447.65f ;
                air@scale_factor = 0.01f ;
Convert to type "float" as the data are being read:
 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" 

  f    = addfile("" , "r")
  t2m  = short2flt( f->air )  

The output contains
Variable: t2m
Type: float
Total Size: 26350080 bytes
            6587520 values
Number of Dimensions: 4
Dimensions and sizes:   [time | 365] x [level | 1] x [lat | 94] x [lon | 192]
            time: [1569072..1577808]
            level: [ 2.. 2]
            lat: [88.542..-88.542]
            lon: [ 0..358.125]
Number Of Attributes: 18
  long_name :   Daily Forecast of Air temperature at 2 m
NOTE 1: it is possible to test a variable's type prior to reading the variable to memory. Using the above example:
  f    = addfile("" , "r")
  if (getfilevartypes (f,"air").eq."short") then)
      t2m  = short2flt( f->air )
      t2m  = f->air 
  end if
NOTE 2: The above file's time units are "hours since 1800-1-1 00:00:0.0". Many people find these units rather cumbersome to use. To convert to more 'human readable' time units the cd_calendar function can be used:
   ymdh = cd_calendar(time, 0)          ; ymdh(:,0:5)
   yyyymmddhh = cd_calendar(time, -3)   ; integer