!OPTIONS XOPT(NOEVAL)
SUBROUTINE LWBV15 ( KIDIA,KFDIA,KLON,KLEV,&
 & KMODE,KFLUX,KRAD,KLIM,&
 & PDP,PDT0,PEMIS,PPMB,PTL,&
 & PTAVE,&
 & PCOLC,PFLUC,&
 & PABCU,PBINT,PBSUI,PCTS,PCNTRB,PFDN,PFUP)  

!**** *LWBV15*   - COMPUTE PLANCK FUNC., PERF. VERT. INTEGRATION
!****              FROZEN VERSION (CYCLE 15) OF LWBV

!     PURPOSE.
!     --------
!           TO COMPUTE THE PLANCK FUNCTION AND PERFORM THE
!           VERTICAL INTEGRATION. SPLIT OUT FROM LW FOR MEMORY
!           SAVING

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

!        *LWVB15* IS CALLED FROM *LW15*

!        EXPLICIT ARGUMENTS :
!        --------------------
! PDP    : (KLON,KLEV)       ; LAYER PRESSURE THICKNESS
! PDT0   : (KLON)             ; SURFACE TEMPERATURE DISCONTINUITY
! PEMIS  : (KLON)             ; SURFACE EMISSIVITY
! PPMB   : (KLON,KLEV+1)     ; HALF LEVEL PRESSURE
! PTAVE  : (KLON,KLEV)       ; TEMPERATURE
! PTL    : (KLON,KLEV+1)     ; HALF LEVEL TEMPERATURE
!     ==== OUTPUTS ===

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

!     METHOD.
!     -------

!          1. COMPUTES THE PLANCK FUNCTIONS ON THE INTERFACES AND THE
!     GRADIENT OF PLANCK FUNCTIONS IN THE LAYERS.
!          2. PERFORMS THE VERTICAL INTEGRATION DISTINGUISHING THE CON-
!     TRIBUTIONS OF THE ADJACENT AND DISTANT LAYERS AND THOSE FROM THE
!     BOUNDARIES.
!          3. COMPUTES THE CLEAR-SKY COOLING RATES.

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

!          *LWB15*, *LWV15*

!     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

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

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

USE YOMLW15  , ONLY : NINT15   ,NUA15
USE YOMRDU15 , ONLY : NUAER15  ,NTRAER15 ,RCDAY15

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)               :: KMODE ! Argument NOT used
INTEGER(KIND=JPIM)               :: KFLUX ! Argument NOT used
INTEGER(KIND=JPIM)               :: KRAD ! Argument NOT used
INTEGER(KIND=JPIM),INTENT(OUT)   :: KLIM 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDP(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDT0(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PEMIS(KLON) 
REAL(KIND=JPRB)                  :: PPMB(KLON,KLEV+1) ! Argument NOT used
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTL(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTAVE(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCOLC(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFLUC(KLON,2,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PABCU(KLON,NUA15,3*KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PBINT(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PBSUI(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCTS(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCNTRB(KLON,KLEV+1,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFDN(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFUP(KLON,KLEV+1) 
!-----------------------------------------------------------------------

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

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

!              ------------
REAL(KIND=JPRB) :: ZB(KLON,NINT15,KLEV+1)&
 & ,  ZBSUR(KLON,NINT15), ZBTOP(KLON,NINT15)&
 & ,  ZDBSL(KLON,NINT15,KLEV*2)&
 & ,  ZGA(KLON,8,2,KLEV), ZGB(KLON,8,2,KLEV)&
 & ,  ZGASUR(KLON,8,2)   , ZGBSUR(KLON,8,2)&
 & ,  ZGATOP(KLON,8,2)   , ZGBTOP(KLON,8,2)  

INTEGER(KIND=JPIM) :: JK, JKL, JL

REAL(KIND=JPRB) :: ZDFNET
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "lwb15.intfb.h"
#include "lwv15.intfb.h"

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

!*         2.    COMPUTES PLANCK FUNCTIONS
!                -------------------------

IF (LHOOK) CALL DR_HOOK('LWBV15',0,ZHOOK_HANDLE)
CALL LWB15 ( KIDIA,KFDIA,KLON,KLEV,KMODE,KFLUX,KRAD,&
 & PDT0,PTAVE,PTL,&
 & ZB,PBINT,PBSUI,ZBSUR,ZBTOP,ZDBSL,&
 & ZGA,ZGB,ZGASUR,ZGBSUR,ZGATOP,ZGBTOP     )  

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

!*         3.    PERFORMS THE VERTICAL INTEGRATION
!                ---------------------------------

CALL LWV15 ( KIDIA,KFDIA,KLON,KLEV,KMODE,KFLUX,KRAD,&
 & NUAER15,NTRAER15,&
 & KLIM,&
 & PABCU,ZB,PBINT,PBSUI,ZBSUR,ZBTOP,ZDBSL,PEMIS,PPMB,PTAVE,&
 & ZGA,ZGB,ZGASUR,ZGBSUR,ZGATOP,ZGBTOP,&
 & PCNTRB,PCTS,PCOLC,PFLUC                     )  

DO JK = 1 , KLEV+1
  DO JL = KIDIA,KFDIA
    PFDN(JL,JK) = PFLUC(JL,2,JK)
    PFUP(JL,JK) = PFLUC(JL,1,JK)
  ENDDO
ENDDO

DO JKL = 1 , KLEV
  JK = KLEV+1 - JKL
  DO JL = KIDIA,KFDIA
    ZDFNET = PFLUC(JL,1,JK+1) + PFLUC(JL,2,JK+1)&
     & -PFLUC(JL,1,JK  ) - PFLUC(JL,2,JK  )  
    PCOLC(JL,JK) = RCDAY15 * ZDFNET / PDP(JL,JKL)
  ENDDO
ENDDO

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

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