MODULE GMV_SUBS_MOD

! Modifications
!   16-Jul-2003 C. Fischer   add Aladin NHS auxiliary array
!   01-Oct-2003 M. Hamrud    CY28 Cleaning
!   31-Oct-2003 M. Tudor     physics tendencies
!   09-Jun-2004 J. Masek     NH cleaning (LPC_NOTR, LFULLIMP, LVSLWBC)
!   26-Jan-2004 C. Temperton fixes for shallow water equations
!   20-Feb-2005 J. Vivoda  3TL PC Eulerian scheme, GWADV scheme for PC_FULL 
!   K. Yessad 07-02-2007: Splitting alti/surf for (gw) in NH+LGWADV.
!   K. Yessad 07-03-2007: Remove useless (gw)_surf interpolations in NH+LGWADV.
!   N. Wedi and K. Yessad (Nov 2007): NHX allocated also if (LGWADV+ND4SYS=2).
!   N. Wedi and K. Yessad (Jan 2008): different dev for NH model and PC scheme
!   K. Yessad (Sep 2008): remove lpc_xidt.
! End Modifications
!-------------------------------------------------------------------------

USE PARKIND1 , ONLY : JPIM     ,JPRB
USE TYPE_GMVS, ONLY : TYPE_T0
USE YOMCT0   , ONLY : LTWOTL   ,LNHDYN   ,LVERCOR  ,LPC_NESC , &
 &                    LPC_FULL ,LTENC    ,LPC_OLD  ,NCONF    ,LSLAG
USE YOMDIM   , ONLY : NFLEVG   ,NPROMA   ,NGPBLKS  ,NFTHER   ,LADER    , &
 &                    LUVDER   ,LVOR     ,NUNDEFLD
USE YOMDYNA  , ONLY : LGWADV   ,NVDVAR   ,LRDBBC   ,LNHX     ,LNHXDER  , &
 & LRWSDLR
USE YOMDYN   , ONLY : LSLINLC1 ,LSLINLC2 ,LSLINL
USE YOMGMV   , ONLY : YT0      ,YT9      ,YT1      ,YT5      ,YPH9     , &
 &                    GMV      ,GMVS     ,GMV5     ,GMV5S    , &
 &                    NDIMGMV  ,NDIMGMVS
USE YOMHOOK  , ONLY : LHOOK    ,DR_HOOK
USE YOMLUN   , ONLY : NULOUT
USE YOMPHY   , ONLY : LMPHYS
USE YOEPHY   , ONLY : LEPHYS

IMPLICIT NONE

SAVE 

PRIVATE
PUBLIC SETUP_GMV, SETUP_PH9_PRED, SETUP_PH9_CORR

CONTAINS

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

SUBROUTINE SETUP_GMV
REAL(KIND=JPRB) :: ZHOOK_HANDLE
IF (LHOOK) CALL DR_HOOK('GMV_SUBS_MOD:SETUP_GMV',0,ZHOOK_HANDLE)
WRITE(NULOUT,*)
WRITE(NULOUT,*) 'SETUP_GMV PRINTS'
WRITE(NULOUT,*)' * SETUP_T0 : time t POINTERS (YT0)'
CALL SETUP_T0(YT0)
CALL SETUP_T9
CALL SETUP_T1
CALL SETUP_PH9
NDIMGMV  = YT0%NDIM+YT9%NDIM
NDIMGMVS = YT0%NDIMS+YT9%NDIMS
WRITE(NULOUT,*)
WRITE(NULOUT,*)'YT0%NDIM=',YT0%NDIM,' YT0%NDIMS=',YT0%NDIMS
WRITE(NULOUT,*)'YT9%NDIM=',YT9%NDIM,' YT9%NDIMS=',YT9%NDIMS
WRITE(NULOUT,*)'YT1%NDIM=',YT1%NDIM,' YT1%NDIMS=',YT1%NDIMS
IF(ALLOCATED(GMV)) DEALLOCATE(GMV)
IF(ALLOCATED(GMVS)) DEALLOCATE(GMVS)
ALLOCATE(GMV(NPROMA,NFLEVG,NDIMGMV,NGPBLKS))
WRITE(NULOUT,*) 'GMV ALLOCATED  ',SIZE(GMV),SHAPE(GMV)
ALLOCATE(GMVS(NPROMA,NDIMGMVS,NGPBLKS))
WRITE(NULOUT,*) 'GMVS ALLOCATED ',SIZE(GMVS),SHAPE(GMVS)

IF(NCONF/100 == 1.OR.NCONF == 801.OR.NCONF == 601.OR. &
   & NCONF == 401.OR.NCONF == 501.OR. & 
   & NCONF == 421.OR.NCONF == 521) THEN  
  WRITE(NULOUT,*)' SETUP_T5 : TRAJECTORY POINTERS (YT5)'
  CALL SETUP_T0(YT5)
  WRITE(NULOUT,*)'YT5%NDIM=',YT5%NDIM,' YT5%NDIMS=',YT5%NDIMS
  IF(ALLOCATED(GMV5)) DEALLOCATE(GMV5)
  IF(ALLOCATED(GMV5S)) DEALLOCATE(GMV5S)
  ALLOCATE(GMV5(NPROMA,NFLEVG,YT5%NDIM,NGPBLKS))
  WRITE(NULOUT,*) 'GMV5 ALLOCATED  ',SIZE(GMV5),SHAPE(GMV5)
  ALLOCATE(GMV5S(NPROMA,YT5%NDIMS,NGPBLKS))
  WRITE(NULOUT,*) 'GMV5S ALLOCATED ',SIZE(GMV5S),SHAPE(GMV5S)
ENDIF
WRITE(NULOUT,*)

IF (LHOOK) CALL DR_HOOK('GMV_SUBS_MOD:SETUP_GMV',1,ZHOOK_HANDLE)

END SUBROUTINE SETUP_GMV

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

SUBROUTINE SETUP_T0(YDT)
TYPE(TYPE_T0),INTENT(OUT)  :: YDT

INTEGER(KIND=JPIM) :: IPT,IPTS
REAL(KIND=JPRB) :: ZHOOK_HANDLE
LOGICAL :: LLSW

IF (LHOOK) CALL DR_HOOK('GMV_SUBS_MOD:SETUP_T0',0,ZHOOK_HANDLE)
YDT%MU    = NUNDEFLD
YDT%MV    = NUNDEFLD
YDT%MT    = NUNDEFLD
YDT%MTL   = NUNDEFLD
YDT%MTM   = NUNDEFLD
YDT%MDIV  = NUNDEFLD
YDT%MVOR  = NUNDEFLD
YDT%MUL   = NUNDEFLD
YDT%MVL   = NUNDEFLD
YDT%MSPD  = NUNDEFLD
YDT%MSPDL = NUNDEFLD
YDT%MSPDM = NUNDEFLD
YDT%MSVD  = NUNDEFLD
YDT%MSVDL = NUNDEFLD
YDT%MSVDM = NUNDEFLD
YDT%MNHX  = NUNDEFLD
YDT%MNHXL = NUNDEFLD
YDT%MNHXM = NUNDEFLD
YDT%MEDOT = NUNDEFLD
! Field pointers in GMVS
YDT%MSP   = NUNDEFLD
YDT%MSPL  = NUNDEFLD
YDT%MSPM  = NUNDEFLD

LLSW=(NCONF == 201).OR.(NCONF == 421).OR.(NCONF == 521)
IPT  = 0
IPTS = 0
IF(LVOR.AND.LADER) THEN
  IPT = IPT+1
  YDT%MVOR = IPT
ENDIF
IF(LADER) THEN
  IPT = IPT+1
  YDT%MDIV = IPT
ENDIF
IPT = IPT+1
YDT%MU = IPT
IPT = IPT+1
YDT%MV = IPT
IF(LUVDER) THEN
  IPT = IPT+1
  YDT%MUL = IPT
  IPT = IPT+1
  YDT%MVL = IPT
ENDIF
YDT%NDIMUV=IPT

IF (.NOT.LLSW) THEN
  IPT = IPT+1
  YDT%MT = IPT
  IF(LNHDYN) THEN
    IPT = IPT+1
    YDT%MSPD = IPT
    IPT = IPT+1
    YDT%MSVD = IPT
    IF(LNHX) THEN
      IPT = IPT+1
      YDT%MNHX = IPT
    ENDIF
  ENDIF
  IF (LADER) THEN
    IPT = IPT+1
    YDT%MTM = IPT
    IF(LNHDYN) THEN
      IPT = IPT+1
      YDT%MSPDM = IPT
      IPT = IPT+1
      YDT%MSVDM = IPT
      IF(LNHXDER) THEN
        IPT = IPT+1
        YDT%MNHXM = IPT
      ENDIF
    ENDIF
  ENDIF
  IF (LADER) THEN
    IPT = IPT+1
    YDT%MTL = IPT
    IF(LNHDYN) THEN
      IPT = IPT+1
      YDT%MSPDL = IPT
      IPT = IPT+1
      YDT%MSVDL = IPT
      IF(LNHXDER) THEN
        IPT = IPT+1
        YDT%MNHXL = IPT
      ENDIF
    ENDIF
  ENDIF
ENDIF

IPTS    = IPTS+1
YDT%MSP  = IPTS
IF (LADER) THEN
  IPTS    = IPTS+1
  YDT%MSPM = IPTS
  IPTS    = IPTS+1
  YDT%MSPL = IPTS
ENDIF
  
YDT%NDIM  = IPT
YDT%NDIMS = IPTS

WRITE(NULOUT,*)' MU=',YDT%MU,'MV=',YDT%MV,&
 & ' MT=',YDT%MT,' MTL=',YDT%MTL,' MTM=',YDT%MTM  
WRITE(NULOUT,*)' MEDOT=',YDT%MEDOT
WRITE(NULOUT,*)' MDIV=',YDT%MDIV,' MVOR=',YDT%MVOR
WRITE(NULOUT,*)' MUL=',YDT%MUL,' MVL=',YDT%MVL,' MSPD=',YDT%MSPD,&
 & ' MSPDL=',YDT%MSPDL,' MSPDM=',YDT%MSPDM  
WRITE(NULOUT,*)' MSVD=',YDT%MSVD,' MSVDL=',YDT%MSVDL,' MSVDM=',YDT%MSVDM
WRITE(NULOUT,*)' MNHX=',YDT%MNHX,' MNHXL=',YDT%MNHXL,' MNHXM=',YDT%MNHXM
WRITE(NULOUT,*)' MSP=',YDT%MSP,' MSPL=',YDT%MSPL,' MSPM=',YDT%MSPM  
IF (LHOOK) CALL DR_HOOK('GMV_SUBS_MOD:SETUP_T0',1,ZHOOK_HANDLE)

END SUBROUTINE SETUP_T0

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

SUBROUTINE SETUP_T9

INTEGER(KIND=JPIM) :: IPT,IPTS
REAL(KIND=JPRB) :: ZHOOK_HANDLE
LOGICAL :: LLSW

IF (LHOOK) CALL DR_HOOK('GMV_SUBS_MOD:SETUP_T9',0,ZHOOK_HANDLE)

YT9%MU = NUNDEFLD
YT9%MV = NUNDEFLD
YT9%MT = NUNDEFLD
YT9%MTL = NUNDEFLD
YT9%MTM = NUNDEFLD
YT9%MEDOT = NUNDEFLD
YT9%MUNL = NUNDEFLD
YT9%MUNL_SI = NUNDEFLD
YT9%MVNL = NUNDEFLD
YT9%MVNL_SI = NUNDEFLD
YT9%MTNL = NUNDEFLD
YT9%MTNL_SI = NUNDEFLD
YT9%MSPNL = NUNDEFLD
YT9%MSPNL_SI = NUNDEFLD
YT9%MVCASRS = NUNDEFLD
YT9%MRDLASR = NUNDEFLD
YT9%MVWVNL = NUNDEFLD
YT9%MSVDNL_SI = NUNDEFLD
YT9%MSPDNL = NUNDEFLD
YT9%MSPDNL_SI = NUNDEFLD
YT9%MYNL = NUNDEFLD
YT9%MDIV = NUNDEFLD
YT9%MVOR = NUNDEFLD
YT9%MUL = NUNDEFLD
YT9%MVL = NUNDEFLD
YT9%MSPD = NUNDEFLD
YT9%MSPDL = NUNDEFLD
YT9%MSPDM = NUNDEFLD
YT9%MSVD = NUNDEFLD
YT9%MSVDL = NUNDEFLD
YT9%MSVDM = NUNDEFLD
YT9%MNHX = NUNDEFLD
YT9%MGW   = NUNDEFLD
YT9%MCUNL = NUNDEFLD
YT9%MCVNL = NUNDEFLD
YT9%MCTNL = NUNDEFLD
YT9%MCSPNL = NUNDEFLD
YT9%MCVWVNL = NUNDEFLD
YT9%MCSPDNL = NUNDEFLD
YT9%MCUPT = NUNDEFLD
YT9%MCVPT = NUNDEFLD
YT9%MCTPT = NUNDEFLD
YT9%MDPHI = NUNDEFLD

YT9%MCURHS = NUNDEFLD
YT9%MCVRHS = NUNDEFLD
YT9%MCTRHS = NUNDEFLD
YT9%MCSPDRHS = NUNDEFLD
YT9%MCSVDRHS = NUNDEFLD
YT9%MCSPRHS = NUNDEFLD
YT9%MNHXNL = NUNDEFLD
YT9%MCNHXNL = NUNDEFLD
! Field pointers in GMVS
YT9%MSP = NUNDEFLD
YT9%MSPL = NUNDEFLD
YT9%MSPM = NUNDEFLD
YT9%MCSPPT = NUNDEFLD
YT9%MDBBC = NUNDEFLD
YT9%MGWS = NUNDEFLD

LLSW=(NCONF == 201).OR.(NCONF == 421).OR.(NCONF == 521)
IPT  = YT0%NDIM
IPTS = YT0%NDIMS

IF (LTWOTL) THEN

  ! * GMV:
  IPT    = IPT+1
  YT9%MU = IPT
  IPT    = IPT+1
  YT9%MV = IPT
  IF (LLSW) THEN
    IPT    = IPT+1
    YT9%MSPNL = IPT
  ELSE
    IPT    = IPT+1
    YT9%MEDOT = IPT
    IF(LVERCOR) THEN
      IPT   = IPT+1
      YT9%MVCASRS=IPT
    ENDIF
    IF(LRWSDLR) THEN
      IPT   = IPT+1
      YT9%MRDLASR=IPT
    ENDIF
    IF( .NOT.LPC_NESC )THEN
      IPT = IPT+1
      YT9%MUNL = IPT
      IPT = IPT+1
      YT9%MVNL = IPT
      IPT = IPT+1
      YT9%MTNL =IPT
      IF (LSLINL) THEN
        IPT = IPT+1
        YT9%MUNL_SI = IPT
        IPT = IPT+1
        YT9%MVNL_SI = IPT
        IPT = IPT+1
        YT9%MTNL_SI = IPT
      ENDIF
      IPT = IPT+1
      YT9%MSPNL = IPT
      IF (LSLINLC1.OR.LSLINLC2) THEN
        IPT = IPT+1
        YT9%MSPNL_SI = IPT
      ENDIF
    ENDIF
    IF(LPC_FULL)THEN
      IPT = IPT+1
      YT9%MT = IPT
      IPT = IPT+1
      YT9%MTL = IPT
      IPT = IPT+1
      YT9%MTM = IPT
      IF(LNHDYN) THEN
        IPT = IPT+1
        YT9%MSPD=IPT
        IPT = IPT+1
        YT9%MSVD=IPT
        IPT = IPT+1
        YT9%MSPDL=IPT
        IPT = IPT+1
        YT9%MSVDL=IPT
        IPT = IPT+1
        YT9%MSPDM=IPT
        IPT = IPT+1
        YT9%MSVDM=IPT
        !! already allocated below
        !! IF(NVDVAR == 4) THEN
        !!   IPT   = IPT+1
        !!   YT9%MNHX= IPT
        !! ENDIF
        IF(LGWADV)THEN
          IPT    = IPT+1
          YT9%MGW= IPT
        ENDIF
      ENDIF
    ENDIF
    IF( LPC_FULL )THEN
      IPT = IPT+1
      YT9%MCUNL=IPT
      IPT = IPT+1
      YT9%MCVNL=IPT
      IPT = IPT+1
      YT9%MCTNL=IPT
      IPT = IPT+1
      YT9%MCSPNL=IPT
      IF(LNHDYN) THEN
        IPT = IPT+1
        YT9%MCVWVNL=IPT
        IPT = IPT+1
        YT9%MCSPDNL=IPT
      ENDIF
    ENDIF
    IF(LPC_FULL.AND.(LMPHYS.OR.LEPHYS))THEN  
      IPT = IPT+1
      YT9%MCUPT = IPT
      IPT = IPT+1
      YT9%MCVPT = IPT
      IPT = IPT+1
      YT9%MCTPT = IPT
    ENDIF
    IF(LNHDYN) THEN
      IF( .NOT.LPC_NESC )THEN
        IPT = IPT+1
        YT9%MVWVNL=IPT
        IPT = IPT+1
        YT9%MSPDNL=IPT
        IF (LSLINL) THEN
          IPT = IPT+1
          YT9%MSVDNL_SI=IPT
          IPT = IPT+1
          YT9%MSPDNL_SI=IPT
        ENDIF
      ENDIF
      IF(LPC_OLD)THEN
        IPT = IPT+1
        YT9%MYNL=IPT
      ENDIF
      IF (NVDVAR==4) THEN
        IPT = IPT+1
        YT9%MNHX=IPT
      ENDIF
    ENDIF
    IF(LNHDYN.AND.LRDBBC) THEN
      IPT = IPT+1
      YT9%MDPHI = IPT
    ENDIF
  ENDIF

  ! * GMVS:
  IF(LPC_FULL.OR.LTENC)THEN  
    IPTS    = IPTS+1
    YT9%MSP  = IPTS
    IPTS    = IPTS+1
    YT9%MSPM = IPTS
    IPTS    = IPTS+1
    YT9%MSPL = IPTS
  ENDIF
  IF(LPC_FULL.AND.LMPHYS)THEN  
    IPTS    = IPTS+1
    YT9%MCSPPT = IPTS
  ENDIF
  IF(LNHDYN.AND.LRDBBC) THEN
    IPTS    = IPTS+1
    YT9%MDBBC = IPTS
    IF(LPC_FULL) THEN
      IPTS    = IPTS+1
      YT9%MGWS = IPTS
    ENDIF
  ENDIF

ELSE

  ! LPC_FULL pointers only valid for Eulerian code only.
  ! LPC_FULL not yet coded for SL3TL.

  ! * GMV:
  IPT   = IPT+1
  YT9%MDIV = IPT
  IPT   = IPT+1
  YT9%MU = IPT
  IPT   = IPT+1
  YT9%MV = IPT
  IF(NFTHER > 0) THEN
    IPT   = IPT+1
    YT9%MT = IPT
    IPT   = IPT+1
    YT9%MTL = IPT
    IPT   = IPT+1
    YT9%MTM = IPT
  ENDIF
  IF(LVERCOR.AND.LSLAG) THEN
    IPT   = IPT+1
    YT9%MVCASRS=IPT
  ENDIF
  IF(LRWSDLR.AND.LSLAG) THEN
    IPT   = IPT+1
    YT9%MRDLASR=IPT
  ENDIF
  IF(LNHDYN) THEN
    IPT   = IPT+1
    YT9%MSPD = IPT
    IPT   = IPT+1
    YT9%MSVD = IPT
    IPT   = IPT+1
    YT9%MSPDL = IPT
    IPT   = IPT+1
    YT9%MSVDL = IPT
    IPT   = IPT+1
    YT9%MSPDM = IPT
    IPT   = IPT+1
    YT9%MSVDM = IPT
    IF (NVDVAR == 4) THEN
      IPT   = IPT+1
      YT9%MNHX= IPT
      IF(LPC_FULL)THEN
        IPT = IPT+1
        YT9%MNHXNL=IPT
        IPT = IPT+1
        YT9%MCNHXNL=IPT
      ENDIF
    ENDIF
  ENDIF
  IF( LPC_FULL )THEN
    IPT = IPT+1
    YT9%MUNL = IPT
    IPT = IPT+1
    YT9%MVNL = IPT
    IPT = IPT+1
    YT9%MTNL =IPT
    IF( LNHDYN )THEN
      IPT = IPT+1
      YT9%MVWVNL=IPT
      IPT = IPT+1
      YT9%MSPDNL=IPT
    ENDIF
    IPT = IPT+1
    YT9%MCUNL=IPT
    IPT = IPT+1
    YT9%MCVNL=IPT
    IPT = IPT+1
    YT9%MCTNL=IPT
    IF(LNHDYN) THEN
      IPT = IPT+1
      YT9%MCVWVNL=IPT
      IPT = IPT+1
      YT9%MCSPDNL=IPT
    ENDIF
    IPT = IPT+1
    YT9%MCURHS=IPT
    IPT = IPT+1
    YT9%MCVRHS=IPT
    IPT = IPT+1
    YT9%MCTRHS=IPT
    IF(LNHDYN) THEN
      IPT = IPT+1
      YT9%MCSVDRHS=IPT
      IPT = IPT+1
      YT9%MCSPDRHS=IPT
    ENDIF
  ENDIF
  
  ! * GMVS:
  IPTS    = IPTS+1
  YT9%MSP  = IPTS
  IPTS    = IPTS+1
  YT9%MSPM = IPTS
  IPTS    = IPTS+1
  YT9%MSPL = IPTS
  IF( LPC_FULL )THEN
    ! ky: MSPNL,MSPNL_SI are in GMVS in EUL but in GMV in SL.
    IPTS    = IPTS+1
    YT9%MSPNL  = IPTS           
    IF (LSLINLC1) THEN
      IPTS    = IPTS+1
      YT9%MSPNL_SI  = IPTS           
    ENDIF
    IPTS    = IPTS+1
    YT9%MCSPNL  = IPTS           
    IPTS    = IPTS+1
    YT9%MCSPRHS  = IPTS           
  ENDIF  

ENDIF

YT9%NDIM  = IPT -YT0%NDIM
YT9%NDIMS = IPTS-YT0%NDIMS

WRITE(NULOUT,*)' * SETUP_T9 : t-dt POINTERS (YT9)'
WRITE(NULOUT,*)' MU=',YT9%MU,'MV=',YT9%MV,&
 & ' MT=',YT9%MT,' MTL=',YT9%MTL,' MTM=',YT9%MTM  
WRITE(NULOUT,*)' MEDOT=',YT9%MEDOT,' MUNL=',YT9%MUNL,&
 & ' MVNL=',YT9%MVNL,' MTNL=',YT9%MTNL  
WRITE(NULOUT,*)' MSPNL=',YT9%MSPNL,' MVCASRS=',YT9%MVCASRS,&
 & ' MRDLASR=',YT9%MRDLASR,' MVWVNL=',YT9%MVWVNL  
WRITE(NULOUT,*)' MSPDNL=',YT9%MSPDNL,' MYNL=',YT9%MYNL,&
 & ' MDIV=',YT9%MDIV,' MVOR=',YT9%MVOR  
WRITE(NULOUT,*)' MUL=',YT9%MUL,' MVL=',YT9%MVL,' MSPD=',YT9%MSPD,&
 & ' MSPDL=',YT9%MSPDL,' MSPDM=',YT9%MSPDM  
WRITE(NULOUT,*)' MSVD=',YT9%MSVD,' MSVDL=',YT9%MSVDL,' MSVDM=',YT9%MSVDM,&
 & ' MNHX=',YT9%MNHX  
WRITE(NULOUT,*)' MCUNL=',YT9%MCUNL,' MCVNL=',YT9%MCVNL,' MCTNL=',YT9%MCTNL,&
 & ' MCSPNL=',YT9%MCSPNL  
WRITE(NULOUT,*)' MCUPT=',YT9%MCUPT,' MCVPT=',YT9%MCVPT,' MCTPT=',YT9%MCTPT
WRITE(NULOUT,*)' MCVWVNL=',YT9%MCVWVNL
WRITE(NULOUT,*)' MCSPDNL=',YT9%MCSPDNL
WRITE(NULOUT,*)' MSP=',YT9%MSP,' MSPL=',YT9%MSPL,' MSPM=',YT9%MSPM,&
 & ' MCSPPT=',YT9%MCSPPT
WRITE(NULOUT,*)' MDPHI=',YT9%MDPHI
WRITE(NULOUT,*)' MDBBC=',YT9%MDBBC,' MGWS=',YT9%MGWS

WRITE(NULOUT,*)' MNHXNL=',YT9%MNHXNL,' MCNHXNL=',YT9%MCNHXNL

! JV 3TL ICI scheme
WRITE(NULOUT,*)' ------ arrays for 3TL ICI scheme (iterative scheme) ----'
WRITE(NULOUT,*)' MCURHS=',YT9%MCURHS,' MCVRHS=',YT9%MCVRHS
WRITE(NULOUT,*)' MCTRHS =',YT9%MCTRHS
WRITE(NULOUT,*)' MCSPRHS =',YT9%MCSPRHS
WRITE(NULOUT,*)' MCSPDRHS =',YT9%MCSPDRHS
WRITE(NULOUT,*)' MCSVDRHS =',YT9%MCSVDRHS
WRITE(NULOUT,*)' ---------------------------------------------------------'
WRITE(NULOUT,*)' ------ arrays for 2TL LGWADV PC_FULL scheme (iterative scheme) ----'
WRITE(NULOUT,*)' MGW=',YT9%MGW

WRITE(NULOUT,*)' Pointers for separate linear terms '
WRITE(NULOUT,*)' MUNL_SI   =',YT9%MUNL_SI
WRITE(NULOUT,*)' MVNL_SI   =',YT9%MVNL_SI
WRITE(NULOUT,*)' MTNL_SI   =',YT9%MTNL_SI
WRITE(NULOUT,*)' MSPNL_SI  =',YT9%MSPNL_SI
WRITE(NULOUT,*)' MSVDNL_SI =',YT9%MSVDNL_SI
WRITE(NULOUT,*)' MSPDNL_SI =',YT9%MSPDNL_SI

IF (LHOOK) CALL DR_HOOK('GMV_SUBS_MOD:SETUP_T9',1,ZHOOK_HANDLE)

END SUBROUTINE SETUP_T9

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

SUBROUTINE SETUP_T1

INTEGER(KIND=JPIM) :: IPT,IPTS
REAL(KIND=JPRB) :: ZHOOK_HANDLE

! Field pointers in GMVT1
IF (LHOOK) CALL DR_HOOK('GMV_SUBS_MOD:SETUP_T1',0,ZHOOK_HANDLE)
YT1%MU = NUNDEFLD
YT1%MV = NUNDEFLD
YT1%MT = NUNDEFLD
YT1%MSPD = NUNDEFLD
YT1%MSVD = NUNDEFLD
YT1%MVOR = NUNDEFLD
YT1%MDIV = NUNDEFLD
YT1%MNHX = NUNDEFLD
! Field pointers in GMVT1S
YT1%MSP = NUNDEFLD

IPT  = 0
IPTS = 0

! Field pointers in GMVT1
IPT = IPT+1
YT1%MU = IPT
IPT = IPT+1
YT1%MV = IPT
IF (NFTHER > 0) THEN
  IPT = IPT+1
  YT1%MT = IPT
ENDIF
IF(LNHDYN) THEN
  IPT = IPT+1
  YT1%MSPD = IPT
  IPT = IPT+1
  YT1%MSVD = IPT
  IF(LNHX) THEN
    IPT = IPT+1
    YT1%MNHX = IPT
  ENDIF
ENDIF
! MVOR and MDIV are equivalanced to MU and MV for use in gridpoint Jb
! calculations and a special option of the Direct Transforms (Config G)
YT1%MVOR = YT1%MU
YT1%MDIV = YT1%MV
! Field pointers in GMVT1S
IPTS    = IPTS+1
YT1%MSP  = IPTS
  
YT1%NDIM  = IPT
YT1%NDIMS = IPTS

WRITE(NULOUT,*)' * SETUP_T1 : t+dt POINTERS (YT1)'
WRITE(NULOUT,*)' MU=',YT1%MU,'MV=',YT1%MV,' MT=',YT1%MT
WRITE(NULOUT,*)' MSPD=',YT1%MSPD,' MSVD=',YT1%MSVD,' MSP=',YT1%MSP
WRITE(NULOUT,*)' MVOR=',YT1%MVOR,' MDIV=',YT1%MDIV,' MNHX=',YT1%MNHX
IF (LHOOK) CALL DR_HOOK('GMV_SUBS_MOD:SETUP_T1',1,ZHOOK_HANDLE)

END SUBROUTINE SETUP_T1

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

SUBROUTINE SETUP_PH9

! Field pointers in GMV
REAL(KIND=JPRB) :: ZHOOK_HANDLE
IF (LHOOK) CALL DR_HOOK('GMV_SUBS_MOD:SETUP_PH9',0,ZHOOK_HANDLE)
YPH9%MU = NUNDEFLD
YPH9%MV = NUNDEFLD
YPH9%MT = NUNDEFLD

! Field pointers in GMVS
YPH9%MSP = NUNDEFLD

IF(LTWOTL) THEN
! Field pointers in GMV
  YPH9%MU = YT0%MU
  YPH9%MV = YT0%MV
  YPH9%MT = YT0%MT
! Field pointers in GMVS
  YPH9%MSP = YT0%MSP
ELSE
! Field pointers in GMV
  YPH9%MU = YT9%MU
  YPH9%MV = YT9%MV
  YPH9%MT = YT9%MT
! Field pointers in GMVS
  YPH9%MSP = YT9%MSP
ENDIF  

WRITE(NULOUT,*)' SETUP_PH9 : PH9 POINTERS (YPH9)'
WRITE(NULOUT,*)' MU=',YPH9%MU,'MV=',YPH9%MV,' MT=',YPH9%MT,' MSP=',YPH9%MSP
IF (LHOOK) CALL DR_HOOK('GMV_SUBS_MOD:SETUP_PH9',1,ZHOOK_HANDLE)

END SUBROUTINE SETUP_PH9
SUBROUTINE SETUP_PH9_PRED

! Field pointers in GMV
REAL(KIND=JPRB) :: ZHOOK_HANDLE
IF (LHOOK) CALL DR_HOOK('GMV_SUBS_MOD:SETUP_PH9_PRED',0,ZHOOK_HANDLE)
YPH9%MU = NUNDEFLD
YPH9%MV = NUNDEFLD
YPH9%MT = NUNDEFLD

! Field pointers in GMVS
YPH9%MSP = NUNDEFLD

IF(LTWOTL) THEN
! Field pointers in GMV
  YPH9%MU = YT0%MU
  YPH9%MV = YT0%MV
  YPH9%MT = YT0%MT
! Field pointers in GMVS
  YPH9%MSP = YT0%MSP
ELSE
! Field pointers in GMV
  YPH9%MU = YT9%MU
  YPH9%MV = YT9%MV
  YPH9%MT = YT9%MT
! Field pointers in GMVS
  YPH9%MSP = YT9%MSP
ENDIF

WRITE(NULOUT,*)' MODIFICATION OF PH9 POINTERS FOR PREDICTOR STEP'
WRITE(NULOUT,*)' MU=',YPH9%MU,'MV=',YPH9%MV,' MT=',YPH9%MT,' MSP=',YPH9%MSP
IF (LHOOK) CALL DR_HOOK('GMV_SUBS_MOD:SETUP_PH9_PRED',1,ZHOOK_HANDLE)

END SUBROUTINE SETUP_PH9_PRED
SUBROUTINE SETUP_PH9_CORR

! Field pointers in GMV
REAL(KIND=JPRB) :: ZHOOK_HANDLE
IF (LHOOK) CALL DR_HOOK('GMV_SUBS_MOD:SETUP_PH9_CORR',0,ZHOOK_HANDLE)
YPH9%MU = NUNDEFLD
YPH9%MV = NUNDEFLD
YPH9%MT = NUNDEFLD

! Field pointers in GMVS
YPH9%MSP = NUNDEFLD

IF(LTWOTL) THEN
! Field pointers in GMV
  YPH9%MU = YT9%MU
  YPH9%MV = YT9%MV
  YPH9%MT = YT9%MT
! Field pointers in GMVS
  YPH9%MSP = YT9%MSP
ELSE
! These pointers used only for ECMWF Physics - to be done later for leap-frog scheme.
! Field pointers in GMV
  YPH9%MU = YT9%MU
  YPH9%MV = YT9%MV
  YPH9%MT = YT9%MT
! Field pointers in GMVS
  YPH9%MSP = YT9%MSP
ENDIF

WRITE(NULOUT,*)' MODIFICATION OF PH9 POINTERS FOR CORRECTOR STEP'
WRITE(NULOUT,*)' MU=',YPH9%MU,'MV=',YPH9%MV,' MT=',YPH9%MT,' MSP=',YPH9%MSP
IF (LHOOK) CALL DR_HOOK('GMV_SUBS_MOD:SETUP_PH9_CORR',1,ZHOOK_HANDLE)

END SUBROUTINE SETUP_PH9_CORR

!-------------------------------------------------------------------------
END MODULE GMV_SUBS_MOD
