SUBROUTINE GNHGW2SVDAROME( &
 & KSTART ,&! (I) start of work
 & KEND   ,&! (I) end of work
 & PREF   ,&! (I) prehyd at full levels
 & PLNPR  ,&! (I) PLNPR in cpg ("delta" at full levels)
 & PT     ,&! (I) temperature at full levels
 & PNHPREF,&! (I) True Pressure "pre" at full levels
 & PGW    ,&! (I) [gw] at half levels (full levels if VFE)
 & PSVD    &! (O) vertical divergence variable svd (d3 or d4) at full levels
 & )  

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

USE YOMCST , ONLY : RD
USE YOMDIM , ONLY : NPROMA   ,NFLEVG
USE YOMGEM , ONLY : VFE_RDETAH
USE YOMDYNA, ONLY : NVDVAR 
USE YOMCVER, ONLY : LVERTFE  ,LVFE_GWMPA

!* GNHGW2SVDAROME - Conversion gw ---> svd.
!                   Simplified version of GNHGW2SVD
!                   called after the AROME physics.

!     Purpose.
!     --------
!        Convert "g times vertical velocity w"
!        to vertical divergence variable "svd".

!     Explicit arguments :
!     --------------------
!        See interface

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

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

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

!     Reference.
!     ----------

!     Author.
!     -------
!        Y. Seity (CNRM/GMAP)

!     Modifications.
!     --------------
!        05-05-2004, Y. Seity:
!          Original. Created from routine gnhgw2svd.F90.
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!        K.Yessad      25-Jan-2005 Cleanings
!        J. Vivoda and K. Yessad (Oct 2007): VFE in NH model

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

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KSTART 
INTEGER(KIND=JPIM),INTENT(IN)    :: KEND 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PREF(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PLNPR(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PT(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PNHPREF(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGW(NPROMA,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PSVD(NPROMA,NFLEVG) 

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

INTEGER(KIND=JPIM) :: JROF,JLEV

REAL(KIND=JPRB) :: ZGDW(NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZPDEP(NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZGWF(NPROMA,NFLEVG)

REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

#include "verder.intfb.h"

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

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

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

! compute zpdep=pre-prehyd
DO JLEV=1,NFLEVG
  ZPDEP(KSTART:KEND,JLEV)=PNHPREF(KSTART:KEND,JLEV)-PREF(KSTART:KEND,JLEV)
ENDDO  

! -----
! transform gw ---> svd
! -----

! transform into gw into -g.dw
IF( LVERTFE.AND.LVFE_GWMPA )THEN
  DO JLEV=1,NFLEVG
    DO JROF=KSTART,KEND
      ZGWF(JROF,JLEV)=-PGW(JROF,JLEV)
    ENDDO
  ENDDO
  CALL VERDER(NPROMA,KSTART,KEND,NFLEVG,ZGWF,ZGDW)
  DO JLEV=1,NFLEVG
    DO JROF=KSTART,KEND
      ZGDW(JROF,JLEV)=ZGDW(JROF,JLEV)/VFE_RDETAH(JLEV)
    ENDDO
  ENDDO
ELSE
  DO JLEV=1,NFLEVG
    DO JROF=KSTART,KEND
      ZGDW(JROF,JLEV)=PGW(JROF,JLEV-1)-PGW(JROF,JLEV)
    ENDDO
  ENDDO
ENDIF

! transform -g.dw into svd

IF ( NVDVAR == 3 .OR. NVDVAR == 4) THEN
  ! * no difference between 3 and 4 because X is considered constant 
  !   at first step for AROME
  DO JLEV=1,NFLEVG
    DO JROF=KSTART,KEND
      PSVD(JROF,JLEV) = ZGDW(JROF,JLEV)/ &
       & ( RD*PT(JROF,JLEV)*PLNPR(JROF,JLEV) )* &
       & ( ZPDEP(JROF,JLEV)/PREF(JROF,JLEV) + 1.0_JPRB )  
    ENDDO
  ENDDO
ENDIF

!     ------------------------------------------------------------------
IF (LHOOK) CALL DR_HOOK('GNHGW2SVDAROME',1,ZHOOK_HANDLE)
END SUBROUTINE GNHGW2SVDAROME

