!-------------------------------------- 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 gem_ctrl - initiate the forward integration of the model
*
#include "model_macros_f.h"
*

      subroutine gem_ctrl 5,7
*
      implicit none
*
*author 
*     Michel Roch - rpn - june 1993
*
*revision
* v2_00 - Desgagne M.       - initial MPI version (from gefcn2 v1_03)
* v2_10 - Tanguay M.        - cancel indata and p_main when 4D-Var 
* v2_20 - Desgagne M.       - correction for Step_total=0
* v2_21 - Dugas B.          - adapt to climate mode
* v2_30 - Desgagne M.       - entry vertical interpolator in gemdm
* v2_31 - Tanguay M.        - initialization done_once and
*                             remove call to adv_set
* v3_21 - Tanguay M.        - do filtering at t=0 in v4d_predat
* v3_21 - valcke, S.        - add oasis coupling initialization
* v3_30 - Desgagne M.       - moved calls set_adw,set_opr to set_dync
* v3_31 - Desgagne M.       - new coupling interface to OASIS
*
*object
*     Beginning of the integration. This subroutine
*     reads the data and performs initialization if required.
*     It then initiates the forward intergration of the model.
*	
*arguments
*	none
*
*implicits
#include "init.cdk"
#include "lctl.cdk"
#include "lun.cdk"
#include "step.cdk"
#include "rstr.cdk"
#include "v4dg.cdk"
#include "vtopo.cdk"
*
      logical rstrt_L
      data rstrt_L /.false./
*
*     ---------------------------------------------------------------
*
*
*C       2.    If this is the beginning of the integration:
*              ----------------------------------------------
*
*C             a) Read input data, performs preprocessing,
*C             b) Initializes physics package with zero timestep call,
*C             c) output field at initial time on the model grid.
*C             d) perform dynamic diagnostics if required.
*C             e) write message on cmclog file for analysis cycle.
*
*
*     Evaluate logical key for Variable Topography
*
      Vtopo_L = ((Vtopo_start .ge. 0)
     %           .and. (Lctl_step-Vtopo_start .le. Vtopo_ndt))

      if ( V4dg_conf.eq.0 ) then
*
        if ( .not. Rstri_rstn_L ) then
*
           call indata()
*
        else
*
           call set_dync()
*
        endif
*
      endif
*
      Rstri_sdon = 0
*
      if ( Init_balgm_L .and. .not.Rstri_idon_L ) call initial (rstrt_L)
*
      if (.not.rstrt_L) call gem_run (.false., rstrt_L)
*
      if (rstrt_L) call wrrstrt ()
*
      if (Lun_out.gt.0) write(Lun_out,3000) Lctl_step
*
      if ( V4dg_conf.eq.0 ) then
         if (Lctl_step.eq.Step_total) then
            call wlog('FEND')
            call wlog('CEND')
         endif
      endif
*
 3000 format(
     +//,'END OF CURRENT TIME SLICE (S/R GEM_CTRL) AT TIMESTEP',I8,
     + /,'=================================================')
*
*     ---------------------------------------------------------------
*
      return
      end