SUBROUTINE LWVTL &
 & ( KIDIA, KFDIA, KLON , KLEV , KUAER , KTRAER,&
 & PGA    , PGB   , PGASUR , PGBSUR, PGATOP , PGBTOP,& 
 & PABCU5 , PB5   , PBINT5 , PBSUR5, PBTOP5 , PDBSL5,&
 & PEMIS5 , PEMIW5,&
 & PCNTRB5, PFLUC5,&
 & PABCU  , PB    , PBINT  , PBSUR , PBTOP  , PDBSL,&
 & PEMIS  , PEMIW ,&
 & PCNTRB , PFLUC &
 & )  

!**** *LWVTL*   - LONGWAVE RADIATION, VERTICAL INTEGRATION
!                      (tangent linear)

!     PURPOSE.
!     --------
!           CARRIES OUT THE VERTICAL INTEGRATION TO GIVE LONGWAVE
!           FLUXES OR RADIANCES

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

!        EXPLICIT ARGUMENTS :
!        --------------------
!     ==== INPUTS ===
!  Trajectory  Perturbation  Description                         Dimension
!  PABCU5      PABCU         ABSORBER AMOUNTS               (KLON,NUA,3*KLEV+1)
!  PB5         PB            SPECTRAL HALF-LEVEL PLANCK
!                            FUNCTIONS                       (KLON,NSIL,KLEV+1)
!  PBINT5      PBINT         HALF-LEVEL PLANCK FUNCTIONS          (KLON,KLEV+1)
!  PBSUR5      PBSUR         SPECTRAL SURFACE PLANCK FUNCTION     (KLON,NSIL)
!  PBTOP5      PBTOP         SPECTRAL T.O.A. PLANCK FUNCTION      (KLON,NSIL)
!  PDBSL5      PDBSL         SUB-LAYER PLANCK FUNCTION GRADIENT   (KLON,KLEV*2)
!  PEMIS5      PEMIS         SURFACE LW EMISSIVITY                (KLON)
!  PEMIW5      PEMIW         SURFACE LW WINDOW EMISSIVITY         (KLON)
!  PGA         ---           PADE APPROXIMANTS               (KLON,NIPD,2,KLEV)
!  PGB         ---           PADE APPROXIMANTS               (KLON,NIPD,2,KLEV)
!  PGASUR      ---           SURFACE PADE APPROXIMANTS            (KLON,NIPD,2)
!  PGBSUR      ---           SURFACE PADE APPROXIMANTS            (KLON,NIPD,2)
!  PGATOP      ---           T.O.A. PADE APPROXIMANTS             (KLON,NIPD,2)
!  PGBTOP      ---           T.O.A. PADE APPROXIMANTS             (KLON,NIPD,2)

!     ==== OUTPUTS ===
!  Trajectory  Perturbation  Description                          Dimension
!  PCNTRB5     PCNTRB        CLEAR-SKY ENERGY EXCHANGE 
!                            MATRIX                        (KLON,KLEV+1,KLEV+1)
!  PFLUC5      PFLUC         RADIATIVE FLUXES CLEAR-SKY           (KLON,2,KLEV)

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

!     METHOD.
!     -------

!          1. PERFORMS THE VERTICAL INTEGRATION DISTINGUISHING BETWEEN
!     CONTRIBUTIONS BY -  THE NEARBY LAYERS
!                      -  THE DISTANT LAYERS
!                      -  THE BOUNDARY TERMS
!          2. COMPUTES THE CLEAR-SKY DOWNWARD AND UPWARD EMISSIVITIES.

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

!          *LWVNTL*, *LWVDTL*, *LWVBTL*

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

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

!     AUTHOR.
!     -------
!        M. Janiskova  *ECMWF*       27-Jan-2006

!     MODIFICATIONS.
!     --------------

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

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

USE YOELW    , ONLY : NSIL     ,NIPD     ,NUA
USE YOPHNC   , ONLY : LH2OCO2

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),INTENT(IN)    :: KUAER 
INTEGER(KIND=JPIM),INTENT(IN)    :: KTRAER 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGA(KLON,NIPD,2,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGB(KLON,NIPD,2,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGASUR(KLON,NIPD,2) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGBSUR(KLON,NIPD,2) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGATOP(KLON,NIPD,2) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGBTOP(KLON,NIPD,2) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PABCU5(KLON,NUA,3*KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PB5(KLON,NSIL,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PBINT5(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PBSUR5(KLON,NSIL) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PBTOP5(KLON,NSIL) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDBSL5(KLON,NSIL,KLEV*2) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PEMIS5(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PEMIW5(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCNTRB5(KLON,KLEV+1,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFLUC5(KLON,2,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PABCU(KLON,NUA,3*KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PB(KLON,NSIL,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PBINT(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PBSUR(KLON,NSIL) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PBTOP(KLON,NSIL) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDBSL(KLON,NSIL,KLEV*2) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PEMIS(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PEMIW(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCNTRB(KLON,KLEV+1,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFLUC(KLON,2,KLEV+1) 

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

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

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

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

REAL(KIND=JPRB) :: ZADJD(KLON,KLEV+1), ZADJU(KLON,KLEV+1)
REAL(KIND=JPRB) :: ZDBDT(KLON,NSIL,KLEV), ZDISD(KLON,KLEV+1) 
REAL(KIND=JPRB) :: ZDISU(KLON,KLEV+1), ZDWFSU(KLON,NSIL)  

REAL(KIND=JPRB) :: ZADJD5(KLON,KLEV+1), ZADJU5(KLON,KLEV+1)
REAL(KIND=JPRB) :: ZDBDT5(KLON,NSIL,KLEV), ZDISD5(KLON,KLEV+1) 
REAL(KIND=JPRB) :: ZDISU5(KLON,KLEV+1), ZDWFSU5(KLON,NSIL)

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

#include "lwvbtl.intfb.h"
#include "lwvbrtl.intfb.h"
#include "lwvdtl.intfb.h"
#include "lwvdrtl.intfb.h"
#include "lwvntl.intfb.h"
#include "lwvnrtl.intfb.h"

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

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

!*         1.1     INITIALIZE LAYER CONTRIBUTIONS
!                  ------------------------------

IF (LHOOK) CALL DR_HOOK('LWVTL',0,ZHOOK_HANDLE)
DO JK=1,KLEV+1
  DO JL=KIDIA,KFDIA
    ZADJD (JL,JK) = 0.0_JPRB
    ZADJD5(JL,JK) = 0.0_JPRB
    ZADJU (JL,JK) = 0.0_JPRB
    ZADJU5(JL,JK) = 0.0_JPRB
    ZDISD (JL,JK) = 0.0_JPRB
    ZDISD5(JL,JK) = 0.0_JPRB
    ZDISU (JL,JK) = 0.0_JPRB
    ZDISU5(JL,JK) = 0.0_JPRB
  ENDDO
ENDDO
DO JA=1,NSIL
  DO JL=KIDIA,KFDIA
    ZDWFSU (JL,JA) = 0.0_JPRB
    ZDWFSU5(JL,JA) = 0.0_JPRB
  ENDDO
ENDDO

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

!*         2.      VERTICAL INTEGRATION
!                  --------------------

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

!*         2.1     CONTRIBUTION FROM ADJACENT LAYERS
!                  ---------------------------------

IF (LH2OCO2) THEN
  CALL LWVNRTL &
   & ( KIDIA, KFDIA, KLON  , KLEV , KUAER,&
   & PGA   , PGB   , PABCU5 , PDBSL5, &
   & ZADJD5, ZADJU5, PCNTRB5, ZDBDT5, ZDWFSU5 ,&
   & PABCU , PDBSL , &
   & ZADJD , ZADJU , PCNTRB , ZDBDT , ZDWFSU &
   & )
ELSE
  CALL LWVNTL &
   & ( KIDIA, KFDIA, KLON  , KLEV , KUAER,&
   & PGA   , PGB   , PABCU5 , PDBSL5, &
   & ZADJD5, ZADJU5, PCNTRB5, ZDBDT5, ZDWFSU5 ,&
   & PABCU , PDBSL , &
   & ZADJD , ZADJU , PCNTRB , ZDBDT , ZDWFSU &
   & )  
ENDIF

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

!*         2.2     CONTRIBUTION FROM DISTANT LAYERS
!                  ---------------------------------

IF (LH2OCO2) THEN
  CALL LWVDRTL &
   & ( KIDIA , KFDIA, KLON , KLEV  , KTRAER,&
   & PGA    , PGB   , PABCU5, ZDBDT5 ,&
   & PCNTRB5, ZDISD5, ZDISU5, ZDWFSU5,&
   & PABCU  , ZDBDT ,&
   & PCNTRB , ZDISD , ZDISU , ZDWFSU &
   & )
ELSE
  CALL LWVDTL &
   & ( KIDIA , KFDIA, KLON , KLEV  , KTRAER,&
   & PGA    , PGB   , PABCU5, ZDBDT5 ,&
   & PCNTRB5, ZDISD5, ZDISU5, ZDWFSU5,&
   & PABCU  , ZDBDT ,&
   & PCNTRB , ZDISD , ZDISU , ZDWFSU &
   & )
ENDIF

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

!*         2.3     EXCHANGE WITH THE BOUNDARIES
!                  ----------------------------

IF (LH2OCO2) THEN
  CALL LWVBRTL &
   & ( KIDIA , KFDIA , KLON  , KLEV  , KUAER,&
   & PGASUR , PGBSUR , PGATOP , PGBTOP,&
   & PABCU5 , ZADJD5 , ZADJU5 ,&
   & PB5    , PBINT5 , PBSUR5 , PBTOP5,&
   & ZDISD5 , ZDISU5 , PEMIS5 , PEMIW5,&
   & ZDWFSU5, PFLUC5 ,&
   & PABCU  , ZADJD  , ZADJU  ,&
   & PB     , PBINT  , PBSUR  , PBTOP ,&
   & ZDISD  , ZDISU  , PEMIS  , PEMIW ,&
   & ZDWFSU , PFLUC  &
   & )
ELSE
  CALL LWVBTL &
   & ( KIDIA , KFDIA , KLON  , KLEV  , KUAER,&
   & PGASUR , PGBSUR , PGATOP , PGBTOP,&
   & PABCU5 , ZADJD5 , ZADJU5 ,&
   & PB5    , PBINT5 , PBSUR5 , PBTOP5,&
   & ZDISD5 , ZDISU5 , PEMIS5 , PEMIW5,&
   & ZDWFSU5, PFLUC5 ,&
   & PABCU  , ZADJD  , ZADJU  ,&
   & PB     , PBINT  , PBSUR  , PBTOP ,&
   & ZDISD  , ZDISU  , PEMIS  , PEMIW ,&
   & ZDWFSU , PFLUC  &
   & )
ENDIF

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

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