!-------------------------------------- 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 sol_main_tr - Equivalent to sol_main for TRAJECTORY 
*
#include "model_macros_f.h"
*

      subroutine sol_main_tr (iln) 3,3
*
      implicit none
*
      integer iln
*
*author
*     M.Tanguay
*
*revision
* v2_10 - Tanguay M.        - initial MPI version
* v2_21 - Tanguay M.        - reduce standard output as in model 
* v2_31 - Tanguay M.        - adapt to f90 native dynamic memory allocation 
* v3_11 - Tanguay M.        - AIXport+Opti+OpenMP for TLM-ADJ
* v3_30 - Tanguay M.        - add parameter iln in sol_main
*
*object
*     see id section
*	
*arguments
*     none
*
*implicits
#include "glb_ld.cdk"
#include "ldnh.cdk"
#include "lun.cdk"
#include "vtxm.cdk"
#include "rhscm.cdk"
#include "trp.cdk"
#include "fft.cdk"
#include "ptopo.cdk"
*
*modules
      integer vmmlod, vmmget, vmmuld
      external vmmlod, vmmget, vmmuld
*
      integer i,j,k,pnerr,keys(2)
*      
      real*8, dimension ((ldnh_maxx-ldnh_minx+1)*(ldnh_maxy-ldnh_miny+1)*l_nk) :: rhs,sol,wk1,wk2
      real*8 fdg1((ldnh_maxy -ldnh_miny +1)*(trp_12smax-trp_12smin+1)*(G_ni+Ptopo_npex))
      real*8 fdg2((trp_12smax-trp_12smin+1)*(trp_22max -trp_22min +1)*(G_nj+Ptopo_npey))
      real*8 fdwfft((ldnh_maxy -ldnh_miny +1)*(trp_12smax-trp_12smin+1)*(G_ni+2+Ptopo_npex))
*
*     ---------------------------------------------------------------
**
      if (Lun_debug_L) write(Lun_out,1000)
*
*     Get needed fields in memory
*
      keys(1) = VMM_KEY(rhelnm)
      keys(2) = VMM_KEY(gptxm)
*
      pnerr = vmmlod( keys, 2 )
      pnerr = VMM_GET_VAR(rhelnm)
      pnerr = VMM_GET_VAR(gptxm)
*
c      if (Lun_out.gt.0) print *,'TRAJ RHELN in solver before sol_hcr'
c      call glbstat (rhelnm,'RHS',LDIST_DIM,G_nk,1,G_ni,1,G_nj,1,G_nk)
*
* Transfering rheln (real*4 with halo) into rhs (real*8 without halo)
      call sol_trsf (rhs,rhelnm,ldnh_minx,ldnh_maxx,ldnh_miny,ldnh_maxy,
     $                                              LDIST_DIM,l_nk, 1)
*
* Computing elliptic problem solution (sol)
      call sol_hcr  (sol,rhs,wk1,wk2,fdg1,fdg2,fdwfft,iln,
     $                ldnh_minx,ldnh_maxx,
     $                ldnh_miny,ldnh_maxy,ldnh_ni,ldnh_nj,l_nk)
*
* Transfering sol (real*8 without halo) into gptx (real*4 with halo)
      call sol_trsf (sol,gptxm ,ldnh_minx,ldnh_maxx,ldnh_miny,ldnh_maxy,
     $                                              LDIST_DIM,l_nk,-1)
*
c      if (Lun_out.gt.0) print *,'TRAJ GPTX in solver after sol_hcr'
c      call glbstat(gptxm,'SOL',LDIST_DIM,G_nk,1,G_ni,1,G_nj,1,G_nk)
*
      pnerr = vmmuld( -1, 0 )
*
**********************************************************************
*
 1000 format(
     +5X,'TRAJ of SOLVING LINEAR HELMHOLTZ PROBLEM: (S/R SOL_MAIN_TR)')
*
      return
      end