!-------------------------------------- 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 e_gettopo
*
#include "model_macros_f.h"
*

      subroutine e_gettopo 1,7
      implicit none
*
*author M. Desgagne
*
*revision
* v3_30 - M. Desgagne          - initial version
*
#include "e_topo.cdk"
#include "e_fu.cdk"
#include "e_grids.cdk"
#include "hgc.cdk"
#include "e_cdate.cdk"
#include "path.cdk"
**
      integer  e_rdhint3,fnom,fstouv,fstfrm,fclos
      external e_rdhint3,fnom,fstouv,fstfrm,fclos
      integer n,nu,nv,codp1,err
*
*----------------------------------------------------------------------
*
      n  = nifi*njfi
      nu = niu *nju
      nv = niv *njv
      allocate (topo (n), topou (nu), topov (nv),
     $          topof(n), topouf(nu), topovf(nv))
*
      if ( .not. Topo_init_L ) then
         topo  = 0.0 ;  topou  = 0.0 ;  topov  = 0.0
         topof = 0.0 ;  topouf = 0.0 ;  topovf = 0.0
         return
      endif
*
      e_fu_geophy = 0
      if (fnom  (e_fu_geophy,trim(Path_input_S)//'/GEOPHY' ,'RND+OLD',0).lt.0) stop
      if (fstouv(e_fu_geophy,'RND').lt.0) stop
*
      datev = -1

      call convip ( codp1, 0., 3, 1, ' ', .false. )
      err = e_rdhint3 (topo,dstf_gid,nifi,njfi,'ME',codp1,-1,-1,
     $             ' ','C',.true.,.false.,'CUBIC',e_fu_geophy,6)
      if (err.lt.0) goto 55
      call convip ( codp1, 1., 3, 1, ' ', .false. )
      if (e_rdhint3(topou,dstu_gid,niu,nju,'ME',codp1,-1,-1,' ','C',
     $          .true.,.false.,'CUBIC',e_fu_geophy,6).lt.0) goto 55
      call convip ( codp1, 2., 3, 1, ' ', .false. )
      if (e_rdhint3(topov,dstv_gid,niv,njv,'ME',codp1,-1,-1,' ','C',
     $          .true.,.false.,'CUBIC',e_fu_geophy,6).lt.0) goto 55
*
      topo  (:) = max ( 0.0, topo (:) )
      topou (:) = max ( 0.0, topou(:) )
      topov (:) = max ( 0.0, topov(:) )
*
      call e_filtopx (topof , topo , nifi, njfi, 'G')
      call e_filtopx (topouf, topou, niu , nju , 'U')
      call e_filtopx (topovf, topov, niv , njv , 'V')
*
      err = fstfrm (e_fu_geophy)
      err = fclos  (e_fu_geophy)
*
      return
 55   call e_arret( 'e_gettopo' )
*----------------------------------------------------------------------
*
      return
      end