SUBROUTINE CPG_ZERO_AD( &
 ! ---------------------------------------------------------------------------
 ! - INPUT:
 & CDCONF,KST,KEND,&
 ! ---------------------------------------------------------------------------
 ! - OUTPUT:
 & PRT0L,PRT0M,PRE0F,PRDELP0,PLNPR0,PALPH0,PRTGR0,&
 & PR0,PCP0,PKAP0,PHIF0,PVVEL0,PDIVP0,PKENE0,PSGRTL,PSGRTM,&
 & PRE9F,PRDELP9,PLNPR9,PALPH9,PR9,PCP9,PHIF9,&
 & PRE0,PDELP0,PHI0,PEVEL0,PSDIV0,PSDVBC0,&
 & PRE9,PDELP9,PHI9,&
 & PRTR0,PGRAWL,PGRAWM,PLHU0,PLHV0,PLHU9,PLHV9,&
 & PRE0L,PRE0M,&
 & PD3Y0,PRRED0,PGPHL,PGPHM,PWW0,PGPPC)

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

USE YOMCT0   , ONLY : LNHDYN   ,LTWOTL   ,LPC_FULL
USE YOMDIM   , ONLY : NFLEVG   ,NPROMA   ,NPROMNH  ,NFGPPC
USE YOMDYN   , ONLY : NCURRENT_ITER
USE YOMSIMPHL, ONLY : LSIMPH

!**** *CPG_ZERO_AD* - Adjoint grid point calculations.
!                     Set to zero some sensitivities.

!     Purpose.
!     --------
!           Adjoint grid point calculations.
!           Set to zero some sensitivities.

!           Notice that this routine has no TL counterpart.
!           These settings to zero are not done in CPG_END_AD in order
!            to keep the maximum of consistency between CPG_END_AD and
!            CPG_END_TL.

!**   Interface.
!     ----------
!        *CALL* *CPG_ZERO_AD*

!        Explicit arguments :
!        --------------------

!*    INPUT:
!     ------
!        CDCONF    : configuration of work.
!        KST       : first element of work.
!        KEND      : last element of work.

!*    OUTPUT:
!     -------
!        PRT0L to PGPPC: see GPG_END_AD, CPG_DYN_AD or CPG_GP_AD for comments.

!        Implicit arguments :
!        --------------------

!     Method.
!     -------
!        See documentation

!     Externals.
!     ----------

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

!     Author.
!     -------
!        K. Yessad (Jul 2004) after part 7 of CPGAD.

!     Modifications.
!     --------------
!   Original : 12-Jul-2004
!   K. Yessad: 10-Apr-2006 Move some zeroing from CPG_END_AD.
!   S. Ivatek-S: 17-Apr-2007 Over dimensioning of PGPNH to NFGPNH+1,
!                           boundary checking problem if NFGPNH=0 bf
!   N. Wedi and K. Yessad (Jan 2008): different dev for NH model and PC scheme
!   K. Yessad (Dec 2008): remove dummy CDLOCK
! End Modifications
!------------------------------------------------------------------------------

IMPLICIT NONE

CHARACTER(LEN=1)  ,INTENT(IN)    :: CDCONF
INTEGER(KIND=JPIM),INTENT(IN)    :: KST
INTEGER(KIND=JPIM),INTENT(IN)    :: KEND
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRT0L(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRT0M(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRE0F(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRDELP0(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PLNPR0(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PALPH0(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRTGR0(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PR0(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCP0(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PKAP0(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PHIF0(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PVVEL0(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PDIVP0(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PKENE0(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PSGRTL(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PSGRTM(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRE9F(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRDELP9(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PLNPR9(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PALPH9(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PR9(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCP9(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PHIF9(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRE0(NPROMA,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PDELP0(NPROMA,0:NFLEVG+1)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PHI0(NPROMA,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PEVEL0(NPROMA,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PSDIV0(NPROMA,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PSDVBC0(NPROMA,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRE9(NPROMA,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PDELP9(NPROMA,0:NFLEVG+1)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PHI9(NPROMA,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRTR0(NPROMNH,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PGRAWL(NPROMNH,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PGRAWM(NPROMNH,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PLHU0(NPROMNH,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PLHV0(NPROMNH,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PLHU9(NPROMNH,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PLHV9(NPROMNH,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRE0L(NPROMA)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRE0M(NPROMA)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PD3Y0(NPROMNH,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRRED0(NPROMNH,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PGPHL(NPROMA,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PGPHM(NPROMA,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PWW0(NPROMNH,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PGPPC(NPROMA,NFGPPC+1)

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

LOGICAL :: LLADNMI
REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

IF (LHOOK) CALL DR_HOOK('CPG_ZERO_AD',0,ZHOOK_HANDLE)

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

!*       1.    Set local sensitivities to zero for the start for var at t
!              ----------------------------------------------------------

PRT0L(KST:KEND,1:NFLEVG)=0.0_JPRB
PRT0M(KST:KEND,1:NFLEVG)=0.0_JPRB
PRE0F(KST:KEND,1:NFLEVG)=0.0_JPRB
PRDELP0(KST:KEND,1:NFLEVG)=0.0_JPRB
PLNPR0(KST:KEND,1:NFLEVG)=0.0_JPRB
PALPH0(KST:KEND,1:NFLEVG)=0.0_JPRB
PRTGR0(KST:KEND,1:NFLEVG)=0.0_JPRB
PR0(KST:KEND,1:NFLEVG)=0.0_JPRB
PCP0(KST:KEND,1:NFLEVG)=0.0_JPRB
PKAP0(KST:KEND,1:NFLEVG)=0.0_JPRB
PHIF0(KST:KEND,1:NFLEVG)=0.0_JPRB
PVVEL0(KST:KEND,1:NFLEVG)=0.0_JPRB
PDIVP0(KST:KEND,1:NFLEVG)=0.0_JPRB
PKENE0(KST:KEND,1:NFLEVG)=0.0_JPRB
PSGRTL(KST:KEND,1:NFLEVG)=0.0_JPRB
PSGRTM(KST:KEND,1:NFLEVG)=0.0_JPRB

PRE0(KST:KEND,0:NFLEVG)=0.0_JPRB
PDELP0(KST:KEND,0:NFLEVG)=0.0_JPRB
PHI0(KST:KEND,0:NFLEVG)=0.0_JPRB
PEVEL0(KST:KEND,0:NFLEVG)=0.0_JPRB
PSDIV0(KST:KEND,0:NFLEVG)=0.0_JPRB
PSDVBC0(KST:KEND,0:NFLEVG)=0.0_JPRB
PGPHL(KST:KEND,0:NFLEVG)=0.0_JPRB
PGPHM(KST:KEND,0:NFLEVG)=0.0_JPRB

IF (LNHDYN) THEN
  PRTR0(KST:KEND,1:NFLEVG)=0.0_JPRB
  PD3Y0(KST:KEND,1:NFLEVG)=0.0_JPRB
  PRRED0(KST:KEND,1:NFLEVG)=0.0_JPRB
  PWW0(KST:KEND,1:NFLEVG)=0.0_JPRB
  PGRAWL(KST:KEND,0:NFLEVG)=0.0_JPRB
  PGRAWM(KST:KEND,0:NFLEVG)=0.0_JPRB
  PLHU0(KST:KEND,0:NFLEVG)=0.0_JPRB
  PLHV0(KST:KEND,0:NFLEVG)=0.0_JPRB
ENDIF

PGPPC(KST:KEND,1:NFGPPC+1)=0.0_JPRB
PRE0L(KST:KEND)=0.0_JPRB
PRE0M(KST:KEND)=0.0_JPRB

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

!*       2.    Set local sensitivities to zero for the start for var at t-dt
!              -------------------------------------------------------------

LLADNMI= CDCONF == 'E' .OR. CDCONF == 'F'

IF ((.NOT.LTWOTL) .AND. (NCURRENT_ITER == 0) .AND. &
 & ((LSIMPH.AND.(.NOT.LLADNMI)).OR.LNHDYN) ) THEN
  PRE9F(KST:KEND,1:NFLEVG)=0.0_JPRB
  PRDELP9(KST:KEND,1:NFLEVG)=0.0_JPRB
  PLNPR9(KST:KEND,1:NFLEVG)=0.0_JPRB
  PALPH9(KST:KEND,1:NFLEVG)=0.0_JPRB
  PDELP9(KST:KEND,0:NFLEVG)=0.0_JPRB
ENDIF

IF ((.NOT.LTWOTL).AND.LSIMPH) THEN
  PR9(KST:KEND,1:NFLEVG)=0.0_JPRB
  PCP9(KST:KEND,1:NFLEVG)=0.0_JPRB
  PHI9(KST:KEND,0:NFLEVG)=0.0_JPRB
  PHIF9(KST:KEND,1:NFLEVG)=0.0_JPRB
ENDIF

IF ((LTWOTL.AND.LPC_FULL).OR.(.NOT.LTWOTL)) THEN
  PRE9(KST:KEND,0:NFLEVG)=0.0_JPRB
ENDIF

IF ((.NOT.LTWOTL).AND.LNHDYN) THEN
  PLHU9(KST:KEND,0:NFLEVG)=0.0_JPRB
  PLHV9(KST:KEND,0:NFLEVG)=0.0_JPRB
ENDIF

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

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