!********************************************************************
!*                   SUBROUTINE CCFFT1D
!********************************************************************
!*
!* Objet      : routine d'interface pour les fft C/C 1D de la lib IBM
!*
!*
!* Methode    :
!*
!* Langage    : Fortran90
!*
!* Auteur     : Guy Moebs
!*
!*
!* $Date$
!*
!********************************************************************
!*
!* $Source$
!*
!* $Log$
!*
!********************************************************************
!*
!* APPELES    :
!*
!********************************************************************
!*
!*
!* ENTREES         :  itrans, ndim, mtimes
!*
!* ENTREES/SORTIES :  X
!*
!* SORTIES         :  
!*
!* CODE ERREUR     :
!*
!*
!********************************************************************
!*
      SUBROUTINE ccfft1d (itrans, ndim, mtimes, X)
!
!--------------------
! modules necessaires
!--------------------
      use numerics
      use modfft
!
      IMPLICIT NONE
!
!--------------------------
! description des arguments
!--------------------------
!     * itrans (E ,I ) Entier definissant la transformation
!     * ndim   (E ,I ) Nombre de points de la transformation
!     * mtimes (E ,I ) Nombre de transformations
!     * X      (ES,CX) Tableau de la transformee en entree / sortie
!
!--------------------------
! declaration des arguments
!--------------------------
      INTEGER,  INTENT(IN)  ::  itrans
      INTEGER,  INTENT(IN)  ::  ndim
      INTEGER,  INTENT(IN)  ::  mtimes
!
      COMPLEX(rp),  DIMENSION(0:ndim,1:mtimes),  INTENT(INOUT)  ::  X
!
!----------------------------------
! declaration des variables locales
!----------------------------------
      REAL(rp)  ::  usn
!
      REAL(rp)  ::  scale
!
      INTEGER   ::  n, m, init, isign
      INTEGER   ::  inc1x, inc2x, inc1y, inc2y
! 
!-----------------------
! debut de la subroutine
!-----------------------
!
      SELECT CASE (itrans)
!
!----------------------------------------------------
! Passage de l'espace physique dans l'espace spectral
!----------------------------------------------------
!
      CASE (-1)
           n = ndim
           m = mtimes
!
           init = 0
!
           inc1x = 1
           inc2x = ndim+1
!
           inc1y = inc1x
           inc2y = inc2x
!
           isign = -1
           scale = 1.0_rp / REAL(n, rp)
!
           CALL DCFT ( init, X, inc1x, inc2x, X, inc1y, inc2y, n, m, &
                       isign, scale, AUX1m, naux1, AUX2, naux2 )
!
!----------------------------------------------------
! Passage de l'espace spectral dans l'espace physique
!----------------------------------------------------
!
      CASE (1)
           n = ndim
           m = mtimes
!
           init = 0
!
           inc1x = 1
           inc2x = ndim+1
!
           inc1y = inc1x
           inc2y = inc2x
!
           isign = 1
           scale = 1.0_rp
!
           CALL DCFT ( init, X, inc1x, inc2x, X, inc1y, inc2y, n, m, &
                       isign, scale, AUX1p, naux1, AUX2, naux2 )
!
!--------------------------
! Initialisations des TRIGS
!--------------------------
!
      CASE (0)
!
           n = ndim
           m = mtimes
!
           init = 1
!
           inc1x = 1
           inc2x = ndim+1
!
           inc1y = inc1x
           inc2y = inc2x
!
           IF ( n <= 2048 ) THEN
              naux1 = 20000
              naux2 = 20000
           ELSE
              naux1 = 20000 + INT( 2.28_rp * n ) + 1
              naux2 = 20000 + INT( 2.28_rp * n ) + 1
           END IF
!
           IF ( (n >= 252) .AND. ( (inc2x == 1) .OR. (inc2y == 1) ) ) THEN
              naux1 = naux1 + (2*n + 256) * MIN (64, m)
              naux2 = naux2 + (2*n + 256) * MIN (64, m)
           END IF

           ALLOCATE( AUX1p(naux1), AUX1m(naux1), AUX2(naux2), STAT = ierr)
           IF( ierr /= 0 ) THEN
              WRITE (6,*) ' Probleme allocation AUX1i, AUXd, AUX2'
              STOP
           END IF
!
           isign = 1
           scale = 1.0_rp
           CALL DCFT ( init, X, inc1x, inc2x, X, inc1y, inc2y, n, m, &
                       isign, scale, AUX1p, naux1, AUX2, naux2 )
!
           isign = -1
           scale = 1.0_rp / REAL(n, rp)
           CALL DCFT ( init, X, inc1x, inc2x, X, inc1y, inc2y, n, m, &
                       isign, scale, AUX1m, naux1, AUX2, naux2 )
!
!-----------------------
! Finalisation des TRIGS
!-----------------------
!
      CASE (-2)
           DEALLOCATE( AUX1m, AUX1p, AUX2 )
!
!-------
! Erreur
!-------
!
      CASE DEFAULT
           WRITE (6,*) 'ERREUR : PARAMETRE itrans INCONNU'
           STOP
!
      END SELECT
!
!---------------------
! Fin de la subroutine
!---------------------
!
      RETURN
      END SUBROUTINE ccfft1d
