!-------------------------------------- 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 wdpers_ad - ADJ of wdpers_tl 
*
#include "model_macros_f.h"
*

      subroutine wdpers_ad 1,3
*
#include "impnone.cdk"
*
*author
*     M.Tanguay
*
*revision
* v2_10 - Tanguay M.        - initial MPI version
* v2_21 - Tanguay M.        - reduce standard output as in model 
* v3_00 - Tanguay M.        - adapt to restructured wdpers 
* v3_20 - Tanguay M.        - 1d higher order diffusion operator 
* v3_21 - Tanguay M.        - do filtering at t=0 in v4d_predat
*
*object
*     see id section
*
*arguments
*     none
*
*implicits
#include "glb_ld.cdk"
#include "lun.cdk"
#include "vth.cdk"
#include "vt1.cdk"
#include "hzd.cdk"
#include "lctl.cdk"
*
*modules
      integer  vmmlod,vmmget,vmmuld
      external vmmlod,vmmget,vmmuld
*
      integer pnerr, pnlkey1(6)
      integer i, j, k
      integer pnlod 
*
      real *8 ZERO_8
      parameter (ZERO_8=0.0)

*     ---------------------------------------------------------------
*
      if (Lun_debug_L) write(Lun_out,1000)
*
      pnlkey1(1) = VMM_KEY(uth)
      pnlkey1(2) = VMM_KEY(vth)
      pnlkey1(3) = VMM_KEY(ut1)
      pnlkey1(4) = VMM_KEY(vt1)
      pnlkey1(5) = VMM_KEY(psdth)
      pnlkey1(6) = VMM_KEY(psdt1)
      pnlod = 6
*
      pnerr = vmmlod(pnlkey1,pnlod)
      pnerr = VMM_GET_VAR(psdth)
      pnerr = VMM_GET_VAR(psdt1)
*
      pnerr = VMM_GET_VAR(uth)
      pnerr = VMM_GET_VAR(vth)
      pnerr = VMM_GET_VAR(ut1)
      pnerr = VMM_GET_VAR(vt1)
*
*C	1. Initialise wind, pi* dot and upstream positions at
*	   time t0-dt/2 (th) for mid trajectory computations
*	   --------------------------------------------------
*
      do k=1,l_nk
         do j= 1, l_nj
         do i= 1, l_ni
*
*        ADJ 
*        ---
         psdt1(i,j,k) = psdth(i,j,k) + psdt1(i,j,k)
         psdth(i,j,k) = ZERO_8
*
         ut1(i,j,k)   = uth(i,j,k) + ut1(i,j,k)
         uth(i,j,k)   = ZERO_8
*
         end do
         end do
*
         do j= 1, l_njv
         do i= 1, l_ni
*
*        ADJ 
*        ---
         vt1(i,j,k) = vth(i,j,k) + vt1(i,j,k)
         vth(i,j,k) = ZERO_8 
*
         end do
         end do
      end do
*
*     Filtering
*     --------- 
      if (Lctl_step.gt.1) then
      if (Hzd_t1_1_L) call hzd_hoffld_ad (psdt1, LDIST_DIM, G_nk, 3)
      if (Hzd_t1_1_L) call hzd_hoffld_ad (vt1,   LDIST_DIM, G_nk, 2)
      if (Hzd_t1_1_L) call hzd_hoffld_ad (ut1,   LDIST_DIM, G_nk, 1)
      endif
*
      pnerr = vmmuld(-1,0)
*
*     ---------------------------------------------------------------
*
*
 1000 format(
     +3X,'ADJ of TRANSFER WINDS T1 ==> TH : (S/R WDPERS_AD)')
*
      return
      end