SUBROUTINE GPHLWIAD(KPROMA,KSTART,KPROF,&
 & PLNPR5,PALPH5,PLNPR0,PALPH0,PWW0)  

!**** *GPHLWIAD* - to half-levels interpolation weights for
!                  adjoint model

!     Purpose.
!     --------
!           Compute weights for interpolation of winds to
!           half levels (in non-hydrostatic dynamics)

!**   Interface.
!     ----------
!        *CALL* *GPHLWIAD()

!        Explicit arguments :
!        --------------------
!         See direct code.

!        Implicit arguments : none.
!        --------------------

!     Method.
!     -------
!        Interpolation from full-levels using logaritmic pressure profile
!        Then modify values on the top and bottom using boundary condition
!        (at the bottom free-slip condition)
!        Store the weights of vertical interpolation

!     Externals.
!     ----------
!     Reference.
!     ----------
!        ARPEGE/ALADIN documentation

!     Author.
!     -------
!        Martin Charron,  CNRM/GMAP - visiteur

!     Modifications.
!     --------------
!        Original : November 1998
!        Modified 02-07-02 by C. Fischer : remove pww5 computation + intents
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!        K.Yessad      20-Mar-2006 Cleaning + optimisation
!        K. Yessad (Dec 2008): remove dummy CDLOCK
!     ----------------------------------------------------------------------

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

USE YOMDIM   , ONLY : NFLEVG

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

!*       0.    ARGUMENTS.
!              ----------

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KPROMA 
INTEGER(KIND=JPIM),INTENT(IN)    :: KSTART 
INTEGER(KIND=JPIM),INTENT(IN)    :: KPROF 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PLNPR5(KPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PALPH5(KPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PLNPR0(KPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PALPH0(KPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PWW0(KPROMA,NFLEVG) 

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

INTEGER(KIND=JPIM) :: JLEV, JROF
REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

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

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

DO JROF=KPROF,KSTART,-1
  !* Bottom half level:
  PWW0(JROF,NFLEVG) = 0.0_JPRB
ENDDO

DO JLEV= NFLEVG - 1 , 1, -1
  DO JROF=KPROF,KSTART,-1
    PLNPR0(JROF,JLEV+1)=PLNPR0(JROF,JLEV+1)+&
     & PALPH5(JROF,JLEV)/(PLNPR5(JROF,JLEV+1)-PALPH5(JROF,JLEV+1)+&
     & PALPH5(JROF,JLEV))**2 * PWW0(JROF,JLEV)  
    PALPH0(JROF,JLEV+1)=PALPH0(JROF,JLEV+1)-&
     & PALPH5(JROF,JLEV)/(PLNPR5(JROF,JLEV+1)-PALPH5(JROF,JLEV+1)+&
     & PALPH5(JROF,JLEV))**2 * PWW0(JROF,JLEV)  
    PALPH0(JROF,JLEV  )=PALPH0(JROF,JLEV  )-&
     & (PLNPR5(JROF,JLEV+1)-PALPH5(JROF,JLEV+1))&
     & /(PLNPR5(JROF,JLEV+1)-PALPH5(JROF,JLEV+1)+&
     & PALPH5(JROF,JLEV))**2 * PWW0(JROF,JLEV)  
    PWW0(JROF,JLEV)=0.0_JPRB
  ENDDO
ENDDO

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

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