!-------------------------------------- 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 gemdm - control of the job at the highest level
*
#include "model_macros_f.h"
*

      subroutine gemdm,16
*
      implicit none
*
*author
*     M. desgagne( after version v1_03 of gefcn0 )
*
*revision
* v2_00 - Desgagne M.       - initial MPI version
* v2_10 - Tanguay M.        - introduce 4D-Var configurations 
* v2_30 - Desgagne M.       - entry vertical interpolator in gemdm
* v3_00 - Gauthier P.       - introduce subr. v4d_4dvar 
* v3_00 - Tanguay M.        - add V4dg_twin_L and V4dg_4dvar_L 
* v3_01 - Tanguay M.        - add V4dg_sgvc_L 
* v3_10 - Corbeil & Desgagne & Lee - AIXport+Opti+OpenMP
* v3_21 - Valcke, S.        - add oasis coupling termination
* v3_22 - Dugas, B.         - add gemclimdm entry point
* v3_30 - Desgagne M.       - new physics, coupling interface
* v3_31 - Desgagne M.       - new coupling interface to OASIS
*
*object
*	
*arguments
*	none
*
#include "lctl.cdk"
#include "step.cdk"
#include "v4dg.cdk"
#include "mult.cdk"
#include "lun.cdk"
**
*
*     ---------------------------------------------------------------
*
*     ===============
      entry gemclimdm
*     ===============
*
*C              Establish processor topology and model configuration
*               ----------------------------------------------------
      call set_world_view ()
*
*C              Allocate a bloc of central memory
*               ---------------------------------
      call set_mem ()
*
*C             Initialize geometry of the model
*              --------------------------------
      call set_geom ()
*
*C             Initialize the physics parameterization package
*              ----------------------------------
      call itf_phy_init ()
*
*C             Initialize the chemistry package
*              --------------------------------
      call itf_chm_init ()
*
*C             Initialize tracers
*              ---------------
      call tracers ( )
*
      call bcs_sto ( )
*
*C             Read restart if present
*              --------------------------------
      call rdrstrt( )
*
*C             Initialize coupling
*              -------------------
      call itf_cpl_init ()
*
*C             Setup commons level 1: VMM tables
*              ---------------------------------
      call set_cn1()
*
*C              Additional settings for 4D-Var 
*               ------------------------------
      if (V4dg_conf.ne.0) call v4d_setting()
*
*C             Initialize commons for output control
*              -------------------------------------
      call set_sor()
*
*     Code branching according to V4dg_conf
*     -------------------------------------
      if (V4dg_conf.eq.0) then
*
         call gem_ctrl()     ! Regular forward gem
*
      else
*
         call v4d_options
*
      endif
*
      call set_term()
*
      if (V4dg_conf.ne.0) Lctl_step = Step_total
*
      call stop_world_view (Lctl_step.lt.Step_total)
*
*     ---------------------------------------------------------------
*
      return
      end