C$$$   SUBPROGRAM DOCUMENTATION BLOCK
C                .      .    .                                       .
C SUBPROGRAM:    M_TV        CALCULATES VIRTUAL TEMPERATURE
C
C   PRGMMR:  BENJAMIN, STAN ORG: ERL/PROFS      DATE: 93-01-12
C
C ABSTRACT:  CALCULATES VIRTUAL TEMPERATURE FROM TEMP, DEWPOINT, AND
C   PRESSURE
C
C PROGRAM HISTORY LOG:
C
C   00-03-14  M. BARTH    COPIED FROM MSAS & MODIFIED FOR MADIS.
C
C USAGE:           M_TV = M_TV(T, TD, P, SPVAL)
C
C   INPUT ARGUMENT LIST:
C   T           - REAL           TEMPERATURE IN CELSIUS OR KELVIN
C   TD          - REAL           DEWPOINT IN CELSIUS OR KELVIN
C   P           - REAL           PRESSURE IN MILLIBARS
C   SPVAL       - REAL           MISSING DATA FLAG
C
C   OUTPUT ARGUMENT LIST:
C   M_TV        - REAL           VIRTUAL TEMPERATURE IN CELSIUS OR
C                                KELVIN
C
C REMARKS: NONE
C
C ATTRIBUTES:
C   LANGUAGE: FORTRAN-77 + EXTENSIONS
C   MACHINE: DEC - VAX, VMS
C
C$$$
C
C
C   T AND TD CAN BE CELSIUS OR KELVIN
C   P MUST BE IN MILLIBARS
C   M_TV IS IN KELVIN
C
      REAL FUNCTION M_TV(T,TD,P,SPVAL)
      REAL M_ESW
      PARAMETER (CONST = 0.37803)
C        constant = 0.62197 * 0.6078
      IF(T.LT.SPVAL .AND. TD.LT.SPVAL .AND. P.NE.SPVAL) THEN
           P2=P
        IF(T.LT.150.) THEN
C* T IN CELSIUS
           T2=T+273.15
        ELSE
           T2=T
        ENDIF
        SATP=M_ESW(TD)
C       M_TV=T2/(1.0 - CONST*(SATP/P2))
        M_TV=T2*(1.0 + CONST*(SATP/P2))
      ELSE IF(T.LT.SPVAL) THEN
C* SOME STUFF IS MISSING,ASSIGN T TO M_TV
        IF (T.LT.150.) THEN
C* T IN CELSIUS
           M_TV=T+273.15
        ELSE
           M_TV=T
         ENDIF
      ELSE
        M_TV=SPVAL
       ENDIF
      RETURN
       END
C**---------------------------------------------------------------------
C**REQUIRED STANDARD FSL DISCLAIMER (NOVEMBER 2000)
C**---------------------------------------------------------------------
C**  OPEN SOURCE LICENSE/DISCLAIMER,  FORECAST SYSTEMS LABORATORY
C**  NOAA/OAR/FSL, 325 BROADWAY BOULDER, CO 80305
C**
C**  THIS SOFTWARE IS DISTRIBUTED UNDER THE OPEN SOURCE DEFINITION, 
C**  WHICH MAY BE FOUND AT http://www.opensource.org/osd.html.
C**
C**  IN PARTICULAR, REDISTRIBUTION AND USE IN SOURCE AND BINARY FORMS,
C**  WITH OR WITHOUT MODIFICATION, ARE PERMITTED PROVIDED THAT THE 
C**  FOLLOWING CONDITIONS ARE MET:
C**
C**  - REDISTRIBUTIONS OF SOURCE CODE MUST RETAIN THIS NOTICE, THIS LIST
C**    OF CONDITIONS AND THE FOLLOWING DISCLAIMER.
C**
C**  - REDISTRIBUTIONS IN BINARY FORM MUST PROVIDE ACCESS TO THIS 
C**    NOTICE, THIS LIST OF CONDITIONS AND THE FOLLOWING DISCLAIMER, AND
C**    THE UNDERLYING SOURCE CODE.
C**
C**  - ALL MODIFICATIONS TO THIS SOFTWARE MUST BE CLEARLY DOCUMENTED, 
C**    AND ARE SOLELY THE RESPONSIBILITY OF THE AGENT MAKING THE 
C**    MODIFICATIONS.
C**
C**  - IF SIGNIFICANT MODIFICATIONS OR ENHANCEMENTS ARE MADE TO THIS
C**    SOFTWARE, THE FSL SOFTWARE POLICY MANAGER 
C**    (softwaremgr.fsl@noaa.gov) BE NOTIFIED.
C**
C**  THIS SOFTWARE AND ITS DOCUMENTATION ARE IN THE PUBLIC DOMAIN AND 
C**  ARE FURNISHED "AS IS."  THE AUTHORS, THE UNITED STATES GOVERNMENT,
C**  ITS INSTRUMENTALITIES, OFFICERS, EMPLOYEES, AND AGENTS MAKE NO 
C**  WARRANTY, EXPRESS OR IMPLIED, AS TO THE USEFULNESS OF THE SOFTWARE
C**  AND DOCUMENTATION FOR ANY PURPOSE.  THEY ASSUME NO RESPONSIBILITY 
C**  (1) FOR THE USE OF THE SOFTWARE AND DOCUMENTATION; OR (2) TO 
C**  PROVIDE TECHNICAL SUPPORT TO USERS.
C**---------------------------------------------------------------------
