!-------------------------------------- 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 vtap_tr - TRAJECTORY equivalent to vtap  
*
#include "model_macros_f.h"
*

      subroutine vtap_tr 1
*
#include "impnone.cdk"
*
*author
*     M.Tanguay
*
*revision
* v3_03 - Tanguay M.        - use Ind comdeck
* v3_22 - Lee V.            - Name change from v4d_vtap_tr for to vtap_tr
*
*object
*     see id section
*
*arguments
*     none
*
*implicits
#include "glb_ld.cdk"
#include "lun.cdk"
#include "cstv.cdk"
#include "dcst.cdk"
#include "geomg.cdk"
#include "schm.cdk"
#include "ind.cdk"
#include "indm.cdk"
*
*modules
      integer i,j,k,ik,jk
*
      real pcon,pr1
*
      real*8, parameter :: ZERO_8 = 0.0
*
*     -----------------
*     Define work space
*     -----------------

      real work1(LDIST_SHAPE,l_nk), work2(LDIST_SHAPE,l_nk)
*     ______________________________________________________
*
*     Zero variables
*     --------------
      do k=1,l_nk
      do j=l_miny,l_maxy
      do i=l_minx,l_maxx
         Indm_fim (i,j,k) = ZERO_8
         Indm_fipm(i,j,k) = ZERO_8
         work1    (i,j,k) = ZERO_8
         work2    (i,j,k) = ZERO_8
      end do
      end do
      end do
*
*     --------------------------------------------------
*     Initialize special T such as d(fit1)/dZ = -(R T/Z)
*     --------------------------------------------------
      do k=1,l_nk
      do j=1,l_nj
      do i=1,l_ni
*
*        Evaluate exp(qt1)
*        -----------------
         work2(i,j,k) = Geomg_pia(k) + Geomg_pib(k)*exp(Indm_sm(i,j))
*
*        Evaluate special T 
*        ------------------
         work2(i,j,k)= (Cstv_tstr_8+Indm_tpm(i,j,k))*
     %                 (1.0+Geomg_dpib(k)*(exp(Indm_sm(i,j))-1.))*
     %                 (Geomg_z_8(k) / work2(i,j,k)) -  Cstv_tstr_8
*
      end do
      end do
      end do
*
*     Initialize GEO bottom boundary condition
*     ----------------------------------------
      do j=1,l_nj
      do i=1,l_ni
*
         work1(i,j,l_nk) = Ind_topo(i,j)
*
      end do
      end do
*
*     Build GEO from T based on VTAP relationship
*     -------------------------------------------
      pcon = - Dcst_rgasd_8 
      do jk = 0,l_nk-2
*
         ik  = l_nk-1-jk
         pr1 = - pcon*(Geomg_z_8(ik+1)-Geomg_z_8(ik))/(Geomg_z_8(ik+1)+Geomg_z_8(ik))
*
         do j = 1, l_nj 
         do i = 1, l_ni 
         work1(i,j,ik) = pr1*( work2(i,j,ik+1) + work2(i,j,ik) ) + work1(i,j,ik+1)
         end do
         end do
*
      end do
*
      do k=1,l_nk
      do j=1,l_nj
      do i=1,l_ni
*
         Indm_fim (i,j,k) = Cstvr_fistr_8(k) + work1(i,j,k)
         Indm_fipm(i,j,k) = Indm_fim(i,j,k) - Cstvr_fistr_8(k) - Ind_topo(i,j)
*
      end do
      end do
      end do
*
      return
      end