!-------------------------------------- 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 hzd_main_tr - Equivalent to hzd_main for TRAJECTORY 
*                    (F_pip, F_qp (No Hyd) ONLY)
*
#include "model_macros_f.h"
*

      subroutine hzd_main_tr  3,5
*
      implicit none
*
*author
*     M.Tanguay
*
*revision
* v3_03 - Tanguay M.        - initial MPI version
* v3_11 - Tanguay M.        - AIXport+Opti+OpenMP for TLM-ADJ
* v3_20 - Tanguay M.        - Introduce Hzd_hzdmain_n_L 
* v3_30 - Tanguay M.        - activate Hzd_type_S='EXPLICIT' 
*
*object
*     see id section
*	
*arguments
*     none
*
*implicits
#include "glb_ld.cdk"
#include "vt1m.cdk"
#include "hzd.cdk"
#include "eigv.cdk"
#include "fft.cdk"
#include "schm.cdk"
*
*modules
      integer  vmmlod,vmmuld,vmmget
      external vmmlod,vmmuld,vmmget
*
      integer err, nlod, key1(2)
*     _________________________________________________________________
*
      if ((.not.Hzd_fact_L).and.(.not.Hzd_ho_L).or..not.Hzd_hzdmain_0_L) then
         return
      endif
*
      key1(1) = VMM_KEY(pipt1m)
      nlod=1
      if (.not. Schm_hydro_L) then
         key1(nlod+1) = VMM_KEY(qpt1m)
         nlod=nlod+1
      endif
*
*     - - - - - - - - - - - - - - -
      err = vmmlod(key1,nlod)
*     - - - - - - - - - - - - - - -
      err = VMM_GET_VAR(pipt1m)
      qpt1m_ = 0
      if (.not. Schm_hydro_L) then
         err = VMM_GET_VAR(qpt1m)
      endif
*
*************************************
*  1. Implicit horizontal diffusion *
*************************************
*
      if (Hzd_fact_L) call hzd_fact_tr (pipt1m,qpt1m,LDIST_DIM,G_nk) 
*
      if (Hzd_ho_L) then
         if (Hzd_type_S.eq.'EXPLICIT') then
*            NOTHING TO DO
         else
         if (Fft_fast_L) then
*           use FFT in diffusion-solver
            if (G_lam) then
                call hzd_hof_lam_tr (pipt1m,qpt1m,LDIST_DIM,G_nk) 
            else
                call hzd_hof_tr (pipt1m,qpt1m,LDIST_DIM,G_nk)
            endif
         else
*           use MXMA in diffusion-solver
            if ( .not. Eigv_parity_L) then
                call hzd_ho_tr (pipt1m,qpt1m,LDIST_DIM,G_nk)
            else
                call hzd_ho_parite_tr (pipt1m,qpt1m,LDIST_DIM,G_nk)
            endif
         endif
         endif
      endif
*
      err = vmmuld(-1,0)
*    
      return
      end