!-------------------------------------- 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 - Envelope for the memory management of the 
*                 Linear Helmholtz solver
*
#include "model_macros_f.h"
*

      subroutine sol_main (iln) 2,5
      implicit none
*
      integer iln
*
*author 
*     Michel Roch - rpn - nov 1993
*
*revision
* v2_00 - Desgagne M.       - initial MPI version
* v2_40 - Lee/Qaddouri      - for LAM version
* v3_00 - Desgagne & Lee    - Lam configuration
*
*object
*	
*arguments
*	none
*
*implicits
#include "glb_ld.cdk"
#include "opr.cdk"
#include "ldnh.cdk"
#include "lun.cdk"
#include "vtx.cdk"
#include "rhsc.cdk"
#include "trp.cdk"
#include "fft.cdk"
#include "ptopo.cdk"
#include "lctl.cdk"
*
*modules
      integer vmmlod, vmmget, vmmuld
      external vmmlod, vmmget, vmmuld
*
      integer i,j,k,pnerr,keys(2),dim
      real*8 pdwrd(2)
      real   prwrd(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(rheln)
      keys(2) = VMM_KEY(gptx)
*
      pnerr = vmmlod( keys, 2 )
      pnerr = VMM_GET_VAR(rheln)
      pnerr = VMM_GET_VAR(gptx)
*
* Transfering rheln (real*4 with halo) into rhs (real*8 without halo)
      call sol_trsf (rhs,rheln,ldnh_minx,ldnh_maxx,ldnh_miny,ldnh_maxy,
     $                                              LDIST_DIM,l_nk, 1)
*
* Computing elliptic problem solution (sol)
      call tmg_start0 (40, 'SOL_0    ' )
      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)
      call tmg_stop0(40)
*
* Transfering sol (real*8 without halo) into gptx (real*4 with halo)
      call sol_trsf (sol,gptx ,ldnh_minx,ldnh_maxx,ldnh_miny,ldnh_maxy,
     $                                              LDIST_DIM,l_nk,-1)
*
      pnerr = vmmuld( -1, 0 )
*
 1000 format(
     +5X,'SOLVING LINEAR HELMHOLTZ PROBLEM: (S/R SOL_MAIN)')
*
*     ---------------------------------------------------------------
*
      return
      end