NCL Home > Documentation > Functions > Meteorology

temp_virtual

Compute atmospheric virtual temperature.

Available in version 6.5.0 and later.

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 temp_virtual (
		t          : numeric,  ; float, double, integer only
		w          : numeric,  
		iounit [3] : integer   
	)

	return_val [dimsizes(t)] :  float or double

Arguments

t

A scalar or array containing temperature (units: degC, degK, degF). If t and w are arrays they must be the same size and shape.

w

A scalar or array containing mixing ratio (units: kg/kg, g/kg). If w and t are arrays they must be the same size and shape.

iounit

An integer array of length 3 which specifies the units of the input t and w and returned virtual temperature (tv).

  • iounit(0)=0 input t are degrees Celcius (degC)
  • iounit(0)=1 input t are degrees Kelvin (degK)
  • iounit(0)=2 input t are degrees Farenheit (degF)

  • iounit(1)=0 input w are kg/kg
  • iounit(1)=1 input w are g/kg

  • iounit(2)=0 output tv are degrees Celcius (degC)
  • iounit(2)=1 output tv are degrees Kelvin (degK)
  • iounit(2)=2 output tv are degrees Farenheit (degF)

Return value

A variable of the same size and shape as t.

Description

The virtual temperature (tv) is the temperature that dry dry air would have if its pressure and density were equal to those of a given sample of moist air.

The specific humidity, often denoted as q, is nearly identical to the mixing ratio, w. Hence, it is common to use q directly in place of w. The function mixhum_convert can be used to perform the q to w conversion.

See Also

mixhum_convert, conform

Examples

Example 1: Calculate virtual temperature and compare with Calculating Virtual Temperature. Also, substitute q directly in place of w to illustrate the small virtual temperature difference.

   t   = 20         ; C         iounit(0)=0
   w   = 13.5       ; g/kg      iounit(1)=1   mixing ratio
   tvw = temp_virtual(t, w, (/0,1,0/))  ; tvw = 22.41; iounit(2)=0
   printVarSummary(tvw)

; To illustrate the small difference that using q instead of w: Perform conversion 

   q   = mixhum_convert(w, "w", (/1,1/))   
   tvq = temp_virtual(t, q, (/0,1,0/))  ; tvq = 22.38         
The edited outout is:

   Variable: tvw
   Type: float
   Total Size: 4 bytes
               1 values
   Number of Dimensions: 1
   Dimensions and sizes:	[1]
   Coordinates: 
   Number Of Attributes: 4
     long_name :	virtual temperature               
     units :	degC
     equation :	T*(1+0.61*w)
     NCL :	temp_virtual

     22.41409

Example 2: Read specific humidity (Q; kg/kg) and T (degK). Calculate virtual temperature using specific humidity directly and, for illustration, calculate mixing ratio.


   a  = addfile("cam35.h0.0008-07.nc","r") 
   t  = a->T       ; K         iounit(0)=1
   q  = a->Q       ; kg/kg     iounit(1)=0

   tvq= temp_virtual(t, q, (/1,0,0/))  ; return degC; iounit(2)=0
   printVarSummary(tvq)
   printMinMax(tvq,0)

   w  = mixhum_convert(q, "q", (/1,1/))  
   tvw= temp_virtual(t, w, (/1,0,1/))  ; return degK; iounit(2)=1
   printVarSummary(tvw)
   printMinMax(tvw,0)