!-------------------------------------- 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 var_topo - varies topography incrementally from analysis
*                 topography to target topography
*
#include "model_macros_f.h"
*

      subroutine var_topo() 1
*
      implicit none
*
*author
*     Sylvie Gravel
*
*revision
* v3_11 - Gravel S.         - initial version
* v3_31 - McTaggart-Cowan R.- correction for Vtopo mode in digflt
*
*object
* (see above)
*
*arguments
*        None
*
*implicits
#include "glb_ld.cdk"
#include "p_geof.cdk" 
#include "lctl.cdk"
#include "dcst.cdk"
#include "vtopo.cdk"
#include "vt1.cdk"
*
*modules
      integer  vmmlod, vmmget, vmmuld
      external vmmlod, vmmget, vmmuld
*
      integer  pnerr, pnlod, pnlkey1(2), i,j,k
      integer, save :: doneStep=-1
**
      real*8 lt, pio2, f, atime, two
      parameter (two = 2.0d0)
*     __________________________________________________________________
*
* Check to see if this step has already been completed
      if (doneStep == Lctl_step) return

      pnlkey1( 1) = VMM_KEY(topo)
      pnlkey1( 2) = VMM_KEY(dtopo)
      pnlod = 2
*     - - - - - - - - - - - - - 
      pnerr = vmmlod(pnlkey1,pnlod)
*     - - - - - - - - - - - - - 
      pnerr = VMM_GET_VAR(topo)
      pnerr = VMM_GET_VAR(dtopo)
*
      lt = Vtopo_ndt
      pio2 = Dcst_pi_8 / two

      f = min(Lctl_step-Vtopo_start+1,Vtopo_ndt)
      atime  = (cos(pio2 * (f-1.)/ lt))**two
     %       - (cos(pio2 * f    / lt))**two
      do j= 1, l_nj 
      do i= 1, l_ni
         topo (i,j)   = topo(i,j)  + atime * dtopo(i,j)
      end do
      end do
*
      pnerr = vmmuld(-1,0)
*
      doneStep = Lctl_step
*
*     __________________________________________________________________
*
      return
      end