SUBROUTINE AER_CLIM &
 &( KIDIA, KFDIA , KLON , KLEV , KAERO , &
 &  PAPH , PAP   , PCLON, PSLON, PGEMU , PT, PTH    , &
 &  PCAERO &
 &)

!*** * AER_CLIM* - SOURCE TERMS FOR TEST AEROSOLS

!**   INTERFACE.
!     ----------
!          *AER_CLIM* IS CALLED FROM *CALLPAR*.

!     AUTHOR.
!     -------
!        JEAN-JACQUES MORCRETTE  *ECMWF*

!     MODIFICATIONS.
!     --------------
!        ORIGINAL : 2004-04-27

!-----------------------------------------------------------------------

USE PARKIND1  ,ONLY : JPIM     ,JPRB
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK

USE YOMDIM   , ONLY : NFLEVG
USE YOMGEM   , ONLY : VBH      ,VAH      ,VP00  

IMPLICIT NONE

!-----------------------------------------------------------------------

!*       0.1   ARGUMENTS
!              ---------

INTEGER(KIND=JPIM),INTENT(IN)    :: KLON 
INTEGER(KIND=JPIM),INTENT(IN)    :: KIDIA 
INTEGER(KIND=JPIM),INTENT(IN)    :: KFDIA 
INTEGER(KIND=JPIM),INTENT(IN)    :: KLEV
INTEGER(KIND=JPIM),INTENT(IN)    :: KAERO

REAL(KIND=JPRB)   ,INTENT(IN)    :: PAP(KLON,KLEV), PAPH(KLON,0:KLEV)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCLON(KLON), PSLON(KLON), PGEMU(KLON)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PT(KLON,KLEV), PTH(KLON,0:KLEV)

REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCAERO(KLON,KLEV,KAERO)


!*       0.5   LOCAL VARIABLES
!              ---------------

INTEGER(KIND=JPIM) :: JK, JL

REAL(KIND=JPRB) :: ZCVHI(KLON,0:KLEV), ZCVLO(KLON,0:KLEV)
REAL(KIND=JPRB) :: ZGRTH(KLON), ZAETRN(KLON),ZAETRO(KLON)
REAL(KIND=JPRB) :: ZAELOO(KLON), ZAEHIO(KLON)

REAL(KIND=JPRB) :: ZAEOPS, ZAETR, ZDPNMO, ZEPSAER, ZEPSBGA, ZHHI, ZHLO, &
  & ZSTBGA, ZTRBGA, Z00BGA, ZTRPT
REAL(KIND=JPRB) :: ZETA(KLON,KLEV), ZETAH(KLON,0:KLEV)
REAL(KIND=JPRB) :: ZETAC(KLEV)    , ZETAHC(0:KLEV)    , ZDPRC(KLEV)
REAL(KIND=JPRB) :: ZPRES(KLEV)    , ZPRESH(0:KLEV)    , ZEPSBG(KLEV)

#include "gppre.intfb.h"

REAL(KIND=JPRB) :: ZHOOK_HANDLE

!-----------------------------------------------------------------------
IF (LHOOK) CALL DR_HOOK('AER_CLIM',0,ZHOOK_HANDLE)

ZHLO=MAX(1.0_JPRB,8434._JPRB/1000._JPRB)
ZHHI=MAX(1.0_JPRB,8434._JPRB/3000._JPRB)
ZTRBGA= 0.030_JPRB/(101325._JPRB-19330._JPRB)
ZSTBGA= 0.045_JPRB/19330._JPRB
Z00BGA= 0.050_JPRB/101325._JPRB
ZAEOPS= 0.050_JPRB
ZTRPT = 30._JPRB
ZEPSBGA=0.001_JPRB/101325._JPRB

ZETAH(:,0)=0._JPRB
ZPRESH(KLEV)=VP00

CALL GPPRE ( 1, 1, 1, NFLEVG, VAH, VBH, ZPRESH, ZPRES )

DO JK=0,KLEV
  ZETAHC(JK)=ZPRESH(JK)/ZPRESH(KLEV)
ENDDO
DO JK=1,KLEV
  ZETAC(JK)=ZPRES(JK)/ZPRESH(KLEV)
  ZDPRC(JK)=ZPRES(JK)-ZPRES(JK-1)
  ZEPSBG(JK)=ZDPRC(JK)*ZEPSBGA
ENDDO

DO JL=KIDIA,KFDIA
  ZCVLO(JL,0)=0._JPRB
  ZCVHI(JL,0)=0._JPRB
  ZAELOO(JL)=1._JPRB*ZCVLO(JL,0)
  ZAEHIO(JL)=1._JPRB*ZCVHI(JL,0)
  ZAETRO(JL)=1._JPRB
ENDDO
DO JK=1,KLEV
  DO JL=KIDIA,KFDIA
    ZETA(JL,JK) =PAP(JL,JK) /PAPH(JL,KLEV)
    ZETAH(JL,JK)=PAPH(JL,JK)/PAPH(JL,KLEV)
    ZCVLO(JL,JK)=ZETAH(JL,JK)**ZHLO
    ZCVHI(JL,JK)=ZETAH(JL,JK)**ZHHI
    ZGRTH(JL)= PTH(JL,JK-1)/PTH(JL,JK)

    IF (0.5_JPRB*(PAPH(JL,JK)+PAPH(JL,JK+1)) < 999._JPRB) THEN
! for models with top above 10hPa
      ZAETRN(JL)=1.0_JPRB
      ZAETRO(JL)=1.0_JPRB
      ZEPSAER=ZEPSBG(JK)
    ELSE
      ZAETRN(JL)=ZAETRO(JL)*(MIN(1.0_JPRB,ZGRTH(JL)))**ZTRPT
      ZEPSAER=1.E-10_JPRB
    ENDIF
    ZDPNMO=PAPH(JL,JK)-PAPH(JL,JK-1)
    ZAETR=SQRT(ZAETRN(JL)*ZAETRO(JL))
    PCAERO(JL,JK,1)=MAX(ZEPSAER, (1._JPRB-ZAETR)*(ZTRBGA*ZDPNMO+ZAEOPS*(ZCVHI(JL,JK)-ZCVHI(JL,JK-1))) )
    PCAERO(JL,JK,2)=MAX(ZEPSAER,          ZAETR *ZSTBGA*ZDPNMO )
    PCAERO(JL,JK,3)=MAX(ZEPSAER,                 Z00BGA*ZDPNMO )
    ZAETRO(JL)=ZAETRN(JL)
  ENDDO
ENDDO

!-----------------------------------------------------------------------
IF (LHOOK) CALL DR_HOOK('AER_CLIM',1,ZHOOK_HANDLE)
END SUBROUTINE AER_CLIM

