SUBROUTINE SWUVO3AD &
 & ( KIDIA,KFDIA,KLON,KNU,KABS,&
 & PU5, PTR5,&
 & PU , PTR  )  
  
!**** *SWUVO3AD* - COMPUTES THE SHORTWAVE TRANSMISSION FUNCTIONS
!                -> ADJOINT <-

!     PURPOSE.
!     --------
!           THIS ROUTINE COMPUTES THE TRANSMISSION FUNCTIONS FOR OZONE
!     IN THE UV and VISIBLE SPECTRAL INTERVALS.

!**   INTERFACE.
!     ----------
!          *SWUVO3AD* IS CALLED FROM *SW1SAD*.

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

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

!     METHOD.
!     -------

!          TRANSMISSION FUNCTION ARE COMPUTED USING SUMS OF EXPONENTIALS

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

!          NONE

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

!     AUTHOR.
!     -------
!        Marta Janiskova  *ECMWF*

!     MODIFICATIONS.
!     --------------
!        ORIGINAL : 2002-05-09
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
   
!-----------------------------------------------------------------------

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

USE YOESW    , ONLY : NEXPO3, REXPO3

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 
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) :: ZU5(KLON,KABS)
REAL(KIND=JPRB) :: ZU(KLON)

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

IF (LHOOK) CALL DR_HOOK('SWUVO3AD',0,ZHOOK_HANDLE)
IEXP=NEXPO3(KNU)

DO JA = 1,KABS
  DO JL=KIDIA,KFDIA
    PTR5(JL,JA)=0.0_JPRB
  ENDDO
    
  DO JX=1,IEXP
    DO JL = KIDIA,KFDIA
      ZU5(JL,JA) = PU5(JL,JA)
      PTR5(JL,JA) = PTR5(JL,JA)+REXPO3(KNU,1,JX) &
       & * EXP(-REXPO3(KNU,2,JX)*ZU5(JL,JA))  
    ENDDO
  ENDDO    
ENDDO

!  -----------------------------------------------------------
!        -------  ADJOINT COMPUTATION --------
!  -----------------------------------------------------------

!*   Initialization

ZU(:) = 0.0_JPRB

DO JA = KABS,1,-1
  
  DO JX=IEXP,1,-1
    DO JL = KIDIA,KFDIA
      ZU(JL) = ZU(JL) - REXPO3(KNU,1,JX)*REXPO3(KNU,2,JX) &
       & * EXP(-REXPO3(KNU,2,JX)*ZU5(JL,JA))*PTR(JL,JA)  
      PU(JL,JA) = PU(JL,JA) + ZU(JL)
      ZU(JL) = 0.0_JPRB
    ENDDO
  ENDDO

  DO JL=KIDIA,KFDIA
    PTR(JL,JA) =0.0_JPRB
  ENDDO
ENDDO
  
IF (LHOOK) CALL DR_HOOK('SWUVO3AD',1,ZHOOK_HANDLE)
END SUBROUTINE SWUVO3AD
