!-------------------------------------- LICENCE BEGIN ------------------------------------
!Environment Canada - Atmospheric Science and Technology License/Disclaimer, 
!                     version 3; Last Modified: May 7, 2008.
!This is free but copyrighted software; you can use/redistribute/modify it under the terms 
!of the Environment Canada - Atmospheric Science and Technology License/Disclaimer 
!version 3 or (at your option) any later version that should be found at: 
!http://collaboration.cmc.ec.gc.ca/science/rpn.comm/license.html 
!
!This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
!without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
!See the above mentioned License/Disclaimer for more details.
!You should have received a copy of the License/Disclaimer along with this software; 
!if not, you can write to: EC-RPN COMM Group, 2121 TransCanada, suite 500, Dorval (Quebec), 
!CANADA, H9P 1J3; or send e-mail to service.rpn@ec.gc.ca
!-------------------------------------- LICENCE END --------------------------------------
***s/r set_vt -	initialization of the commons for time-dependent
*		variable. Virtual Memory manager initialization
*
#define SPY_VMM_CREATE spy_vmm_create
#include "model_macros_f.h"


      subroutine set_vt 1
*
      implicit none
*
*author
*    sylvie gravel - rpn - august 1993
*
*revision
* v2_00 - Desgagne/Lee   - initial MPI version (from set_vt v1_03)
* v2_21 - J. P. Toviessi - rename some model output variables
* v2_30 - Edouard S.     - remove pi' at the top
* v2_31 - Desgagne M.    - remove HU and QC and call to set_trin and
*                          re-introduce 3D tracers
* v3_00 - Desgagne & Lee - Lam configuration
* v3_31 - Tanguay M.     - Introduce time extrapolation 
* v3_31 - Tanguay M.     - SETTLS option
*
*object
*	See above id.
*	
*arguments
*	none
*
*implicits
#include "glb_ld.cdk"
#include "lun.cdk"
#include "schm.cdk"
#include "vt0.cdk"
#include "vth.cdk"
#include "vt1.cdk"
#include "vt2.cdk"
#include "vtw.cdk"
#include "vtx.cdk"
#include "tr3d.cdk"
#include "step.cdk"
*
*modules
      integer vmmcre
      external vmmcre
*
      character*80 attri_S,attri2_S,attrit_S
      integer i
*
*Notes:
*	The level at time t0 is not created explicitly in the
*	VMM manager tables.
*	It exists in the timestep by renaming the variables
*	created at time level t1 when they are not needed anymore
*	and will bear the same attributes.
*	However, for clarity, a complete comdeck is created
*	for all of the variables at time t0 and the keys
*	will be shuffled at run time according to the renaming
*	performed.
*	The user will therefore use two separate sets
*	of variables for clarity, but will only be using one in
*	memory or disk.
*       vt0 (VMM variables at time t0)
*       vt1 (VMM variables at time t1)
*       vt2 (VMM variables at time t2)
*       vth (VMM variables at time th [t0-dt/2])
*       vtx (VMM variables at no specific time: we do not carry from
*            t0 to t1 and from t1 to t2.)
*
**
*
*     ---------------------------------------------------------------
*
      if (Lun_out.gt.0) write(Lun_out,1000)
*
      COMMON_INIT(vt0,-100)
      COMMON_INIT(vth,-100)
      COMMON_INIT(vt1,-100)
      COMMON_INIT(vt2,-100)
      COMMON_INIT(vtw,-100)
      COMMON_INIT(vtx,-100)
      attri_S  = 'SAVE=Y,CL=1,W=5,INIT=R,MUSTEXIST'
      attri2_S = 'SAVE=Y,CL=1,W=5,INIT=0,MUSTEXIST'
      attrit_S = 'SAVE=Y,CL=3,W=5,INIT=0,MUSTEXIST'
*
*C       2.    Initialize comdeck for variables at time t0
*              -------------------------------------------
*	Assign the names of the variables
*
      VMM_NAM(ut0   )= 'UT0'
      VMM_NAM(vt0   )= 'VT0'
      VMM_NAM(wt0   )= 'WT0'
      VMM_NAM(tdt0  )= 'TDT0'
      VMM_NAM(tt0   )= 'TT0'
      VMM_NAM(fit0  )= 'FIT0'
      VMM_NAM(qt0   )= 'QT0'
      VMM_NAM(tpt0  )= 'TPT0'
      VMM_NAM(fipt0 )= 'FIP0'
      VMM_NAM(qpt0  )= 'QPT0'
      VMM_NAM(pipt0 )= 'PIP0'
      VMM_NAM(tplt0 )= 'TPL0'
      VMM_NAM(mut0  )= 'MUT0'
      VMM_NAM(psdt0 )= 'PSD0'
      VMM_NAM(st0   )= 'ST0'
      VMM_NAM(trt0  )= 'TRT0'
*
      VMM_CREATE(ut0  , LARRAY3D, 1, attri2_S)
      VMM_CREATE(vt0  , LARRAY3D, 1, attri2_S)
      VMM_CREATE(wt0  , LARRAY3D, 1, attri_S)
      VMM_CREATE(tdt0 , LARRAY3D, 1, attri_S)
      VMM_CREATE(tt0  , LARRAY3D, 1, attri_S)
      VMM_CREATE(fit0 , LARRAY3D, 1, attri_S)
      VMM_CREATE(qt0  , LARRAY3D, 1, attri_S)
      VMM_CREATE(tpt0 , LARRAY3D, 1, attri_S)
      VMM_CREATE(fipt0, LARRAY3D, 1, attri_S)
      VMM_CREATE(qpt0 , LARRAY3D, 1, attri2_S)
      VMM_CREATE(pipt0, LARRAY3D, 1, attri_S)
      VMM_CREATE(tplt0, LARRAY3D, 1, attri_S)
      VMM_CREATE(psdt0, LARRAY3D, 1, attri_S)
      VMM_CREATE(st0  , LARRAY2D, 1, attri_S)
*
      if (.not. Schm_hydro_L) then
         VMM_CREATE( mut0, LARRAY3D, 1, attri_S )
      endif
      if ( Tr3d_ntr .gt. 0 ) then
         VMM_CREATE(trt0, LARRAY3D, Tr3d_ntr, attrit_S)
      endif
*
*C       3.    Create variables at time t0-dt/2 (th)
*              -------------------------------------
*	Assign the name of the variables
*
      VMM_NAM(uth   )= 'UTH'
      VMM_NAM(vth   )= 'VTH'
      VMM_NAM(psdth )= 'PSDH'
      VMM_NAM(xth   )= 'XTH'
      VMM_NAM(yth   )= 'YTH'
      VMM_NAM(zth   )= 'ZTH'
      VMM_NAM(xcth  )= 'XCTH'
      VMM_NAM(ycth  )= 'YCTH'
      VMM_NAM(zcth  )= 'ZCTH'
*
      VMM_CREATE(uth  ,       LARRAY3D, 1, attri_S)
      VMM_CREATE(vth  ,       LARRAY3D, 1, attri_S)
      VMM_CREATE(psdth,       LARRAY3D, 1, attri_S)
      VMM_CREATE(xth  , l_ni*l_nj*l_nk, 1, attri_S)
      VMM_CREATE(yth  , l_ni*l_nj*l_nk, 1, attri_S)
      VMM_CREATE(zth  , l_ni*l_nj*l_nk, 1, attri_S)
      VMM_CREATE(xcth , l_ni*l_nj*l_nk, 1, attri_S)
      VMM_CREATE(ycth , l_ni*l_nj*l_nk, 1, attri_S)
      VMM_CREATE(zcth , l_ni*l_nj*l_nk, 1, attri_S)
*
*C       4.    Create variables at time t0-dt (t1)
*              -----------------------------------
*	Assign the names of the variables
*
      VMM_NAM(ut1   )= 'UT1'
      VMM_NAM(vt1   )= 'VT1'
      VMM_NAM(wt1   )= 'WT1'
      VMM_NAM(tdt1  )= 'TDT1'
      VMM_NAM(tt1   )= 'TT1'
      VMM_NAM(fit1  )= 'FIT1'
      VMM_NAM(qt1   )= 'QT1'
      VMM_NAM(zz1   )= 'ZZ1'
      VMM_NAM(tpt1  )= 'TPT1'
      VMM_NAM(fipt1 )= 'FIP1'
      VMM_NAM(qpt1  )= 'QPT1'
      VMM_NAM(pipt1 )= 'PIP1'
      VMM_NAM(tplt1 )= 'TPL1'
      VMM_NAM(mut1  )= 'MUT1'
      VMM_NAM(psdt1 )= 'PSD1'
      VMM_NAM(st1   )= 'ST1'
      VMM_NAM(trt1  )= 'TRT1'
*
      VMM_NAM(xt1   )= 'XT1'
      VMM_NAM(yt1   )= 'YT1'
      VMM_NAM(zt1   )= 'ZT1'
      VMM_NAM(xct1  )= 'XCT1'
      VMM_NAM(yct1  )= 'YCT1'
      VMM_NAM(zct1  )= 'ZCT1'
*
      VMM_CREATE(ut1  , LARRAY3D, 1, attri2_S)
      VMM_CREATE(vt1  , LARRAY3D, 1, attri2_S)
      VMM_CREATE(wt1  , LARRAY3D, 1, attri_S)
      VMM_CREATE(tdt1 , LARRAY3D, 1, attri_S)
      VMM_CREATE(tt1  , LARRAY3D, 1, attri_S)
      VMM_CREATE(fit1 , LARRAY3D, 1, attri_S)
      VMM_CREATE(qt1  , LARRAY3D, 1, attri_S)
      VMM_CREATE(zz1  , LARRAY3D, 1, attri_S)
      VMM_CREATE(tpt1 , LARRAY3D, 1, attri_S)
      VMM_CREATE(fipt1, LARRAY3D, 1, attri_S)
      VMM_CREATE(qpt1 , LARRAY3D, 1, attri2_S)
      VMM_CREATE(pipt1, LARRAY3D, 1, attri_S)
      VMM_CREATE(tplt1, LARRAY3D, 1, attri_S)
      VMM_CREATE(psdt1, LARRAY3D, 1, attri_S)
      VMM_CREATE(st1  , LARRAY2D, 1, attri_S)
      if (.not. Schm_hydro_L) then
         VMM_CREATE(  mut1, LARRAY3D, 1, attri_S )
      endif
      if ( Tr3d_ntr .gt. 0 ) then
         VMM_CREATE(trt1, LARRAY3D, Tr3d_ntr, attrit_S)
      endif
*
      VMM_CREATE(xt1  , l_ni*l_nj*l_nk, 1, attri_S)
      VMM_CREATE(yt1  , l_ni*l_nj*l_nk, 1, attri_S)
      VMM_CREATE(zt1  , l_ni*l_nj*l_nk, 1, attri_S)
      VMM_CREATE(xct1 , l_ni*l_nj*l_nk, 1, attri_S)
      VMM_CREATE(yct1 , l_ni*l_nj*l_nk, 1, attri_S)
      VMM_CREATE(zct1 , l_ni*l_nj*l_nk, 1, attri_S)
*
*C       5.    Create variables at time t0-2dt (t2)
*              ------------------------------------
*	Assign the names of the variables
*
      VMM_NAM(ut2   )= 'UT2'
      VMM_NAM(vt2   )= 'VT2'
      VMM_NAM(wt2   )= 'WT2'
      VMM_NAM(tdt2  )= 'TDT2'
      VMM_NAM(tt2   )= 'TT2'
      VMM_NAM(fit2  )= 'FIT2'
      VMM_NAM(qt2   )= 'QT2'
      VMM_NAM(tpt2  )= 'TPT2'
      VMM_NAM(fipt2 )= 'FIP2'
      VMM_NAM(qpt2  )= 'QPT2'
      VMM_NAM(pipt2 )= 'PIP2'
      VMM_NAM(tplt2 )= 'TPL2'
      VMM_NAM(mut2  )=  'MUT2'
      VMM_NAM(psdt2 )= 'PSD2'
      VMM_NAM(st2   )= 'ST2'
      VMM_NAM(trt2  )= 'TRT2'
*
      if (Schm_modcn.eq.Step_total) then
*
*C       5B.   Create variables at time t0-2dt (tw=t2 work space)
*              --------------------------------------------------
*       Assign the names of the variables
*
      VMM_NAM(utw   )= 'UTW'
      VMM_NAM(vtw   )= 'VTW'
      VMM_NAM(wtw   )= 'WTW'
      VMM_NAM(tdtw  )= 'TDRW'
      VMM_NAM(ttw   )= 'TTW'
      VMM_NAM(fitw  )= 'FITW'
      VMM_NAM(qtw   )= 'QTW'
      VMM_NAM(tptw  )= 'TPTW'
      VMM_NAM(fiptw )= 'FIPW'
      VMM_NAM(qptw  )= 'QPTW'
      VMM_NAM(piptw )= 'PIPW'
      VMM_NAM(tpltw )= 'TPLW'
      VMM_NAM(mutw  )= 'MUTW'
      VMM_NAM(psdtw )= 'PSDW'
      VMM_NAM(stw   )= 'STW'
      VMM_NAM(trtw  )= 'TRTW'
*
      VMM_CREATE(utw  , LARRAY3D, 1, attri2_S)
      VMM_CREATE(vtw  , LARRAY3D, 1, attri2_S)
      VMM_CREATE(wtw  , LARRAY3D, 1, attri_S)
      VMM_CREATE(tdtw , LARRAY3D, 1, attri_S)
      VMM_CREATE(ttw  , LARRAY3D, 1, attri_S)
      VMM_CREATE(fitw , LARRAY3D, 1, attri_S)
      VMM_CREATE(qtw  , LARRAY3D, 1, attri_S)
      VMM_CREATE(tptw , LARRAY3D, 1, attri_S)
      VMM_CREATE(fiptw, LARRAY3D, 1, attri_S)
      VMM_CREATE(qptw , LARRAY3D, 1, attri2_S)
      VMM_CREATE(piptw, LARRAY3D, 1, attri_S)
      VMM_CREATE(tpltw, LARRAY3D, 1, attri_S)
      VMM_CREATE(psdtw, LARRAY3D, 1, attri_S)
      VMM_CREATE(stw  , LARRAY2D, 1, attri_S)
      if (.not. Schm_hydro_L) then
         VMM_CREATE(  mutw, LARRAY3D, 1, attri_S )
      endif
      if ( Tr3d_ntr .gt. 0 ) then
         VMM_CREATE(trtw, LARRAY3D, Tr3d_ntr, attrit_S)
      endif
*
      endif
*
*C       6.    Create variables with no specific time tag
*              ------------------------------------------
*	Assign the names of the variables
*
      VMM_NAM(gptx  )= 'GPTX'
      VMM_NAM(gxtx  )= 'GXTX'
      VMM_NAM(multx) = 'MULX'
*
      VMM_CREATE(gptx , LARRAY3D, 1, attri_S)
      VMM_CREATE(gxtx , LARRAY3D, 1, attri_S)
      if (.not. Schm_hydro_L) then
         VMM_CREATE(multx, LARRAY3D, 1, attri_S)
      endif
*
 1000 format(
     +/,'INITIALIZATION OF TIME-DEP. VARIABLE COMDECKS (S/R SET_VT)',
     +/,'=========================================================')
*
*     ---------------------------------------------------------------
*
      return
      end