!OPTIONS XOPT(NOEVAL)
SUBROUTINE RADAER15 ( KIDIA , KFDIA , KPROMA, KTDIA , KLEV,&
 & PAPRS , PAPRSF, PT    , PTS,&
 & PAESEA, PAELAN, PAESOO, PAEDES, PAESUL , PAEVOL,&
 & PAER                                  )  

! ======================================================================

!**** *RADAER15  - COMPUTES DISTRIBUTION OF AEROSOLS
!****              FROZEN VERSION (CYCLE 15) OF RADAER

!     PURPOSE.
!     --------

!     - USE THE ECMWF CLIMATOLOGICAL AEROSOLS DISTRIBUTION
!                   SEE TANRE ET AL., 1984
!     - AVOID THE USE OF RADACT WHICH DOES NOT WORK ON A
!                   NON-ROTATED, UNSTRETCHED GRID.

!     WARNING.
!     --------

!     RADAER HAS BEEN TESTED FOR ARPEGE-CLIMAT ONLY. IN PARTICULAR
!     ONE SHOULD BE CAREFUL WHEN USING IT WITH SPACE INTERPOLATION
!     OR MEMORY PARTITION (SEE RADINT).

!**   INTERFACE.
!     ----------

!     CALL *RADAER15* FROM *APLPAR*

!        EXPLICIT ARGUMENTS :
!        --------------------

!        ==== INPUTS ===

! KIDIA  : LATITUDE INDEX OF 1-ST LATITUDE BAND IN VECTOR
! KFDIA  : LATITUDE INDEX OF LAST LATITUDE BAND IN VECTOR
! KPROMA : VECTOR LENGTH
! KTDIA  : INDEX OF TOP LEVEL FROM WHICH COMPUTATIONS ARE ACTIVE
! KLEV   : NUMBER OF LEVELS
! PAPRS  : (KPROMA,KLEV+1)      ; HALF LEVEL PRESSURE
! PAPRSF : (KPROMA,KLEV )       ; FULL LEVEL PRESSURE
! PT     : (KPROMA,KLEV)        ; FULL LEVEL TEMPERATURE
! PTS    : (KPROMA)             ; SURFACE TEMPERATURE
! PAESOO : (KPROMA)             ; SOOT AEROSOLS
! PAELAN : (KPROMA)             ; LAND AEROSOLS
! PAESEA : (KPROMA)             ; SEA AEROSOLS
! PAEDES : (KPROMA)             ; DESERT AEROSOLS
! PAESUL : (KPROMA)             ; SULFATE AEROSOLS
! PAEVOL : (KPROMA)             ; VOLCANO AEROSOLS

!        ==== OUTPUT ===

! PAER   : (KPROMA,KLEV,6)      ; OPTICAL THICKNESS OF THE AEROSOLS

!        IMPLICIT ARGUMENTS 
!        --------------------

!        NONE

!     METHOD.
!     -------

!     LAND, SEA, SOOT, DESERT AND SULFATE  AEROSOLS DISTRIBUTIONS ARE RED
!     FROM A FILE CONTAINING VARIOUS CLIMATOLOGIES AND COMBINED
!     HERE WITH VERTICAL PROFILES TO GET THE 3D DISTRIBUTION.

!     EXTERNALS.
!     ----------

!     NONE

!     REFERENCE.
!     ----------

!     SEE RADIATION'S PART OF THE MODEL'S DOCUMENTATION AND
!     ECMWF RESEARCH DEPARTMENT DOCUMENTATION OF THE "I.F.S"
!     FOR RADACT
!     J.-J. MORCRETTE E.C.M.W.F.   91/03/15 ORIGINAL RADACT SUBROUTINE

!     AUTHOR.
!     -------

!        96-11: Ph. Dandin. Meteo-France
!     ORIGINAL : Ph. DANDIN      METEO-FRANCE 94/11/14

!     MODIFICATIONS.
!     --------------
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!        F.Bouyssel    27-Sep-2004 Use of 6 aerosols
!        A.Alias       Dec-2005 GMGEC/EAC modif.
!           Hu Rong Ming. Sulphate aerosols
!           M. Deque new aerosols            
!           P. Marquet : Use of the Tegen values if LNEWAER15=.TRUE.
!           ->  Adaptation to CY24T1 for CLIMAT/V4.3 of the modifica-
!               tions prepared by F. Bouyssel (CNRM/GMAP/PROC) : see
!               the subroutine "RADACT"...
!           ->  The "black-carbone" (PAESOO) is added to the
!               "organic" (PAELAN)
!           ->  the "sulfate" is still put in a separate type
!               (see the work of Hu Ron Ming), whereas it is 
!               added to PAELAN in the new RADACT subroutine
!               (in CY28T1, with Tegen values)
!           ->  A limitation for ZAETRN and ZAETRO is introduced
!               for models with top above 10hPa
!           ->  Use of ZREPAER=1.E-12 = SECURITY PARAMETER FOR AEROSOLS
!       A.Alias        Dec-2007 Bug fix in Sulfate aerosol
!-----------------------------------------------------------------------

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

USE YOMCST   , ONLY : RG       ,RD
USE YOMRAD15 , ONLY : LNEWAER15
USE YOMAERD15, ONLY : CVDAES15 ,CVDAEL15 ,CVDAEU15 ,CVDAED15 ,&
 & CVDAEF15 ,&
 & RCAEOPS15,RCAEOPL15,RCAEOPU15,RCAEOPD15,RCTRBGA15,&
 & RCVOBGA15,RCSTBGA15,RCTRPT15  
USE SURFACE_FIELDS_MIX,ONLY : YSD_VAD


IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KPROMA 
INTEGER(KIND=JPIM),INTENT(IN)    :: KLEV 
INTEGER(KIND=JPIM),INTENT(IN)    :: KIDIA 
INTEGER(KIND=JPIM),INTENT(IN)    :: KFDIA 
INTEGER(KIND=JPIM)               :: KTDIA ! Argument NOT used
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPRS(KPROMA,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPRSF(KPROMA,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PT(KPROMA,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTS(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAESEA(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAELAN(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAESOO(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAEDES(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAESUL(KPROMA) 
REAL(KIND=JPRB)                  :: PAEVOL(KPROMA) ! Argument NOT used
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PAER(KPROMA,KLEV,6) 
!     -----------------------------------------------------------------

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

REAL(KIND=JPRB) ::Z_BURSUL(KPROMA)
!     -----------------------------------------------------------------

!*       0.2   LOCAL ARRAYS.
!              -------------

REAL(KIND=JPRB) :: ZTH(KPROMA,KLEV+1)
REAL(KIND=JPRB) :: ZDZHT(KPROMA,KLEV)
REAL(KIND=JPRB) :: ZZHHT(KPROMA,KLEV)
REAL(KIND=JPRB) :: Z_CMSUL(KPROMA,KLEV)
REAL(KIND=JPRB) :: Z_PASUL(KPROMA,KLEV)

REAL(KIND=JPRB) :: ZDPN  (KPROMA),ZDPO  (KPROMA)
REAL(KIND=JPRB) :: ZAEQSN(KPROMA),ZAEQSO(KPROMA)
REAL(KIND=JPRB) :: ZAEQLN(KPROMA),ZAEQLO(KPROMA)
REAL(KIND=JPRB) :: ZAEQUN(KPROMA),ZAEQUO(KPROMA)
REAL(KIND=JPRB) :: ZAEQDN(KPROMA),ZAEQDO(KPROMA)
REAL(KIND=JPRB) :: ZAETRN(KPROMA),ZAETRO(KPROMA)
REAL(KIND=JPRB) :: ZAEQFN(KPROMA),ZAEQFO(KPROMA)

INTEGER(KIND=JPIM) :: JK, JL, JAER, IAER

REAL(KIND=JPRB) :: ZAETR, ZDPNMO, ZGRTH, ZREPAER
REAL(KIND=JPRB) :: Z_COEFA, Z_COEFB, Z_HHTOA
REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

IF (LHOOK) CALL DR_HOOK('RADAER15',0,ZHOOK_HANDLE)
ZREPAER=1.E-12_JPRB
IAER=5
IF (YSD_VAD%NUMFLDS>4) THEN
  IAER=6
ENDIF

!*         1.     AEROSOL PARAMETERS COMPUTATIONS
!                 -------------------------------

! Aerosols come from files containing the climatologies.

!*         2.      VERTICAL DISTRIBUTION
!*                 ---------------------

!*         2.1    HALF-LEVEL TEMPERATURE
!*          =     TEMPERATURES AT LAYERS' BOUNDARIES.

! Half-level temperature interpolation weighted by pressure 
! just as in RADINT (loop 1222) but shortened...

DO JK=2,KLEV
  DO JL=KIDIA,KFDIA
    ZTH(JL,JK)=(PT(JL,JK-1)*PAPRSF(JL,JK-1)&
     & *(PAPRSF(JL,JK)-PAPRS(JL,JK))&
     & +PT(JL,JK)*PAPRSF(JL,JK)*(PAPRS(JL,JK)-PAPRSF(JL,JK-1)))&
     & *(1.0_JPRB/(PAPRS(JL,JK)*(PAPRSF(JL,JK)-PAPRSF(JL,JK-1))))  
  ENDDO
ENDDO

DO JL=KIDIA,KFDIA
  ZTH(JL,KLEV+1)=PTS(JL)
  ZTH(JL,1)=PT(JL,1)-PAPRSF(JL,1)*(PT(JL,1)-ZTH(JL,2))&
   & /(PAPRSF(JL,1)-PAPRS(JL,2))  
ENDDO

!*         2.2    VERTICAL DISTRIBUTIONS

IF (.NOT.LNEWAER15) THEN
  IF(YSD_VAD%NUMFLDS > 4) THEN
    DO JK=2,KLEV
      DO JL=KIDIA,KFDIA
        ZDZHT(JL,JK)=RD*PT(JL,JK)&
         & *(PAPRSF(JL,JK)-PAPRSF(JL,JK-1))&
         & /(PAPRSF(JL,JK)*RG)  
      ENDDO
    ENDDO
    
    DO JK=1,KLEV
      DO JL=KIDIA,KFDIA
        ZZHHT(JL,JK)=32.62_JPRB+RD*PT(JL,JK)&
         & *(LOG(PAPRSF(JL,KLEV))-LOG(PAPRSF(JL,JK)))/RG  
      ENDDO
    ENDDO
    
    DO JL=KIDIA,KFDIA
      Z_CMSUL(JL,1)=0.0_JPRB
      ZDZHT(JL,1)=0.0_JPRB
      Z_BURSUL(JL)=PAESUL(JL)/(5.0_JPRB*1.7_JPRB*1.0E-3_JPRB)
    ENDDO
    
    Z_HHTOA=10._JPRB
    Z_COEFB=1.0_JPRB
    Z_COEFA=Z_COEFB*1.0E-3_JPRB/(1.0_JPRB-EXP(-Z_COEFB*Z_HHTOA))
    
    DO JK=2,KLEV
      DO JL=KIDIA,KFDIA
        Z_CMSUL(JL,JK)=Z_COEFA*Z_BURSUL(JL)*EXP(-Z_COEFB*(ZZHHT(JL,JK)+&
         & ZZHHT(JL,JK-1))/2.0E3_JPRB)  
      ENDDO
    ENDDO
    
    DO JK=1,KLEV
      DO JL=KIDIA,KFDIA
        Z_PASUL(JL,JK)=Z_CMSUL(JL,JK)*ZDZHT(JL,JK)
        PAER(JL,JK,6)=Z_PASUL(JL,JK)*5.0_JPRB*1.7_JPRB*1.0E-3_JPRB
      ENDDO
    ENDDO
  ELSE
    DO JK=1,KLEV
      DO JL=KIDIA,KFDIA
        PAER(JL,JK,6)= 0.0_JPRB
      ENDDO
    ENDDO
  ENDIF
ENDIF


DO JL=KIDIA,KFDIA
  ZDPO(JL)=PAPRS (JL,1)
  IF (LNEWAER15) THEN
    ZAEQSO(JL)=PAESEA(JL)*CVDAES15(1)
    ZAEQLO(JL)=PAELAN(JL)*CVDAEL15(1)
    ZAEQUO(JL)=PAESOO(JL)*CVDAEU15(1)
    ZAEQDO(JL)=PAEDES(JL)*CVDAED15(1)
    ZAEQFO(JL)=PAESUL(JL)*CVDAEF15(1)
  ELSE
    ZAEQSO(JL)=RCAEOPS15*PAESEA(JL)*CVDAES15(1)
    ZAEQLO(JL)=RCAEOPL15*PAELAN(JL)*CVDAEL15(1)
    ZAEQUO(JL)=RCAEOPU15*PAESOO(JL)*CVDAEU15(1)
    ZAEQDO(JL)=RCAEOPD15*PAEDES(JL)*CVDAED15(1)
  ENDIF
  ZAETRO(JL)=1.0_JPRB
ENDDO

DO JK=1,KLEV
  DO JL=KIDIA,KFDIA
    ZGRTH= ZTH(JL,JK)/ZTH(JL,JK+1)
    ZDPN(JL)=PAPRS (JL,JK+1)

    IF (LNEWAER15) THEN
      ZAEQSN(JL)=PAESEA(JL)*CVDAES15(JK+1)
      ZAEQLN(JL)=PAELAN(JL)*CVDAEL15(JK+1)
      ZAEQUN(JL)=PAESOO(JL)*CVDAEU15(JK+1)
      ZAEQDN(JL)=PAEDES(JL)*CVDAED15(JK+1)
      ZAEQFN(JL)=PAESUL(JL)*CVDAEF15(JK+1)
    ELSE
      ZAEQSN(JL)=RCAEOPS15*PAESEA(JL)*CVDAES15(JK+1)
      ZAEQLN(JL)=RCAEOPL15*PAELAN(JL)*CVDAEL15(JK+1)
      ZAEQUN(JL)=RCAEOPU15*PAESOO(JL)*CVDAEU15(JK+1)
      ZAEQDN(JL)=RCAEOPD15*PAEDES(JL)*CVDAED15(JK+1)
    ENDIF
    IF (0.5_JPRB*(PAPRS(JL,JK)+PAPRS(JL,JK+1)) < 999._JPRB) THEN
      ZAETRN(JL)=1.0_JPRB
      ZAETRO(JL)=1.0_JPRB
    ELSE
!     ZAETRN(JL)=ZAETRO(JL)*(MIN(1.,ZTH(JL,JK)/ZTH(JL,JK+1)))**RCTRPT15
      ZAETRN(JL)=ZAETRO(JL)*(MIN(1.0_JPRB,     ZGRTH       ))**RCTRPT15
    ENDIF
    ZAETR =SQRT(ZAETRN(JL)*ZAETRO(JL))
    ZDPNMO=ZDPN(JL)-ZDPO(JL)
    IF (LNEWAER15) THEN
      PAER(JL,JK,1)=(1.0_JPRB-ZAETR)*(RCTRBGA15*ZDPNMO &
       & + ZAEQLN(JL)-ZAEQLO(JL))
      PAER(JL,JK,2)=(1.0_JPRB-ZAETR)*(ZAEQSN(JL)-ZAEQSO(JL))
      PAER(JL,JK,3)=(1.0_JPRB-ZAETR)*(ZAEQDN(JL)-ZAEQDO(JL))
      PAER(JL,JK,4)= ZAETR * RCVOBGA15*ZDPNMO
      PAER(JL,JK,5)= ZAETR * RCSTBGA15*ZDPNMO
      PAER(JL,JK,6)=(1.0_JPRB-ZAETR)*(ZAEQFN(JL)-ZAEQFO(JL)) 
    ELSE
      PAER(JL,JK,1)=(1.0_JPRB-ZAETR)*(RCTRBGA15*ZDPNMO &
       & + ZAEQLN(JL)-ZAEQLO(JL) + ZAEQDN(JL)-ZAEQDO(JL))
      PAER(JL,JK,2)=(1.0_JPRB-ZAETR)*(ZAEQSN(JL)-ZAEQSO(JL))
      PAER(JL,JK,3)=(1.0_JPRB-ZAETR)*(ZAEQUN(JL)-ZAEQUO(JL))
      PAER(JL,JK,4)= ZAETR * RCVOBGA15*ZDPNMO
      PAER(JL,JK,5)= ZAETR * RCSTBGA15*ZDPNMO
      ! the sulfate array PAER(...,6) is set in the section 2.2 above
    ENDIF

!* Specific computations for sulfate aerosols PAER(JL,JK,6) 
!  (use of Penner data, by Hu Rong Ming, June 1999)

!**** **************************************************
!**** **************************************************
  ENDDO
  IF (LNEWAER15) THEN
    IF (YSD_VAD%NUMFLDS > 4) THEN
      DO JL=KIDIA,KFDIA
        PAER(JL,JK,1)= PAER(JL,JK,1) + (1.0_JPRB-ZAETR)* &
         & (ZAEQUN(JL)-ZAEQUO(JL))
      ENDDO
    ENDIF
    DO JAER=1,IAER
      DO JL=KIDIA,KFDIA
        PAER(JL,JK,JAER)=MAX(PAER(JL,JK,JAER),ZREPAER)
      ENDDO
    ENDDO
  ENDIF
  DO JL=KIDIA,KFDIA
    ZDPO(JL)=ZDPN(JL)
    ZAEQSO(JL)=ZAEQSN(JL)
    ZAEQLO(JL)=ZAEQLN(JL)
    ZAEQUO(JL)=ZAEQUN(JL)
    ZAEQDO(JL)=ZAEQDN(JL)
    ZAEQFO(JL)=ZAEQFN(JL)
    ZAETRO(JL)=ZAETRN(JL)
  ENDDO

ENDDO

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

IF (LHOOK) CALL DR_HOOK('RADAER15',1,ZHOOK_HANDLE)
END SUBROUTINE RADAER15
