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

!**** *SWTT1TL* - COMPUTES THE SHORTWAVE TRANSMISSION FUNCTIONS
!                 -> TANGENT LINEAR <-

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

!**   INTERFACE.
!     ----------
!          *SWTT1TL* IS CALLED FROM *SWUTL*, *SW1STL*.

!        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-09-26
!        03-10-10 Deborah Salmond and Marta Janiskova Optimisation
!        M.Hamrud      01-Oct-2003 CY28 Cleaning

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

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(IN)    :: PU(KLON,KABS) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: 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) :: ZRR,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('SWTT1TL',0,ZHOOK_HANDLE)
DO JA = 1,KABS
  IA=KIND(JA)
  DO JL = KIDIA,KFDIA
    ZU (JL) = PU (JL,JA)
    ZU5(JL) = PU5(JL,JA)
    ZR1 (JL) = ZU(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) ))))))  

    ZR2 (JL) = ZU(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) ))))))  

    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)
    ZRR= -ZR2(JL)*ZRR5**2

!*         2.      ADD THE BACKGROUND TRANSMISSION

! 200 CONTINUE

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

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