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

      subroutine hzd_hoffld_ad (F, DIST_DIM, Nk, grid)  12,6
*
      implicit none
*
      integer DIST_DIM, Nk, grid 
*
      real F(DIST_SHAPE,Nk)
*
*author
*    M.Tanguay
*
*revision
* v3_20 - Tanguay M.        - initial version
*
*object
*     see id section
*
*arguments
*  Name        I/O              Description
*----------------------------------------------------------------
*  F           I/0             field to diffuse
*  grid        I               type of grid
*----------------------------------------------------------------
*
*implicits
#include "fft.cdk"
#include "glb_ld.cdk"
#include "trp.cdk"
#include "hzd.cdk"
#include "opr.cdk"
#include "geomg.cdk"
#include "lun.cdk"
#include "ptopo.cdk"
*
      integer i, j, k, dpwr
      real*8 wk1_8
*
      real*8, parameter :: ZERO_8 = 0.0
*     __________________________________________________________________
*
      dpwr = Hzd_pwr / 2
      if (Lun_debug_L) write(Lun_out,1000) Hzd_pwr, grid 
*
*     Zero adjoint variables
*     ----------------------
      wk1_8 = ZERO_8
*
*     ------------
*     ADJ of
*     2D diffusion
*     ------------
      if ( .not.Hzd_1d_L ) then
*
         if ( Hzd_cdiff .gt. 0.0 ) then
*
            if ( grid.eq.1 ) then
            call hzd_solfft_ad (F, wk1_8, Fft_pri_8,
     %                      Hzd_au_8,Hzd_cu_8,Hzd_deltau_8,
     %                      trp_12dmin,trp_12dmax,trp_22min,trp_22max,
     %                      trp_12dn,trp_22n,G_nj, dpwr,l_minx,
     %                      l_maxx,l_miny,l_maxy,Nk,G_ni,l_ni,l_nj,
     %                      trp_12dn,Hzd_xp0_8,Opr_opsyp0_8, Hzd_cdiff,
     %                      Ptopo_npex,Ptopo_npey)
*
            elseif ( grid.eq.2 ) then
            call hzd_solfft_ad (F, wk1_8, Fft_pri_8 ,
     %                      Hzd_av_8,Hzd_cv_8,Hzd_deltav_8,
     %                      trp_12dmin,trp_12dmax,trp_22min,trp_22max,
     %                      trp_12dn,trp_22n,G_nj, dpwr,l_minx,
     %                      l_maxx,l_miny,l_maxy,Nk,G_ni,l_ni,l_nj,
     %                      trp_12dn,Opr_opsxp0_8,Hzd_yp0_8, Hzd_cdiff,
     %                      Ptopo_npex,Ptopo_npey)
*
            elseif ( grid.eq.3 ) then
            call hzd_solfft_ad (F, wk1_8, Fft_pri_8 ,
     %                      Hzd_as_8,Hzd_cs_8,Hzd_deltas_8,
     %                      trp_12dmin,trp_12dmax,trp_22min,trp_22max,
     %                      trp_12dn,trp_22n,G_nj, dpwr,l_minx,
     %                      l_maxx, l_miny, l_maxy,Nk,G_ni,l_ni,l_nj,
     %                      trp_12dn,Opr_opsxp0_8,Opr_opsyp0_8, Hzd_cdiff,
     %                      Ptopo_npex,Ptopo_npey)
*
            endif
*
         endif
*
*     ------------
*     ADJ of
*     1D diffusion
*     ------------
      else
*
         if ( Hzd_cdiff .gt. 0.0 ) then
*
            if ( grid.eq.1 ) then
            call hzd_solfft_1d_ad (F, wk1_8, Fft_pri_8,
     %                      Hz1d_deltau_8,
     %                      trp_12dmin,trp_12dmax,trp_22min,trp_22max,
     %                      trp_12dn,trp_22n,G_nj, dpwr,l_minx,
     %                      l_maxx,l_miny,l_maxy,Nk,G_ni,l_ni,l_nj,
     %                      trp_12dn,Hzd_xp0_8,Opr_opsyp0_8, Hzd_cdiff,
     %                      Ptopo_npex,Ptopo_npey)
*
            elseif ( grid.eq.2 ) then
            call hzd_solfft_1d_ad (F, wk1_8, Fft_pri_8 ,
     %                      Hz1d_deltav_8,
     %                      trp_12dmin,trp_12dmax,trp_22min,trp_22max,
     %                      trp_12dn,trp_22n,G_nj, dpwr,l_minx,
     %                      l_maxx,l_miny,l_maxy,Nk,G_ni,l_ni,l_nj,
     %                      trp_12dn,Opr_opsxp0_8,Hzd_yp0_8, Hzd_cdiff,
     %                      Ptopo_npex,Ptopo_npey)
*
            elseif ( grid.eq.3 ) then
            call hzd_solfft_1d_ad (F, wk1_8, Fft_pri_8 ,
     %                      Hz1d_deltas_8,
     %                      trp_12dmin,trp_12dmax,trp_22min,trp_22max,
     %                      trp_12dn,trp_22n,G_nj, dpwr,l_minx,
     %                      l_maxx, l_miny, l_maxy,Nk,G_ni,l_ni,l_nj,
     %                      trp_12dn,Opr_opsxp0_8,Opr_opsyp0_8, Hzd_cdiff,
     %                      Ptopo_npex,Ptopo_npey)
            endif
*
         endif
*
      endif
*
 1000 format(/,
     $  3X,'ADJ of PERFORM DEL-',i1,' FFT HORIZONTAL DIFFUSION: (S/R HZD_HOFFLD_AD) grid=',i2)
*     __________________________________________________________________
*
      return
      end