!********************************************************************
!*                   SUBROUTINE RCFFT1D
!********************************************************************
!*
!* Objet      : routine d'interface pour les fft R/C 1D de la lib IBM
!*
!*
!* Methode    :
!*
!* Langage    : Fortran90
!*
!* Auteur     : Guy Moebs
!*
!*
!* $Date$
!*
!********************************************************************
!*
!* $Source$
!*
!* $Log$
!*
!********************************************************************
!*
!* APPELES    :
!*
!********************************************************************
!*
!*
!* ENTREES         :  itrans, ndim, mtimes
!*
!* ENTREES/SORTIES :  R, C
!*
!* SORTIES         :
!*
!* CODE ERREUR     :
!*
!*
!********************************************************************
!*
      SUBROUTINE rcfft1d (itrans, ndim, mtimes, X, Y)
!      
!--------------------
! 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 transformantion
!     * mtimes (E ,I ) Nombre de transformations
!     * X      (ES,R ) Tableau des valeurs reelles
!     * Y      (ES,CX) Tableau des valeurs complexes
!
!--------------------------
! declaration des arguments
!--------------------------
      INTEGER,  INTENT(IN)  ::  itrans
      INTEGER,  INTENT(IN)  ::  ndim
      INTEGER,  INTENT(IN)  ::  mtimes
!
      REAL(rp),     DIMENSION(0:ndim,   1:mtimes),  INTENT(INOUT)  ::  X
      COMPLEX(rp),  DIMENSION(0:ndim/2, 1:mtimes),  INTENT(INOUT)  ::  Y
!
!----------------------------------
! declaration des variables locales
!----------------------------------
      REAL(rp)  ::  scale
      REAL(rp)  ::  dummy = 0.0_rp
!
      INTEGER   ::  n, m, init, isign
      INTEGER   ::  inc2x, inc2y
      INTEGER   ::  ndummy = 1
!
!-----------------------
! debut de la subroutine
!-----------------------
!
      SELECT CASE (itrans)
!
!----------------------------------------------------
! Passage de l'espace spectral dans l'espace physique
!----------------------------------------------------
!
      CASE (-1)
           n = ndim
           m = mtimes
!
           init = 0
!
           inc2x = ndim+1
!
           inc2y = ndim/2+1
!
           isign = -1
           scale = 1.0_rp / REAL(n, rp)
!
           CALL DRCFT ( init, X, inc2x, Y, inc2y, n, m, isign, &
                        scale, AUX1m, naux1, AUX2, naux2, dummy, ndummy )
!
!----------------------------------------------------
! Passage de l'espace physique dans l'espace spectral
!----------------------------------------------------
!
      CASE (1)
           n = ndim
           m = mtimes
!
           init = 0
!
           inc2x = ndim+1
!
           inc2y = ndim/2+1
!
           isign = 1
           scale = 1.0_rp
!
           CALL DRCFT ( init, X, inc2x, Y, inc2y, n, m, isign, &
                        scale, AUX1p, naux1, AUX2, naux2, dummy, ndummy )
!
!--------------------------
! Initialisations des TRIGS
!--------------------------
!
      CASE (0)
           n = ndim
           m = mtimes
!
           init = 1
!
           inc2x = ndim+1
!
           inc2y = ndim/2+1
!
           IF ( n <= 4096 ) THEN
              naux1 = 22000
              naux2 = 20000
           ELSE
              naux1 = 20000 + INT( 1.64_rp * n ) + 1
              naux2 = 20000 + INT( 1.14_rp * n ) + 1
           END IF
!
           ALLOCATE( AUX1p(naux1), AUX1m(naux1), AUX2(naux2), STAT = ierr)
           IF( ierr /= 0 ) THEN
              WRITE (6,*) ' Probleme allocation AUX1p, AUX1m, AUX2'
              STOP
           END IF
!
           isign = 1
           scale = 1.0_rp
           CALL DRCFT ( init, X, inc2x, Y, inc2y, n, m, isign, &
                        scale, AUX1p, naux1, AUX2, naux2, dummy, ndummy )
!
           isign = -1
           scale = 1.0_rp / REAL(n, rp)
           CALL DRCFT ( init, X, inc2x, Y, inc2y, n, m, isign, &
                        scale, AUX1m, naux1, AUX2, naux2, dummy, ndummy )
!
!-----------------------
! Finalisation des TRIGS
!-----------------------
!
      CASE (-2)
           DEALLOCATE( AUX1p, AUX1m, AUX2 )
!
!-------
! Erreur
!-------
!
      CASE DEFAULT
           WRITE (6,'(A)') 'ERREUR : PARAMETRE itrans INCONNU'
           STOP
!
      END SELECT
!
!---------------------
! Fin de la subroutine
!---------------------
!
      RETURN
      END SUBROUTINE rcfft1d
