!-------------------------------------- LICENCE BEGIN ------------------------------------
!Environment Canada - Atmospheric Science and Technology License/Disclaimer,
!                     version 3; Last Modified: May 7, 2008.
!This is free but copyrighted software; you can use/redistribute/modify it under the terms
!of the Environment Canada - Atmospheric Science and Technology License/Disclaimer
!version 3 or (at your option) any later version that should be found at:
!http://collaboration.cmc.ec.gc.ca/science/rpn.comm/license.html
!
!This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
!without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
!See the above mentioned License/Disclaimer for more details.
!You should have received a copy of the License/Disclaimer along with this software;
!if not, you can write to: EC-RPN COMM Group, 2121 TransCanada, suite 500, Dorval (Quebec),
!CANADA, H9P 1J3; or send e-mail to service.rpn@ec.gc.ca
!-------------------------------------- LICENCE END --------------------------------------
!

      SUBROUTINE MHUAESV 2
#if defined (DOC)
***   S/R MHUAES  -  CALCULATE ES=T-TD FROM T AND Q
*
*Author
*          N. Brunet  (Jan91)
*
*Revision
* 001      B. Bilodeau  (August 1991)- Adaptation to UNIX
*
* 002      C.CHOUINARD  (August 1998)- ADAPTATION TO 3DVAR
*
* 003      C.CHARETTE  (March 1999)- Added llprint and print diagnostics
* 004      S.Pellerin  (SEPT. 2000)- Exclude reference to commvo1
* 005      JM Belanger CMDA/SMC  Nov 2000
*                   . 32 bits conversion
* 006      Y.J. Rochon and Cecilien Charette - SMC - Sept 2004
*            - Use of new function FOTW8 FOEFQ8(in fintern8.cdk)
*              Follow WMO convention on T-Td vs HU relationship)

*Object
*          to calculate the dew point depression from specific
*          humidity, temperature and pressure.  No ice phase
*          is permitted and the pressure vector is given.
*
#endif
      IMPLICIT NONE
*IMPLICITS
*         --------------------------------------------------------------------------
#include "comlun.cdk"
#include "pardim.cdk"
#include "comdim.cdk"
#include "comdimo.cdk"
#include "comgem.cdk"
#include "commvo.cdk"
#include "commvog.cdk"
#include "comcst.cdk"
*
      INTEGER JOBS,JLEV
      REAL*8 ZE, ZTD, ZHU
      LOGICAL LLPRINT
*
#include "comphy.cdk"
#include "dintern8.cdk"
#include "fintern8.cdk"
*
c
*
      LLPRINT = .FALSE.
*
      DO JLEV=1,NFLEV
*
        DO JOBS=1,NOBTOT
*
*     get the saturated vapor pressure from q (specific humidity)
*
         ZHU = exp(gomqg(jlev,jobs))
         ZE = FOEFQ8(ZHU, RPPOBS(JLEV,JOBS))
*
*     now the dewpoint temperature
*
            ZTD=FOTW8(ZE)
*
*
*     finally the dewpoint depression
*
         GOMESG(JLEV,JOBS) = min(GOMTG(JLEV,JOBS) - ZTD,rmaxes)

********************************************************************
c         IF(LLPRINT) THEN
c            write(nulout,*)'MHUAESV:JOBS,JLEV,RPOBS,GMESG,GMTG,ZTD,ZHU '
c     &           ,JOBS,JLEV,RPPOBS(JLEV,JOBS),GOMESG(JLEV,JOBS)
c     &           ,GOMTG(JLEV,JOBS),ZTD,ZHU
c         ENDIF
*******************************************************************
*
        ENDDO
*
      ENDDO
*
      RETURN
      END