!-------------------------------------- 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 --------------------------------------
#if defined (DOC)
*
***comdeck adw.cdk
*______________________________________________________________________
*                                                                      |
* GRIDS USED IN THE ADVECTION CONTEXT                                  |
*                                                                      |
* revision                                                             |
* v3_20 - Gravel & Valin & Tanguay - Lagrange 3D                       | 
*                                    and Optimized SETINT/TRILIN       |
* v3_30 - McTaggart-Cowan R.	   - Add Adw_interp_type options       |
*______________________________________________________________________|
*                                                                      |
* 3 different grids are refered to throughout the advection process:   |
*                                                                      |
* GLOBAL GRID:    Global domain                                        |
*                                                                      |
* ADVECTION GRID: In the general case, the tiles adjacent to the poles |
*                 would have an advection source grid periodic in x.   |
*                 For the other tiles, the advection grid would be the |
*                 same as the local grid.                              |
*                                                                      |
* LOCAL GRID:     Local domain                                         |
*                                                                      |
* All of these grids could include halos or not                        |
*______________________________________________________________________|
*                                                                      |
* VARIABLES FOR ADVECTION                                              |
*______________________________________________________________________|
*              |                                                       |
* NAME         | DESCRIPTION                                           |
*--------------|-------------------------------------------------------|
* Adw_nkbz_L   | switch: .true. : no knot boundary condition for       |
*              |                  vertical interpolation               |
* Adw_exdg_L   | switch: .true. : print diagnostics on the number of   |
*              |                  upstream positions exchanged among   |
*              |                  processors                           |
* Adw_ckbd_L   | switch: .true. : check if upstream points from north  |
*              |                  and south pe's for which an interpo- |
*              |                  lation is requested are inside own   |
*              |                  advection source grid                |
* Adw_mono_L   | switch: .true. : advection of tracers is monotonic    |
* Adw_interp_type interpolation scheme for back-trajectories ("cubic"):|
*	       |  "cubic"         Lagrangian(h)/cubic(v) interpolation |
*	       |  "lag3d"         tri-Lagrangian 3D interpolation      |
*	       |  "lag3d_trunc "  truncated Lagrangian 3D interpolation|
* Adw_nosetint_L switch: .true. : no setint for TRILIN (done inside)   |
* Adw_hor_L    | switch: .true. : update horizontal positions          |
*              |                  for Optimized SETINT/TRILIN          |
* Adw_ver_L    | switch: .true. : update vertical positions            |
*              |                  for Optimized SETINT/TRILIN          |
*----------------------------------------------------------------------|
* GRIDS SIZE SPECIFICATIONS                                            |
*----------------------------------------------------------------------|
* Adw_halox    | advection specific halo in x                          |
* Adw_haloy    | advection specific halo in y                          |
*              |                                                       |
* Adw_nit      | \ total number of points in x,y direction in          |
* Adw_njt      | / advection grid (including halos)                    |
*              |                                                       |
* Adw_nic      | \ number of points in x,y direction in central        |
* Adw_njc      | / portion of advection grid (excluding halos)         |
*              |                                                       |
* Adw_int_i_off| offset global-advection grids in x                    |
* Adw_int_j_off| offset global-advection grids in y                    |
*----------------------------------------------------------------------|
* GRIDS COORDINATES SPECIFICATIONS AND DEPENDENT PARAM                 |
*----------------------------------------------------------------------|
* Adw_xg_8     | global grid x coordinates                             |
* Adw_yg_8     | global grid y coordinates                             |
* Adw_wx_8     | global grid weights proportional grid distances       |
* Adw_xx_8     | local grid x coordinates                              |
* Adw_cx_8     | local grid cos of x                                   |
* Adw_sx_8     | local grid sin of x                                   |
* Adw_yy_8     | local grid x coordinates                              |
* Adw_cy_8     | local grid cos of y                                   |
* Adw_sy_8     | local grid sin of y                                   |
* Adw_cx2d_8   | local grid 2D array filled with cos of x              |
* Adw_sx2d_8   | local grid 2D array filled with sin of x              |
* Adw_cy2d_8   | local grid 2D array filled with cos of y              |
* Adw_sy2d_8   | local grid 2D array filled with sin of y              |
*----------------------------------------------------------------------|
* UPSTREAM POSITIONS EXCHANGE PARAMETERS                               |
*----------------------------------------------------------------------|
* Adw_for_n    | number of information points for  north neighbor      |
* Adw_for_s    | number of information points for  south neighbor      |
* Adw_for_a    | number of information points for  all   neighbor      |
* Adw_fro_n    | number of information points from north neighbor      |
* Adw_fro_s    | number of information points from south neighbor      |
* Adw_fro_a    | number of information points from all   neighbor      |
*----------------------------------------------------------------------|
* LOCALISATION PARAMETERS                                              |
*----------------------------------------------------------------------|
* Adw_ovdx_8   | \                                                     |
* Adw_ovdy_8   |   inverse of shortest grid distance in x,y,z          |
* Adw_ovdz_8   | /                                                     |
*              |                                                       |
* Adw_x00_8    | \                                                     |
* Adw_y00_8    |   reference coordinate for localisation in x,y,z      |
* Adw_z00_8    | /                                                     |
*              |                                                       |
* Adw_lcx      | \                                                     |
* Adw_lcy      |   fine grid to variable grid equivalence used for     |
* Adw_lcz      | / fast localisation                                   |
*              |                                                       |
*----------------------------------------------------------------------|
* PRECOMPUTED INTERPOLATION PARAMETERS                                 |
*----------------------------------------------------------------------|
* Adw_iln      | for interpolation of grid reflexion across the pole   |
* Adw_lnr_8    | for interpolation of grid reflexion across the pole   |
* Adw_bsx_8    | \                                                     |
* Adw_dlx_8    |  |                                                    |
* Adw_dix_8    |  |                                                    |
* Adw_bsy_8    |  |                                                    |
* Adw_dly_8    |  |                                                    |
* Adw_diy_8    |   \ precomputed interpolation parameters along x,y,z  |
* Adw_bsz_8    |   /                                                   |
* Adw_dlz_8    |  |                                                    |
* Adw_diz_8    |  |                                                    |
* Adw_dbz_8    |  |                                                    |
* Adw_qzz_8    |  |                                                    |
* Adw_qzi_8    |  |                                                    |
* Adw_xbc_8    |  | Coefficients for linear interpolation in x,y and z |
* Adw_ybc_8    |  |                                                    |
* Adw_zbc_8    |  |                                                    |
* Adw_xabcd_8  |  | Coefficients for Lagrange 3D in x,y and z          |
* Adw_xbacd_8  |  |                                                    |
* Adw_xcabd_8  |  |                                                    |
* Adw_xdabc_8  |  |                                                    |
* Adw_yabcd_8  |  |                                                    |
* Adw_ybacd_8  |  |                                                    |
* Adw_ycabd_8  |  |                                                    |
* Adw_ydabc_8  |  |                                                    |
* Adw_zabcd_8  |  |                                                    |
* Adw_zbacd_8  |  |                                                    |
* Adw_zcabd_8  |  |                                                    |
* Adw_zdabc_8  | /                                                     |
* Adw_Fn_I     | Localisation indices for Optimized SETINT/TRILIN      |
*______________________________________________________________________
*                                                                      |
*  VARIABLES ASSOCIATED WITH CFL COMPUTATION FOR LAM (ADW_CFL_LAM)     |
*______________________________________________________________________|
*                    |                                                 |
* NAME               | DESCRIPTION                                     |
*--------------------|-------------------------------------------------|
* Adw_cfl(i,j,PE)    | i = the max value of the following:             |
*                    |     1: max cfl value found                      |
*                    |     2: the "I" grid point of max cfl found      |
*                    |     3: the "J" grid point of max cfl found      |
*                    |     4: the "K" grid point of max cfl found      |
*                    | j = the type of max cfl computed                |
*                    |     1: the largest horizontal courrant number   |
*                    |     2: the largest vertical   courrant number   |
*                    |     3: the largest 3-dimensional courrant number|
*                    |PE = the number of the PE (processor)            |
*                    |     The overall maximum cfl value of the entire |
*                    |     grid will be placed in PE 1 before printing |
*______________________________________________________________________|
*
#endif
*
      logical            Adw_nkbz_L, Adw_exdg_L, Adw_ckbd_L, 
     %                   Adw_mono_L,Adw_nosetint_L,Adw_hor_L,Adw_ver_L
*
      integer            Adw_halox, Adw_haloy,
     %                   Adw_nic, Adw_nit, Adw_njc, Adw_njt,
     %                   Adw_int_i_off, Adw_int_j_off,
     %                   Adw_for_n, Adw_for_s, Adw_for_a,
     %                   Adw_fro_n, Adw_fro_s, Adw_fro_a,
     %                   Adw_cfl_i(3,3)
*
      real*8             Adw_ovdx_8, Adw_ovdy_8, Adw_ovdz_8, 
     %                   Adw_x00_8,  Adw_y00_8,  Adw_z00_8, Adw_cfl_8(3)
*
      character(len=64) :: Adw_interp_type_S
*
      MARK_COMMON_BEG (adw_c)
      common / adw_c  /  Adw_interp_type_S
      MARK_COMMON_END (adw_c)
*
      MARK_COMMON_BEG (adw_l)
      common / adw_l  /  Adw_nkbz_L,Adw_exdg_L,Adw_nosetint_L,
     %                   Adw_ckbd_L,Adw_mono_L,
     %                   Adw_hor_L, Adw_ver_L
      MARK_COMMON_END (adw_l)
*
      MARK_COMMON_BEG (adw_ia)
      common / adw_ia /  Adw_halox, Adw_haloy
      MARK_COMMON_END (adw_ia)
*
      common / adw_ib /  Adw_nic, Adw_nit, Adw_njc, Adw_njt,
     %                   Adw_int_i_off, Adw_int_j_off,
     %                   Adw_for_n, Adw_for_s, Adw_for_a,
     %                   Adw_fro_n, Adw_fro_s, Adw_fro_a,
     %                   Adw_cfl_i
*
      common / adw_r8 /  Adw_ovdx_8, Adw_ovdy_8, Adw_ovdz_8, 
     %                   Adw_x00_8,  Adw_y00_8,  Adw_z00_8, Adw_cfl_8
*
      DCL_DYNVAR(Adw,   xg_8,    real*8 , (*))
      DCL_DYNVAR(Adw,   yg_8,    real*8 , (*))
      DCL_DYNVAR(Adw,   wx_8,    real*8 , (*))
      DCL_DYNVAR(Adw,   xx_8,    real*8 , (*))
      DCL_DYNVAR(Adw,   cx_8,    real*8 , (*))
      DCL_DYNVAR(Adw,   sx_8,    real*8 , (*))
      DCL_DYNVAR(Adw,   yy_8,    real*8 , (*))
      DCL_DYNVAR(Adw,   cy_8,    real*8 , (*))
      DCL_DYNVAR(Adw,   sy_8,    real*8 , (*))
      DCL_DYNVAR(Adw, cx2d_8,    real*8 , (*))
      DCL_DYNVAR(Adw, sx2d_8,    real*8 , (*))
      DCL_DYNVAR(Adw, cy2d_8,    real*8 , (*))
      DCL_DYNVAR(Adw, sy2d_8,    real*8 , (*))
      DCL_DYNVAR(Adw,    lcx,    integer, (*))
      DCL_DYNVAR(Adw,    lcy,    integer, (*))
      DCL_DYNVAR(Adw,    lcz,    integer, (*))
*
      DCL_DYNVAR(Adw,  fn_I ,    integer, (*))
*
      DCL_DYNVAR(Adw,  bsx_8,    real*8 , (*))
      DCL_DYNVAR(Adw,  dlx_8,    real*8 , (*))
      DCL_DYNVAR(Adw,  dix_8,    real*8 , (*))
      DCL_DYNVAR(Adw,  bsy_8,    real*8 , (*))
      DCL_DYNVAR(Adw,  dly_8,    real*8 , (*))
      DCL_DYNVAR(Adw,  diy_8,    real*8 , (*))
      DCL_DYNVAR(Adw,  bsz_8,    real*8 , ( 0:*))
      DCL_DYNVAR(Adw,  dlz_8,    real*8 , (-1:*))
      DCL_DYNVAR(Adw,  diz_8,    real*8 , (-1:*))
      DCL_DYNVAR(Adw,  dbz_8,    real*8 , ( 0:*))
*
      DCL_DYNVAR(Adw,  iln  ,    integer, (*))
      DCL_DYNVAR(Adw,  lnr_8,    real*8 , (*))
*
      DCL_DYNVAR(Adw,  qzz_8,    real*8 , (*))
      DCL_DYNVAR(Adw,  qzi_8,    real*8 , (*))
*
      DCL_DYNVAR(Adw,  xbc_8,    real*8 , (*))
      DCL_DYNVAR(Adw,  ybc_8,    real*8 , (*))
      DCL_DYNVAR(Adw,  zbc_8,    real*8 , (*))
*
      DCL_DYNVAR(Adw,xabcd_8,    real*8 , (*))
      DCL_DYNVAR(Adw,xbacd_8,    real*8 , (*))
      DCL_DYNVAR(Adw,xcabd_8,    real*8 , (*))
      DCL_DYNVAR(Adw,xdabc_8,    real*8 , (*))
      DCL_DYNVAR(Adw,yabcd_8,    real*8 , (*))
      DCL_DYNVAR(Adw,ybacd_8,    real*8 , (*))
      DCL_DYNVAR(Adw,ycabd_8,    real*8 , (*))
      DCL_DYNVAR(Adw,ydabc_8,    real*8 , (*))
      DCL_DYNVAR(Adw,zabcd_8,    real*8 , (*))
      DCL_DYNVAR(Adw,zbacd_8,    real*8 , (*))
      DCL_DYNVAR(Adw,zcabd_8,    real*8 , (*))
      DCL_DYNVAR(Adw,zdabc_8,    real*8 , (*))
*
      DCL_DYNVAR(Adw,  capx1,    real   , (*))
      DCL_DYNVAR(Adw,  capy1,    real   , (*))
      DCL_DYNVAR(Adw,  capz1,    real   , (*))
      DCL_DYNVAR(Adw,   xdd1,    real   , (*))
      DCL_DYNVAR(Adw,   ydd1,    real   , (*))
      DCL_DYNVAR(Adw,   xgg1,    real   , (*))
      DCL_DYNVAR(Adw,   ygg1,    real   , (*))
      DCL_DYNVAR(Adw,    cz1,    real   , (*))
      DCL_DYNVAR(Adw,     n1,    real   , (*))
      DCL_DYNVAR(Adw,     c1,    real   , (*))
      DCL_DYNVAR(Adw,   wrkb,    real   , (*))
      DCL_DYNVAR(Adw,   wrkc,    real   , (*))
      DCL_DYNVAR(Adw,  capx2,    real   , (*))
      DCL_DYNVAR(Adw,  capy2,    real   , (*))
      DCL_DYNVAR(Adw,  capz2,    real   , (*))
      DCL_DYNVAR(Adw,   xdd2,    real   , (*))
      DCL_DYNVAR(Adw,   ydd2,    real   , (*))
      DCL_DYNVAR(Adw,   xgg2,    real   , (*))
      DCL_DYNVAR(Adw,   ygg2,    real   , (*))
      DCL_DYNVAR(Adw,    cz2,    real   , (*))
      DCL_DYNVAR(Adw,     n2,    real   , (*))
      DCL_DYNVAR(Adw,   wrka,    real   , (*))