SUBROUTINE PPTCC(KPROMA,KSTART,KPROF,KFLEV,KLEVP,KLOLEV,&
 & PCCF,&
 & PTCCPP)  

!**** *PPTCC* - POST-PROCESS TOTAL CLOUD COVER

!     PURPOSE.
!     --------

!        PERFORMS THE VERTICAL INTEGRATION OF CLOUD COVER

!**   INTERFACE.
!     ----------
!        *CALL* *PPTCC(KPROMA,KSTART,KPROF,KFLEV,KLEVP,KLOLEV,
!                      PCCF,PTCCPP)

!        EXPLICIT ARGUMENTS
!        ------------------

!        KPROMA                    - HORIZONTAL DIMENSION.             (INPUT-C)
!        KSTART                    - START OF WORK.                    (INPUT-C)
!        KPROF                     - DEPTH OF WORK.                    (INPUT-C)
!        KFLEV                     - NUMBER OF INPUT PRESSURE LEVELS   (INPUT-C)
!        KLEVP                     - NUMBER OF OUTPUT PRESSURE LEVELS  (INPUT-C)
!        KLOLEV                    - BEGINING FOR THE INTERPOLATION    (INPUT-C)
!        PCCF(KPROMA,0:KFLEV)      - CLOUD COVER ON FULL INPUT LEVELS  (INPUT)

!        PTCCPP(KPROMA,KLEVP)      - POST-PROCESSED CLOUD COVER       (OUTPUT)

!        IMPLICIT ARGUMENTS :  CONSTANTS FROM YOMCST AND YOMSTA.
!        --------------------

!     METHOD.
!     -------
!        SEE DOCUMENTATION

!     EXTERNALS.  PPINTP - LINEAR INTERPOLATION
!     ----------

!     REFERENCE.
!     ----------
!        ECMWF Research Department documentation of the IFS

!     AUTHOR.
!     -------
!        D. VASILJEVIC  *ECMWF*

!     MODIFICATIONS.
!     --------------
!        Ad Stoffelen   Friday 13/08/93  Debugging!
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!     ------------------------------------------------------------------

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

USE YOMLUN   , ONLY : NULOUT

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KPROMA 
INTEGER(KIND=JPIM),INTENT(IN)    :: KFLEV 
INTEGER(KIND=JPIM),INTENT(IN)    :: KLEVP 
INTEGER(KIND=JPIM),INTENT(IN)    :: KSTART 
INTEGER(KIND=JPIM),INTENT(IN)    :: KPROF 
INTEGER(KIND=JPIM),INTENT(IN)    :: KLOLEV 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCCF(KPROMA,0:KFLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PTCCPP(KPROMA,KLEVP) 
REAL(KIND=JPRB) :: ZMAXTCC(KPROMA)

INTEGER(KIND=JPIM) :: JL, JLEV

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

#include "abor1.intfb.h"

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

!*       1.    POST-PROCESS CLOUD COVER
!              ------------------------

!*       1.0   PRESET

IF (LHOOK) CALL DR_HOOK('PPTCC',0,ZHOOK_HANDLE)
IF( KLEVP /= KLOLEV )THEN
  WRITE(NULOUT,*) ' PPTCC: NOT ONE TCC PER PROFILE!',KLEVP, KLOLEV
  CALL ABOR1('SUBROUTINE PPTCC')
ENDIF
DO JL = KSTART, KPROF
  PTCCPP(JL,KLEVP) = 0.0_JPRB
  ZMAXTCC(JL) = PCCF(JL,1)
ENDDO

!*       1.1   INTEGRATE CLOUD COVER

DO JLEV = 2, KFLEV
  DO JL = KSTART, KPROF
    IF( PCCF(JL,JLEV-1) < 0.0_JPRB )THEN
      ZX = PTCCPP(JL,KLEVP)
      PTCCPP (JL,KLEVP) = ZX + (1.0_JPRB-ZX)*ZMAXTCC(JL)
      ZMAXTCC(JL) = PCCF(JL,JLEV)
    ELSE
      IF( ZMAXTCC(JL) < PCCF(JL,JLEV) )THEN
        ZMAXTCC(JL) = PCCF(JL,JLEV)
      ENDIF
    ENDIF
  ENDDO
ENDDO

DO JL = KSTART, KPROF
  ZX = PTCCPP(JL,KLEVP)
  PTCCPP(JL,KLEVP) = ZX + (1.0_JPRB-ZX)*ZMAXTCC(JL)
ENDDO

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

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

