!-------------------------------------- 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 --------------------------------------
!

      SUBROUTINE FFT3DVAR(PGD,KIBEG,KIEND,KDIM,KJBEG,KJEND,KFIELD,KDIR) 9
#if defined (DOC)
*
C**s/r FFT3DAVR  - fast fourier transforms
*                  parallel code for 3rd dimension (usually latitude)
*
*Author  : P.Koclas  - CMC  November 1997
*
*Revision:
*           JM Belanger CMDA/SMC  Aug 2000 
*                   . 32 bits conversion 
*                     (replace call to REAL interface FFT771 
*                      by call to REAL*8 FFFT8 )
*
*           P. Koclas CMC Apr 2003
*             -removed commulti and added openmp for ibm conversion
*           L. Fillion ARMA/EC - 16 Aug 2010 - Introduce Hemispheric Transform.
*
*Arguments
*     i-o PGD               : Field to apply the fft
*     i   KIBEG, KIEND      : first Dimensions of PGD
*     i   KDIM              : second Dimensions of PGD
*     i   KJBEG, KJEND      : 3rd Dimensions of PGD (usually latitude)
*     i   KFIELD            : Number of fields to do fft 
*     i   KDIR              : Number of fields to do fft 
*
#endif
      IMPLICIT NONE
*implicits
#include "comdim.cdk"
#include "commulti.cdk"
#include "comcva.cdk"
C
      INTEGER KIBEG, KIEND, KJBEG, KJEND, KDIM,KFIELD,KDIR
      REAL*8 PGD(KIBEG:KIEND,KDIM,KJBEG:KJEND)
C
      INTEGER  ILATBD,IJUMP,INFFT
      INTEGER  JLAT,inj
!
!!
      inj = nj
      if(lcva_hsp) inj = njlath
C
C     1. Inverse fourier transform
C     .  -------------------------
      IJUMP = KIEND - KIBEG + 1
      NFFTSTRID=16

!$OMP PARALLEL PRIVATE (ILATBD,INFFT)
!$OMP DO PRIVATE (JLAT)
      DO  JLAT = 1, inj, NFFTSTRID
         ILATBD = MIN(NFFTSTRID,inj - JLAT + 1)
         INFFT = KFIELD*ILATBD
         CALL FFFT8(PGD(1,1,JLAT),1,IJUMP,INFFT,KDIR)

*     subroutine ffft8( a, inc, jump, lot, isign )
*     a      is the array containing input & output data
*     fwork  is no longer used.
*     ftrigs is no longer used, -> trigs in 'comfft8'
*     fifax  is no longer used, -> ifax in 'comfft8'
*     inc    is the increment within each data 'vector'
*            (e.g. inc=1 for consecutively stored data)
*     jump   is the increment between the start of each data vector
*     fn     is no longer used, -> n in 'comfft8'
*     lot    is the number of data vectors
*     isign  = +1 for transform from spectral to gridpoint
*            = -1 for transform from gridpoint to spectral

      END DO
!$OMP END DO
!$OMP END PARALLEL
C
      RETURN
      END