NCL Website header
NCL Home > Documentation > Functions > Metadata routines


Returns True for every element of the input that contains a missing value (_FillValue).


	function ismissing (

	return_val [dimsizes(data)] :  logical



A variable of any type and dimensionality.

Return value

Returns a logical value (True or False) for each data value.


For each element in data, ismissing returns True if the element is a missing value, and False otherwise.

ismissing is the only way to check for missing values (_FillValue). Conventional direct if checks:

          if (data(32)
          if (any(
          if (all(
will not work. This behavior is analogous to checking for NaN in many languages. A direct check [eg: x.eq.NaN ] will not work. A function must be used.

This is useful for filtering missing values.

See Also

set_default_fillvalue, default_fillvalue, ind


Example 1

If your data can contain all missing values, you may want to check this before doing a calculation on it or trying to plot it:

  if(all(ismissing(data))) then
    print("Your data is all missing. Cannot create plot.")
   plot = gsn_csm_contour(wks,data,res)
  end if

Example 2

If you want to print a warning message if your data contains some missing values:

  if(any(ismissing(data))) then
    print("Your data contains some missing values. Beware.")
  end if

Example 3

Assume you want to calculate the standard deviation of your data, and you also want to know how many data points were used to calculate this quantity:

   x = stddev(data)
   N = num(.not.ismissing(data))

Example 4

The ismissing function is often used in conjunction with the ind function. The code snippet below shows how to take all elements of lon_values longitude array, and create a new array that has the longitude values followed by a "E" or "W" (for "East" or "West"), or "Eq" for the equator:

  lon_labels = new(dimsizes(lon_values),string)

  lonW_index = ind(  0)
  lonE_index = ind(

    lon_labels(lonW_index) = fabs(lon(lonW_index)) + "W"  ; west
  end if

    lon_labels(lonE_index) = lon_values(lonE_index) + "E"  ; east
  end if

; Clean up (not necessary)


Example 5: Consider x[*] with _FillValue attribute: (a) count the number of _FillValue (missing values); (b) extract only the non-missing values.

  nmsg = num(ismissing(x))   ; count number of missing

  igood = ind(.not.ismissing(x))
  xgood = x(igood)