!OPTIONS XOPT(NOEVAL)
SUBROUTINE LWU15 ( KIDIA,KFDIA,KLON,KLEV,KAER,KMODE,KFLUX,KRAD,&
 & PAER,PCCO2,PDP,PPMB,PPSOL,PQOF,PTAVE,PVIEW,PWV,&
 & PABCU     )  

!**** *LWU15* - LONGWAVE EFFECTIVE ABSORBER AMOUNTS
!****           FROZEN VERSION (CYCLE 15) OF LWU

!     PURPOSE.
!     --------
!           COMPUTES ABSORBER AMOUNTS INCLUDING PRESSURE AND
!           TEMPERATURE EFFECTS

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

!        EXPLICIT ARGUMENTS :
!        --------------------
!     ==== INPUTS ===
! PAER   : (KLON,KLEV,5)     ; OPTICAL THICKNESS OF THE AEROSOLS
! PCCO2  :                   ; CONCENTRATION IN CO2 (PA/PA)
! PDP    : (KLON,KLEV)       ; LAYER PRESSURE THICKNESS (PA)
! PPMB   : (KLON,KLEV+1)     ; HALF LEVEL PRESSURE
! PPSOL  : (KLON)            ; SURFACE PRESSURE
! PQOF   : (KLON,KLEV)       ; CONCENTRATION IN OZONE (PA/PA)
! PTAVE  : (KLON,KLEV)       ; TEMPERATURE
! PWV    : (KLON,KLEV)       ; SPECIFIC HUMIDITY PA/PA
! PVIEW  : (KLON)            ; COSECANT OF VIEWING ANGLE
!     ==== OUTPUTS ===
! PABCU  :(KLON,NUA15,3*KLEV+1); EFFECTIVE ABSORBER AMOUNTS

!        IMPLICIT ARGUMENTS :   NONE
!        --------------------

!     METHOD.
!     -------

!          1. COMPUTES THE PRESSURE AND TEMPERATURE WEIGHTED AMOUNTS OF
!     ABSORBERS.

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

!          NONE

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

!        SEE RADIATION'S PART OF THE MODEL'S DOCUMENTATION AND
!        ECMWF RESEARCH DEPARTMENT DOCUMENTATION OF THE IFS

!     AUTHOR.
!     -------
!        96-11: Ph. Dandin. Meteo-France
!        ORIGINAL : 89-07-14 BY JEAN-JACQUES MORCRETTE  *ECMWF*

!     MODIFICATIONS.
!     --------------
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!        A.Alias       19-09-2005 sulfate aerosols (Hu Rong Ming)
!-----------------------------------------------------------------------

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

USE YOMCST   , ONLY : RG
USE YOMAER15 , ONLY : RAER15
USE YOMLW15  , ONLY : NINT15   ,NUA15    ,NG115    ,NG1P115  ,&
 & AT15     ,BT15     ,OCT15    ,RT115    ,TREF15   ,&
 & RVGCO215 ,RVGH2O15 ,RVGO315  
USE YOMRDI15 , ONLY : RCH415   ,RN2O15   ,RCFC1115 ,RCFC1215
USE YOMRDU15 , ONLY : R10E15   ,REPSCO15 ,REPSCQ15

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KLON 
INTEGER(KIND=JPIM),INTENT(IN)    :: KLEV 
INTEGER(KIND=JPIM),INTENT(IN)    :: KIDIA 
INTEGER(KIND=JPIM),INTENT(IN)    :: KFDIA 
INTEGER(KIND=JPIM)               :: KAER ! Argument NOT used
INTEGER(KIND=JPIM)               :: KMODE ! Argument NOT used
INTEGER(KIND=JPIM)               :: KFLUX ! Argument NOT used
INTEGER(KIND=JPIM)               :: KRAD ! Argument NOT used
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAER(KLON,KLEV,6) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCCO2 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDP(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PPMB(KLON,KLEV+1) 
REAL(KIND=JPRB)                  :: PPSOL(KLON) ! Argument NOT used
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQOF(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTAVE(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVIEW(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PWV(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PABCU(KLON,NUA15,3*KLEV+1) 
!-----------------------------------------------------------------------

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

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

!              ------------
REAL(KIND=JPRB) :: ZABLY(KLON,NUA15,3*KLEV+1), ZDUC(KLON, 3*KLEV+1)
REAL(KIND=JPRB) :: ZPHIO(KLON),ZPSC2(KLON),ZPSC3(KLON),ZPSH1(KLON)&
 & ,  ZPSH2(KLON),ZPSH3(KLON),ZPSH4(KLON),ZPSH5(KLON)&
 & ,  ZPSH6(KLON),ZPSIO(KLON),ZTCON(KLON)&
 & ,  ZPHM6(KLON),ZPSM6(KLON),ZPHN6(KLON),ZPSN6(KLON)  
REAL(KIND=JPRB) :: ZSSIG(KLON,3*KLEV+1), ZTAVI(KLON)&
 & ,  ZUAER(KLON,NINT15), ZXOZ(KLON), ZXWV(KLON)  

INTEGER(KIND=JPIM) :: IG1, IKL, JA, JAE, JAE1, JAE2, JAE3, JC,&
 & JCP1, JJ, JJPN, JK, JKI, JKIP1, JKJ, JKJP, &
 & JKJPN, JKJR, JKK, JL  

REAL(KIND=JPRB) :: ZALUP, ZCAC8, ZCAH1, ZCAH2, ZCAH3, ZCAH4,&
 & ZCAH5, ZCAH6, ZCBC8, ZCBH1, ZCBH2, ZCBH3, &
 & ZCBH4, ZCBH5, ZCBH6, ZDIFF, ZDPM, ZFPPW, &
 & ZTX, ZTX2, ZU6, ZUP, ZUPM, ZUPMCO2, ZUPMH2O, &
 & ZUPMO3, ZZABLY  
REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

!*         1.    INITIALIZATION
!                --------------

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

!*         2.    PRESSURE OVER GAUSS SUB-LEVELS
!                ------------------------------

IF (LHOOK) CALL DR_HOOK('LWU15',0,ZHOOK_HANDLE)
DO JL = KIDIA,KFDIA
  ZSSIG(JL, 1 ) = PPMB(JL,1) * 100._JPRB
ENDDO

DO JK = 1 , KLEV
  JKJ=(JK-1)*NG1P115+1
  JKJR = JKJ
  JKJP = JKJ + NG1P115
  DO JL = KIDIA,KFDIA
    ZSSIG(JL,JKJP)=PPMB(JL,JK+1)* 100._JPRB
  ENDDO
  DO IG1=1,NG115
    JKJ=JKJ+1
    DO JL = KIDIA,KFDIA
      ZSSIG(JL,JKJ)= (ZSSIG(JL,JKJR)+ZSSIG(JL,JKJP))*0.5_JPRB &
       & + RT115(IG1) * (ZSSIG(JL,JKJP) - ZSSIG(JL,JKJR)) * 0.5_JPRB  
    ENDDO
  ENDDO
ENDDO

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

!*         4.    PRESSURE THICKNESS AND MEAN PRESSURE OF SUB-LAYERS
!                --------------------------------------------------

DO JKI=1,3*KLEV
  JKIP1=JKI+1
  DO JL = KIDIA,KFDIA
    ZABLY(JL,5,JKI)=(ZSSIG(JL,JKI)+ZSSIG(JL,JKIP1))*0.5_JPRB
    ZABLY(JL,3,JKI)=(ZSSIG(JL,JKI)-ZSSIG(JL,JKIP1))/(10._JPRB*RG)
  ENDDO
ENDDO

DO JK = 1 , KLEV
  IKL = KLEV+1 - JK
  DO JL = KIDIA,KFDIA
    ZXWV(JL) = MAX (PWV(JL,IKL) , REPSCQ15 )
    ZXOZ(JL) = MAX (PQOF(JL,IKL) / PDP(JL,IKL) , REPSCO15 )
  ENDDO
  JKJ=(JK-1)*NG1P115+1
  JKJPN=JKJ+NG115
  DO JKK=JKJ,JKJPN
    DO JL = KIDIA,KFDIA
      ZDPM = ZABLY(JL,3,JKK)
      ZUPM = ZABLY(JL,5,JKK)             * ZDPM / 101325._JPRB
      ZUPMCO2 = ( ZABLY(JL,5,JKK) + RVGCO215 ) * ZDPM / 101325._JPRB
      ZUPMH2O = ( ZABLY(JL,5,JKK) + RVGH2O15 ) * ZDPM / 101325._JPRB
      ZUPMO3  = ( ZABLY(JL,5,JKK) + RVGO315  ) * ZDPM / 101325._JPRB
      ZDUC(JL,JKK) = ZDPM
      ZABLY(JL,12,JKK) = ZXOZ(JL) * ZDPM
      ZABLY(JL,13,JKK) = ZXOZ(JL) * ZUPMO3
      ZU6 = ZXWV(JL) * ZUPM
      ZFPPW = 1.6078_JPRB * ZXWV(JL) / (1.0_JPRB+0.608_JPRB*ZXWV(JL))
      ZABLY(JL,6,JKK) = ZXWV(JL) * ZUPMH2O
      ZABLY(JL,11,JKK) = ZU6 * ZFPPW
      ZABLY(JL,10,JKK) = ZU6 * (1.0_JPRB-ZFPPW)
      ZABLY(JL,9,JKK) = PCCO2 * ZUPMCO2
      ZABLY(JL,8,JKK) = PCCO2 * ZDPM
    ENDDO
  ENDDO
ENDDO

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

!*         5.    CUMULATIVE ABSORBER AMOUNTS FROM TOP OF ATMOSPHERE
!                --------------------------------------------------

DO JA = 1, NUA15
  DO JL = KIDIA,KFDIA
    PABCU(JL,JA,3*KLEV+1) = 0.0_JPRB
  ENDDO
ENDDO

DO JK = 1 , KLEV
  JJ=(JK-1)*NG1P115+1
  JJPN=JJ+NG115
  IKL=KLEV+1-JK

!*         5.1  CUMULATIVE AEROSOL AMOUNTS FROM TOP OF ATMOSPHERE
!               --------------------------------------------------
! --            NB: 'PAER' AEROSOLS ARE ENTERED FROM TOP TO BOTTOM

  JAE1=3*KLEV+1-JJ
  JAE2=3*KLEV+1-(JJ+1)
  JAE3=3*KLEV+1-JJPN
  DO JAE=1,5
    DO JL = KIDIA,KFDIA
      ZUAER(JL,JAE) = (RAER15(JAE,1)*PAER(JL,JK,1)&
       & +RAER15(JAE,2)*PAER(JL,JK,2)+RAER15(JAE,3)*PAER(JL,JK,3)&
       & +RAER15(JAE,4)*PAER(JL,JK,4)+RAER15(JAE,5)*PAER(JL,JK,5)&
       & +RAER15(JAE,6)*PAER(JL,JK,6))&
       & /(ZDUC(JL,JAE1)+ZDUC(JL,JAE2)+ZDUC(JL,JAE3))  
    ENDDO
  ENDDO

!*         5.2  INTRODUCES TEMPERATURE EFFECTS ON ABSORBER AMOUNTS
!               --------------------------------------------------

  DO JL = KI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,1)+ZUP*(BT15(6,2)+ZUP*(BT15(6,3)))
    ZPSH6(JL)=EXP( ZCAH6 * ZTX + ZCBH6 * ZTX2 )
    ZPHM6(JL)=EXP(-5.81E-4_JPRB * ZTX - 1.13E-6_JPRB * ZTX2 )
    ZPSM6(JL)=EXP(-5.57E-4_JPRB * ZTX - 3.30E-6_JPRB * ZTX2 )
    ZPHN6(JL)=EXP(-3.46E-5_JPRB * ZTX + 2.05E-7_JPRB * ZTX2 )
    ZPSN6(JL)=EXP( 3.70E-3_JPRB * ZTX - 2.30E-6_JPRB * ZTX2 )
  ENDDO

  DO JL = KIDIA,KFDIA
    ZTAVI(JL)=PTAVE(JL,IKL)
    ZTX=ZTAVI(JL)-TREF15
    ZTX2=ZTX*ZTX
    ZZABLY = ZABLY(JL,9,JAE1)+ZABLY(JL,9,JAE2)+ZABLY(JL,9,JAE3)
    ZALUP = R10E15 * LOG ( ZZABLY )
    ZUP   = MAX( 0.0_JPRB , 5.0_JPRB + 0.5_JPRB * ZALUP )
    ZPSC2(JL) = (ZTAVI(JL)/TREF15) ** ZUP
    ZCAC8=AT15(8,1)+ZUP*(AT15(8,2)+ZUP*(AT15(8,3)))
    ZCBC8=BT15(8,1)+ZUP*(BT15(8,2)+ZUP*(BT15(8,3)))
    ZPSC3(JL)=EXP( ZCAC8 * ZTX + ZCBC8 * ZTX2 )
    ZPHIO(JL) = EXP( OCT15(1) * ZTX + OCT15(2) * ZTX2)
    ZPSIO(JL) = EXP( 2.0_JPRB* (OCT15(3)*ZTX+OCT15(4)*ZTX2))
  ENDDO

  DO JKK=JJ,JJPN
    JC=3*KLEV+1-JKK
    JCP1=JC+1
    DO JL = KIDIA,KFDIA
      ZDIFF = PVIEW(JL)
      PABCU(JL,10,JC)=PABCU(JL,10,JCP1)+ZABLY(JL,10,JC)           *ZDIFF
      PABCU(JL,11,JC)=PABCU(JL,11,JCP1)+ZABLY(JL,11,JC)*ZTCON(JL)*ZDIFF

      PABCU(JL,12,JC)=PABCU(JL,12,JCP1)+ZABLY(JL,12,JC)*ZPHIO(JL)*ZDIFF
      PABCU(JL,13,JC)=PABCU(JL,13,JCP1)+ZABLY(JL,13,JC)*ZPSIO(JL)*ZDIFF

      PABCU(JL,7,JC)=PABCU(JL,7,JCP1)+ZABLY(JL,9,JC)*ZPSC2(JL)*ZDIFF
      PABCU(JL,8,JC)=PABCU(JL,8,JCP1)+ZABLY(JL,9,JC)*ZPSC3(JL)*ZDIFF
      PABCU(JL,9,JC)=PABCU(JL,9,JCP1)+ZABLY(JL,9,JC)*ZPSC3(JL)*ZDIFF

      PABCU(JL,1,JC)=PABCU(JL,1,JCP1)+ZABLY(JL,6,JC)*ZPSH1(JL)*ZDIFF
      PABCU(JL,2,JC)=PABCU(JL,2,JCP1)+ZABLY(JL,6,JC)*ZPSH2(JL)*ZDIFF
      PABCU(JL,3,JC)=PABCU(JL,3,JCP1)+ZABLY(JL,6,JC)*ZPSH5(JL)*ZDIFF
      PABCU(JL,4,JC)=PABCU(JL,4,JCP1)+ZABLY(JL,6,JC)*ZPSH3(JL)*ZDIFF
      PABCU(JL,5,JC)=PABCU(JL,5,JCP1)+ZABLY(JL,6,JC)*ZPSH4(JL)*ZDIFF
      PABCU(JL,6,JC)=PABCU(JL,6,JCP1)+ZABLY(JL,6,JC)*ZPSH6(JL)*ZDIFF

      PABCU(JL,14,JC)=PABCU(JL,14,JCP1)+ZUAER(JL,1)    *ZDUC(JL,JC)*ZDIFF
      PABCU(JL,15,JC)=PABCU(JL,15,JCP1)+ZUAER(JL,2)    *ZDUC(JL,JC)*ZDIFF
      PABCU(JL,16,JC)=PABCU(JL,16,JCP1)+ZUAER(JL,3)    *ZDUC(JL,JC)*ZDIFF
      PABCU(JL,17,JC)=PABCU(JL,17,JCP1)+ZUAER(JL,4)    *ZDUC(JL,JC)*ZDIFF
      PABCU(JL,18,JC)=PABCU(JL,18,JCP1)+ZUAER(JL,5)    *ZDUC(JL,JC)*ZDIFF

      PABCU(JL,19,JC)=PABCU(JL,19,JCP1)&
       & +ZABLY(JL,8,JC)*RCH415/PCCO2*ZPHM6(JL)*ZDIFF  
      PABCU(JL,20,JC)=PABCU(JL,20,JCP1)&
       & +ZABLY(JL,9,JC)*RCH415/PCCO2*ZPSM6(JL)*ZDIFF  
      PABCU(JL,21,JC)=PABCU(JL,21,JCP1)&
       & +ZABLY(JL,8,JC)*RN2O15/PCCO2*ZPHN6(JL)*ZDIFF  
      PABCU(JL,22,JC)=PABCU(JL,22,JCP1)&
       & +ZABLY(JL,9,JC)*RN2O15/PCCO2*ZPSN6(JL)*ZDIFF  

      PABCU(JL,23,JC)=PABCU(JL,23,JCP1)&
       & +ZABLY(JL,8,JC)*RCFC1115/PCCO2         *ZDIFF  
      PABCU(JL,24,JC)=PABCU(JL,24,JCP1)&
       & +ZABLY(JL,8,JC)*RCFC1215/PCCO2         *ZDIFF  
    ENDDO
  ENDDO

ENDDO

IF (LHOOK) CALL DR_HOOK('LWU15',1,ZHOOK_HANDLE)

!-----------------------------------------------------------------------
!                       FORMATS
!                       -------

884 FORMAT (1X,F7.2,18F6.1,F7.2)
886 FORMAT (1X,20I5)
888 FORMAT (1X,13E9.2)
890 FORMAT (1X,2I4,13F9.2)
9100 FORMAT (1X,' LWU  END 100')
9200 FORMAT (1X,' LWU  END 200')
9300 FORMAT (1X,' LWU  END 300')
9400 FORMAT (1X,' LWU  END 400')
9401 FORMAT (1X,' LWU ',21F5.2)
9404 FORMAT (1X,' LWU ',I3,9E13.7)
9502 FORMAT (1X,' LWU ',6I5)
9509 FORMAT (10(/,1X,32F4.0))
9510 FORMAT (1X,' LWU  END 510')
9511 FORMAT (1X,' LWU ZUAER ',5E13.7)
9521 FORMAT (1X,' LWU  END 521',I3,4E13.7)
9522 FORMAT (1X,' LWU  END 522')
9529 FORMAT (1X,' LWU  END 529')

END SUBROUTINE LWU15
