C-----------------------------------------------------------------------
C  MOIFUN IS A SET OF MOISTURE VARIABLE CONVERSION FUNCTIONS. THE
C  FUNCTION PACKAGE RELATES ATMOSPHERIC PRESSURE, TEMPERATURE, AND
C  WATER VAPOR PRESSURE, WITH THE MOISTURE VARIABLES OF RELATIVE
C  HUMIDITY, MIXING RATIO, SPECIFIC HUMIDITY, DEWPOINT, AND VIRTUAL
C  TEMPERATURE. VARIOUS COMPONENTS OF THE FUNCTIONS ARE GIVEN BELOW.
C
C
C  SYMBOLS (AND THEIR UNITS) USED IN THE FUNCTION ARGUMENTS ARE:
C
C     P  = ATMOSPHEREIC PRESSURE     (MB)
C     E  = WATER VAPOR PRESSURE      (MB)
C     T  = TEMPERATURE               (DEG C)
C     R  = RELATIVE HUMIDITY         (PERCENT)
C     W  = MIXING RATIO              (G/G)
C     Q  = SPECIFIC HUMIDITY         (G/G)
C     DP = TEMPERATURE               (DEG C)
C     ES = SATURATION VAPOR PRESSURE (MB)
C     WS = SATURATION MIXING RATION  (G/G)
C     TV = VIRTUAL TEMPERATURE       (DEG C)
C     TS = SENSIBLE TEMPERATURE      (DEG C)
C
C  PHYSICAL CONSTANTS USED ARE:
C
C     EZERO = WATER VAPOR ES @ 0 DEG C    (   6.11  MILIBARS        )
C     EVLAT = LATENT HEAT OF EVAPORATION  (  597.3  CAL/G           )
C     VMOLW = MOLECULAR WEIGHT OF WATER   ( 18.016  G/MOL           )
C     DMOLW = MOLECULAR WEIGHT OF DRY AIR ( 28.966  G/MOL           )
C     RSTAR = UNIVERSAL GAS CONSTANT      (   1.98  CAL/(MOL*DEG K) )
C     TZERO = 0 DEG C IN DEG K            ( 273.16  DEG K           )
C     EPSLN = VMOLW/DMOLW                 (   .622  NO UNITS        )
C
C  THE SATURATION WATER VAPOR PRESSURE(ES) IS COMPUTED AS A SOLUTION
C  OF THE CLAUSIUS-CLAPEYRON EQUATION (SEE HESS,"INTRODUCTION TO
C  THEORETICAL METEOROLOGY", PGS 48-49). THE SPECIFIC FORMULATION,
C
C  ES(T)=EZERO*EXP(17.269*T/(T+237.3)),
C
C  WHERE T IS DEGREES CELSIUS, IS A FORM OF TETENS' FORMULA FOR SATURATION
C  VAPOR PRESSURE. FOR MORE DETAILS SEE NMC OFFICE NOTE 36, OR
C  TETENS, O., 1930: OBER EINIGE METEOROLOGISCHE VEGRIFFE. Z. GEOPHYS.
C
C  THE DEFINITIONS OF MOISTURE VARIABLES ARE (FROM HESS,PGS 58-60):
C
C     RELATIVE HUMIDITY    R  = W/WS
C     MIXING RATIO         W  = EPSLN*E/(P-E)
C     SPECIFIC HUMIDITY    Q  = EPSLN*E/(P-E*(1-EPSLN))    (EXACT FORM)
C     DEW POINT            DP = TEMPERATURE WHERE WS(DP,P,E) = W(T,P,E)
C     VIRTUAL TEMPERATURE  VT = T*(1+W/EPSLN)/(1+W)
C     SENSIBLE TEMPERATURE TS = T*(1+W)/(1+W/EPSLN)
C
C  MOIFUN PROVIDES ENTRY POINTS WHICH COMPUTE MOISTURE VARIABLES FROM
C  THEIR COMPONENTS. ENTRIES ARE ALSO GIVEN WHICH CALCULATE E FROM
C  THE MOISTURE VARIABLES. THIS ENABLES CONVERSIONS BETWEEN MOISTURE
C  VARIABLES. THE FUNCTION ENTRY POINTS ARE:
C
C     1) ESVP(T     ) - SATURATION WATER VAPOR PRESSURE FROM T
C     2) ERLH(P,R,T ) - WATER VAPOR PRESSURE FROM P,R,T
C     3) EMIX(P,W   ) - WATER VAPOR PRESSURE FROM P,W
C     4) ESPH(P,Q   ) - WATER VAPOR PRESSURE FROM P,Q
C     5) EDEW(DP    ) - WATER VAPOR PRESSURE FROM DP
C     6) RELH(P,E,T ) - RELATIVE HUMIDITY FROM P,E,T
C     7) WMIX(P,E   ) - MIXING RATIO FROM P,E
C     8) QSPH(P,E   ) - SPECIFIC HUMIDITY FROM P,E
C     9) DPAL(E     ) - DEW POINT FROM E   (ALGEBRAIC)
C    10) VIRT(P,E,TS) - VIRTUAL  TEMPERATURE FROM P,E,TS
C    11) SENT(P,E,TV) - SENSIBLE TEMPERATURE FROM P,E,TV
C
C  THE MAIN ENTRY POINT (MOIFUN) IS A DUMMY FUNCTION.
C
C     CALLING MOIFUN RESULTS IN AN ABORT.
C
C-----------------------------------------------------------------------
      FUNCTION MOIFUN(DUMMY)
 
      PARAMETER (RSTAR = 1.98        )
      PARAMETER (TZERO = 273.16      )
      PARAMETER (EVLAT = 597.3       )
      PARAMETER (VMOLW = 18.016      )
      PARAMETER (DMOLW = 28.966      )
      PARAMETER (EZERO = 6.11        )
      PARAMETER (EPSLN = VMOLW/DMOLW )
 
C-----------------------------------------------------------------------
      ES(T) = EZERO*EXP(17.269*T/(T+237.3))
C-----------------------------------------------------------------------
 
C  MAIN ENTRY POINT DOES NOTHING
C  -----------------------------
 
      moifun=0; RETURN
 
C  SATURATION VAPOR PRESSURE FROM T
C  --------------------------------
 
      ENTRY ESVP(T)
      ESVP = ES(T)
      RETURN
 
C  VAPOR PRESSURE FROM P,R,T
C  -------------------------
 
      ENTRY ERLH(P,R,T)
      RH   = .01*R
      ERLH = P/(1.+P/(RH*ES(T))-1./RH)
      RETURN
 
C  VAPOR PRESSURE FROM P,W
C  -----------------------
 
      ENTRY EMIX(P,W)
      EMIX = W*P/(EPSLN+W)
      RETURN
 
C  VAPOR PRESSURE FROM P,Q
C  -----------------------
 
      ENTRY ESPH(P,Q)
C     ESPH = Q*P/(1.   +Q*(1.-EPSLN))
      ESPH = Q*P/(EPSLN+Q*(1.-EPSLN))
      RETURN
 
C  VAPOR PRESSURE FROM DP
C  ----------------------
 
      ENTRY EDEW(DP)
      EDEW = ES(DP)
      RETURN
 
C  RELATIVE HUMIDITY FROM P,E,T
C  ----------------------------
 
      ENTRY RELH(P,E,T)
      EST  = ES(T)
      RELH = (E/(P-E))/(EST/(P-EST))
      RETURN
 
C  MIXING RATIO FROM P,E
C  ---------------------
 
      ENTRY WMIX(P,E)
      WMIX = EPSLN*E/(P-E)
      RETURN
 
C  SPECIFIC HUMIDITY FROM P,E
C  --------------------------
 
      ENTRY QSPH(P,E)
      QSPH = EPSLN*E/(P-E*(1.-EPSLN))
      RETURN
 
C  DEW POINT FROM ALGEBRAIC MANIPULATION OF ES FUNCTION GIVEN E
C  ------------------------------------------------------------
 
      ENTRY DPAL(E)
      XLNE = LOG(E/EZERO)
      DPAL = 237.3*XLNE/(17.269-XLNE)
      RETURN
 
C  VIRTUAL TEMPERATURE FROM P,E,TS
C  -------------------------------
 
      ENTRY VIRT(P,E,TS)
      RMIX = EPSLN*E/(P-E)
      VIRT = (TS+TZERO)*(1.+RMIX/EPSLN)/(1.+RMIX) - TZERO
      RETURN
 
C  SENSIBLE TEMPERATURE FROM P,E,TV
C  --------------------------------
 
      ENTRY SENT(P,E,TV)
      RMIX = EPSLN*E/(P-E)
      SENT = (TV+TZERO)*(1.+RMIX)/(1.+RMIX/EPSLN) - TZERO
      RETURN
 
      END
