! Library:phys $Id: hlesat.h 6317 2008-10-30 09:59:24Z towil $
!
!     ------------------------------------------------------------
!
!     Definition of function 'pecor(pp,tt)'
!     The function is intended for handling
!     the computation of saturation specific humidity
!     at low pressures in the atmosphere.
!     The saturation specific humidity QSAT will
!     then be computed as :
!     QSAT=0.622*esat(tt)/pecor(pp,tt)
!
!     The full unapproxipated formula is
!     QSAT=0.622*esat(tt)/( pp -(1-0.622)*esat(tt) )
!
!     For very low pressures together with high temperatures
!     (physically unrealistic)
!     the formula does not behave well since the denominator
!     can in principle become zero or negative.
!     ------------------------------------------------------------

      real(kind=jprb) :: pp,pecor
      real(kind=jprb), parameter :: zc5p = 10000._jprb
      real(kind=jprb), parameter :: zc6e = 0.378_jprb

      real(kind=jprb), parameter :: zmelt =273.16_jprb
      real(kind=jprb), parameter :: zdlat =2368.71_jprb
      real(kind=jprb)            :: flatvt

! latent heat of fusion is a function of temperature

#ifdef ESATSFUN
#include "hlesatsfun.h"

      pecor(pp,tt) = pp - min(pp,zc5p)/zc5p*zc6e*esat(tt)

      flatvt(tt)=-zdlat*(tt - zmelt)      
#else
#include "hlesatstab.h"

      real(kind=jprb) :: esatw,desdtw,esati,desdti,desdt,esat,tt

      esat(tt)=estab(nint(xndegr*tt))
      desdt(tt)=destab(nint(xndegr*tt))
      esatw(tt)=estabw(nint(xndegr*tt))
      desdtw(tt)=destabw(nint(xndegr*tt))
      esati(tt)=estabi(nint(xndegr*tt))
      desdti(tt)=destabi(nint(xndegr*tt))

      pecor(pp,tt) = pp - min(pp,zc5p)/zc5p*zc6e*esat(tt)

      flatvt(tt)=-zdlat*(tt - zmelt)

      call hltabdef
#endif
