!OCL NOEVAL
SUBROUTINE TRANSINV_NHCONV(&
 ! ----- OUTPUT --------------------------------------------------------------
 & PU,PV,PT,PTL,PTM,PSPD,PSPDL,PSPDM,PSVD,PSP,PSPL,PSPM, &
 & PQ,PQL,PQM,PL,PLL,PLM,PI,PIL,PIM,PR,PS,PG &
 &)

!* TRANSINV_NHCONV - Conversion of NH variables (model to file and vice-versa)
!                    Inverse transforms

! Purpose
! -------

! Interface
! ---------
!  * OUTPUT:
!     PU     : U-wind
!     PV     : V-wind
!     PT     : temperature
!     PTL    : zonal comp of grad(temperature)
!     PTM    : merid comp of grad(temperature)
!     PSPD   : NH pressure departure variable "spd"
!     PSPDL  : zonal comp of grad(spd)
!     PSPDM  : merid comp of grad(spd)
!     PSVD   : NH vertical divergence variable "svd"
!     PSP    : log(prehyd)
!     PSPL   : zonal comp of grad(log(prehyd))
!     PSPM   : merid comp of grad(log(prehyd))
!     PQ     : moisture
!     PQL    : zonal comp of grad(moisture)
!     PQM    : merid comp of grad(moisture)
!     PL     : liquid water
!     PLL    : zonal comp of grad(liquid water)
!     PLM    : merid comp of grad(liquid water)
!     PI     : ice
!     PIL    : zonal comp of grad(ice)
!     PIM    : merid comp of grad(ice)
!     PR     : rain
!     PS     : snow
!     PG     : graupels

! Externals
! ---------

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

! Reference
! ---------

! Author
! ------
!   27-Jan-2005 K. Yessad (after old part 2 of GNHPDVDCONV)

! Modifications
! -------------
!   13-Oct-2005 K. Yessad       : B-level parallelisation.
!   N. Wedi and K. Yessad (Jan 2008): different dev for NH model and PC scheme
! End Modifications
!------------------------------------------------------------------------------

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

USE YOMDIM   , ONLY : NFLSUR   ,NFLEVG
USE YOMDYNA  , ONLY : NVDVAR   ,NPDVAR   ,LNH_PDVD ,LNH_GEOGW
USE YOMGEM   , ONLY : NGPTOT
USE YOMSP    , ONLY : SPVOR    ,SPDIV    ,SPT      ,SPQ      ,SPL      , &
 &                    SPI      ,SPSPD    ,SPSVD    ,SPSP
USE YOM_YGFL , ONLY : YQ       ,YL       ,YI

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

IMPLICIT NONE

REAL(KIND=JPRB),INTENT(OUT) :: PU   (NGPTOT,NFLEVG)
REAL(KIND=JPRB),INTENT(OUT) :: PV   (NGPTOT,NFLEVG)
REAL(KIND=JPRB),INTENT(OUT) :: PT   (NGPTOT,NFLEVG)
REAL(KIND=JPRB),INTENT(OUT) :: PTL  (NGPTOT,NFLEVG)
REAL(KIND=JPRB),INTENT(OUT) :: PTM  (NGPTOT,NFLEVG)
REAL(KIND=JPRB),INTENT(OUT) :: PSPD (NGPTOT,NFLEVG)
REAL(KIND=JPRB),INTENT(OUT) :: PSPDL(NGPTOT,NFLEVG)
REAL(KIND=JPRB),INTENT(OUT) :: PSPDM(NGPTOT,NFLEVG)
REAL(KIND=JPRB),INTENT(OUT) :: PSVD (NGPTOT,NFLEVG)
REAL(KIND=JPRB),INTENT(OUT) :: PSP  (NGPTOT)
REAL(KIND=JPRB),INTENT(OUT) :: PSPL (NGPTOT)
REAL(KIND=JPRB),INTENT(OUT) :: PSPM (NGPTOT)
REAL(KIND=JPRB),INTENT(OUT) :: PQ   (NGPTOT,NFLEVG)
REAL(KIND=JPRB),INTENT(OUT) :: PQL  (NGPTOT,NFLEVG)
REAL(KIND=JPRB),INTENT(OUT) :: PQM  (NGPTOT,NFLEVG)
REAL(KIND=JPRB),INTENT(OUT) :: PL   (NGPTOT,NFLEVG)
REAL(KIND=JPRB),INTENT(OUT) :: PLL  (NGPTOT,NFLEVG)
REAL(KIND=JPRB),INTENT(OUT) :: PLM  (NGPTOT,NFLEVG)
REAL(KIND=JPRB),INTENT(OUT) :: PI   (NGPTOT,NFLEVG)
REAL(KIND=JPRB),INTENT(OUT) :: PIL  (NGPTOT,NFLEVG)
REAL(KIND=JPRB),INTENT(OUT) :: PIM  (NGPTOT,NFLEVG)
REAL(KIND=JPRB),INTENT(OUT) :: PR   (NGPTOT,NFLEVG)
REAL(KIND=JPRB),INTENT(OUT) :: PS   (NGPTOT,NFLEVG)
REAL(KIND=JPRB),INTENT(OUT) :: PG   (NGPTOT,NFLEVG)

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

REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

#include "speree.intfb.h"
#include "speree_der.intfb.h"
#include "speuv.intfb.h"

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

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

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

!* 1. TRANSFORM SPECTRAL FIELDS TO GRID POINT SPACE
!     ---------------------------------------------

!  1.1 GMV variables

IF (LNH_PDVD) THEN

  ! * vorticity, divergence, wind
  IF ( NVDVAR == 4 ) CALL SPEUV(SPVOR,SPDIV,PU,PV,NFLSUR,NFLEVG,1)

  ! * temperature
  IF ( NVDVAR == 4 ) THEN
    CALL SPEREE_DER(NFLSUR,NFLEVG,SPT,PT,PTL,PTM)
  ELSEIF ( NVDVAR == 3 ) THEN
    CALL SPEREE(NFLSUR,NFLEVG,SPT,PT)
  ENDIF

  ! * NH pressure departure variable
  IF ( NVDVAR == 4 ) THEN
    CALL SPEREE_DER(NFLSUR,NFLEVG,SPSPD,PSPD,PSPDL,PSPDM)
  ELSEIF ( NVDVAR == 3 ) THEN
    CALL SPEREE(NFLSUR,NFLEVG,SPSPD,PSPD)
  ENDIF

  ! * NH vertical divergence variable
  CALL SPEREE(NFLSUR,NFLEVG,SPSVD,PSVD)

ELSEIF (LNH_GEOGW) THEN

  ! * vorticity, divergence, wind
  CALL SPEUV(SPVOR,SPDIV,PU,PV,NFLSUR,NFLEVG,1)

  ! * temperature
  CALL SPEREE_DER(NFLSUR,NFLEVG,SPT,PT,PTL,PTM)

  ! * NH pressure departure variable
  CALL SPEREE_DER(NFLSUR,NFLEVG,SPSPD,PSPD,PSPDL,PSPDM)

  ! * NH vertical divergence variable
  CALL SPEREE(NFLSUR,NFLEVG,SPSVD,PSVD)

ENDIF


!  1.2 GMVS variables

! * surface pressure
IF (LNH_PDVD) THEN
  IF ( NPDVAR == 2 ) THEN
    IF ( NVDVAR == 4 ) THEN
      CALL SPEREE_DER(1,1,SPSP,PSP,PSPL,PSPM)
    ELSEIF ( NVDVAR == 3 ) THEN
      CALL SPEREE(1,1,SPSP,PSP)
    ENDIF
  ENDIF
ELSEIF (LNH_GEOGW) THEN
  CALL SPEREE_DER(1,1,SPSP,PSP,PSPL,PSPM)
ENDIF


!  1.3 GFL variables

! remark: this part has to be rewritten in the future with
!  "global treatment of GFL".

IF ( (LNH_PDVD.AND.NVDVAR == 4).OR.LNH_GEOGW ) THEN

  ! * specific humidity
  IF (YQ%LSP) THEN
    CALL SPEREE_DER(NFLSUR,NFLEVG,SPQ,PQ,PQL,PQM)
  ELSE
    PQ (1:NGPTOT,1:NFLEVG)=0.0_JPRB
    PQM(1:NGPTOT,1:NFLEVG)=0.0_JPRB
    PQL(1:NGPTOT,1:NFLEVG)=0.0_JPRB
  ENDIF

  ! * specific mass of liquid
  IF (YL%LSP) THEN
    CALL SPEREE_DER(NFLSUR,NFLEVG,SPL,PL,PLL,PLM)
  ELSE
    PL (1:NGPTOT,1:NFLEVG)=0.0_JPRB
    PLM(1:NGPTOT,1:NFLEVG)=0.0_JPRB
    PLL(1:NGPTOT,1:NFLEVG)=0.0_JPRB
  ENDIF

  ! * specific mass of ice
  IF (YI%LSP) THEN
    CALL SPEREE_DER(NFLSUR,NFLEVG,SPI,PI,PIL,PIM)
  ELSE
    PI (1:NGPTOT,1:NFLEVG)=0.0_JPRB
    PIM(1:NGPTOT,1:NFLEVG)=0.0_JPRB
    PIL(1:NGPTOT,1:NFLEVG)=0.0_JPRB
  ENDIF

  ! * Rain, graupel and snow for AROME
  PR(1:NGPTOT,1:NFLEVG) =0.0_JPRB
  PS(1:NGPTOT,1:NFLEVG) =0.0_JPRB
  PG(1:NGPTOT,1:NFLEVG) =0.0_JPRB

ENDIF ! NVDVAR

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

IF (LHOOK) CALL DR_HOOK('TRANSINV_NHCONV',1,ZHOOK_HANDLE)

END SUBROUTINE TRANSINV_NHCONV

