SUBROUTINE SWTT1AD &
 & ( KIDIA, KFDIA, KLON, KNU, KABS, KIND,&
 & PU5,&
 & PTR5,&
 & PU,&
 & PTR  &
 & )  

!**** *SWTT1AD* - COMPUTES THE SHORTWAVE TRANSMISSION FUNCTIONS
!                 -> ADJOINT <-

!     PURPOSE.
!     --------
!           THIS ROUTINE COMPUTES THE TRANSMISSION FUNCTIONS FOR ALL THE
!     ABSORBERS (H2O, UNIFORMLY MIXED GASES, AND O3) IN THE TWO SPECTRAL
!     INTERVALS.

!**   INTERFACE.
!     ----------
!          *SWTT1AD* IS CALLED FROM *SWUAD*, *SW1SAD*.

!        EXPLICIT ARGUMENTS :
!        --------------------
! KNU    :                     ; INDEX OF THE SPECTRAL INTERVAL
! KABS   :                     ; NUMBER OF ABSORBERS
! KIND   : (KABS)              ; INDICES OF THE ABSORBERS
! PU     : (KLON,KABS)         ; ABSORBER AMOUNT
!     ==== OUTPUTS ===
! PTR    : (KLON,KABS)         ; TRANSMISSION FUNCTION

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

!     METHOD.
!     -------

!          TRANSMISSION FUNCTION ARE COMPUTED USING PADE APPROXIMANTS
!     AND HORNER'S ALGORITHM.

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

!          NONE

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

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

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

!     MODIFICATIONS.
!     --------------
!        ORIGINAL : 96-10-17
!        03-10-10 Deborah Salmond and Marta Janiskova Optimisation
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!        M.Janiskova   18-Mar-2008 code optimization

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

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

USE YOESW    , ONLY : APAD     ,BPAD     ,D

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KLON 
INTEGER(KIND=JPIM),INTENT(IN)    :: KABS 
INTEGER(KIND=JPIM),INTENT(IN)    :: KIDIA 
INTEGER(KIND=JPIM),INTENT(IN)    :: KFDIA 
INTEGER(KIND=JPIM),INTENT(IN)    :: KNU 
INTEGER(KIND=JPIM),INTENT(IN)    :: KIND(KABS) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PU5(KLON,KABS) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PTR5(KLON,KABS) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PU(KLON,KABS) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PTR(KLON,KABS) 
!-----------------------------------------------------------------------

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

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

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

REAL(KIND=JPRB) :: ZR15(KLON), ZR25(KLON), ZU5(KLON)
REAL(KIND=JPRB) :: ZR1(KLON) , ZR2(KLON) , ZU(KLON)
REAL(KIND=JPRB) :: ZRR5

INTEGER(KIND=JPIM) :: IA, JA, JL
REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

!*         1.      HORNER'S ALGORITHM TO COMPUTE TRANSMISSION FUNCTION

! 100 CONTINUE

IF (LHOOK) CALL DR_HOOK('SWTT1AD',0,ZHOOK_HANDLE)
DO JA = 1,KABS
  IA=KIND(JA)
  DO JL = KIDIA,KFDIA
    ZU5(JL) = PU5(JL,JA)

    ZR15(JL)= APAD(KNU,IA,1) + ZU5(JL) * (APAD(KNU,IA,2) + ZU5(JL)&
     & * ( APAD(KNU,IA,3) + ZU5(JL) * (APAD(KNU,IA,4) + ZU5(JL)&
     & * ( APAD(KNU,IA,5) + ZU5(JL) * (APAD(KNU,IA,6) + ZU5(JL)&
     & * ( APAD(KNU,IA,7) ))))))  

    ZR25(JL)= BPAD(KNU,IA,1) + ZU5(JL) * (BPAD(KNU,IA,2) + ZU5(JL)&
     & * ( BPAD(KNU,IA,3) + ZU5(JL) * (BPAD(KNU,IA,4) + ZU5(JL)&
     & * ( BPAD(KNU,IA,5) + ZU5(JL) * (BPAD(KNU,IA,6) + ZU5(JL)&
     & * ( BPAD(KNU,IA,7) ))))))  
    ZRR5=1.0_JPRB/ZR25(JL)

!*         2.      ADD THE BACKGROUND TRANSMISSION

! 200 CONTINUE

    PTR5(JL,JA) = (ZR15(JL)*ZRR5) * (1.0_JPRB-D(KNU,IA)) + D(KNU,IA)

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

!          10.     ADJOINT COMPUTATIONS
!                  --------------------

    ZR1(JL)=0.0_JPRB
    ZR2(JL)=0.0_JPRB
    ZU(JL) =0.0_JPRB

!*         2.      ADD THE BACKGROUND TRANSMISSION

    ZR1(JL) = ZR1(JL) + (1.0_JPRB-D(KNU,IA))*PTR(JL,JA)*ZRR5
    ZR2(JL) = ZR2(JL) - (1.0_JPRB-D(KNU,IA))*PTR(JL,JA)*ZR15(JL)*ZRR5**2
    PTR(JL,JA) = 0.0_JPRB

!*         1.      HORNER'S ALGORITHM TO COMPUTE TRANSMISSION FUNCTION

    ZU(JL) = ZU(JL) + ZR2(JL)           *( BPAD(KNU,IA,2) +&
     & ZU5(JL)&
     & * ( 2*BPAD(KNU,IA,3) + ZU5(JL)*( 3*BPAD(KNU,IA,4) + ZU5(JL)&
     & * ( 4*BPAD(KNU,IA,5) + ZU5(JL)*( 5*BPAD(KNU,IA,6) + ZU5(JL)&
     & * ( 6*BPAD(KNU,IA,7) ))))))  
!    ZR2(JL) = 0.0_JPRB

    ZU(JL) = ZU(JL) + ZR1(JL)           *( APAD(KNU,IA,2) +&
     & ZU5(JL)&
     & * ( 2*APAD(KNU,IA,3) + ZU5(JL)*( 3*APAD(KNU,IA,4) + ZU5(JL)&
     & * ( 4*APAD(KNU,IA,5) + ZU5(JL)*( 5*APAD(KNU,IA,6) + ZU5(JL)&
     & * ( 6*APAD(KNU,IA,7) ))))))  
!    ZR1(JL) = 0.0_JPRB

    PU(JL,JA) = PU(JL,JA) + ZU(JL)
!    ZU(JL) = 0.0_JPRB

  ENDDO

ENDDO

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

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