NCL Home > Documentation > Functions > Variable query

typeof

Returns the string name of the type of the input variable.

Prototype

	function typeof (
		val       
	)

	return_val [1] :  string

Arguments

val

A variable of any type and dimensionality.

Description

This function returns the string name of the input type. This is especially useful when you need to create a new variable whose type is the same as an existing variable's type.

See Also

getfilevartypes

Examples

Example 1

The following short code snippet shows how to use typeof and dimsizes to create a new variable y that is the same size and type as x:

  x = new((/2,3/),float)
  y = new(dimsizes(x),typeof(x))
Example 2

The following example shows how to use typeof to create an NCL function called "tofloat" that converts any numeric value to a float:

function tofloat(x:numeric)
local xf
begin
  if(typeof(x).eq."double")
    xf = doubletofloat(x)
  else
    if(isatt(x,"_FillValue"))
      xf = new(dimsizes(x),float,x@_FillValue)
    else
      xf = new(dimsizes(x),float)
      delete(xf@_FillValue)
    end if
    xf = x
  end if
  return(xf)
end