!********************************************************************
!*                   PROGRAM MAIN
!********************************************************************
!*
!* Objet      : test les fft C/C 1D de la lib SGI
!*
!*
!* Methode    :
!* 
!* Langage    : Fortran90
!*   
!* Auteur     : $Author$  
!*               
!*
!* $Date$
!*
!********************************************************************
!*
!* $Source$
!*
!* $Log$
!*
!********************************************************************
!*
!* APPELES    :
!*
!********************************************************************
!*
!*
!* ENTREES    :
!*
!* ENTREES/SORTIES :
!*
!* SORTIES    :
!*
!* CODE ERREUR :
!*
!*
!********************************************************************
!*
      PROGRAM MAIN
!*
      USE numerics
      USE modfft
!*
      IMPLICIT NONE
!*
      COMPLEX(rp), DIMENSION(:), ALLOCATABLE  ::  U
      COMPLEX(rp), DIMENSION(:), ALLOCATABLE  ::  V
!*
      INTEGER   ::  i, n
!*
      REAL(rp)  ::  erreur
      REAL(rp)  ::  usn
      REAL(rp)  ::  PI2n
!*
!*
      INTERFACE
!*
      SUBROUTINE ccfft1d (itrans, ndim, A, B)
      use numerics
      use modfft
      IMPLICIT NONE
      INTEGER,  INTENT(IN)  ::  itrans
      INTEGER,  INTENT(IN)  ::  ndim
      COMPLEX(rp),  DIMENSION(0:ndim-1),  INTENT(IN)   ::  A
      COMPLEX(rp),  DIMENSION(0:ndim-1),  INTENT(OUT)  ::  B
      END SUBROUTINE ccfft1d
!*
      END INTERFACE
!*
!********************************************************************
!*
!* DEBUT DU PROGRAMME
!*
!********************************************************************
!*
!* Lecture de la dimension
      OPEN (19, file = 'FFT1D.DAT', STATUS = 'OLD', FORM = 'FORMATTED')
      READ (19, *) n
      CLOSE (19)
!*
      ALLOCATE( V(0:n-1), U(0:n-1), STAT = ierr)
      IF( ierr /= 0 ) THEN
         WRITE (6,*) ' Probleme allocation U, V'
         STOP
      END IF
!*
!* Initialisation des TRIGS
      CALL ccfft1d(  0, n, U, U )
!*
!* Initialisation et sauvegarde du signal
      usn = un / REAL( n, rp )
      PI2n = 2.0_rp * ACOS( -un ) * usn
!*
      DO i = 0, n - 1
         U(i) = SIN( PI2n * REAL( i,rp ) )
         V(i) = U(i)
      END DO
!*
!* FFT directe
      CALL ccfft1d( -1, n, U, U )
!*
!* Affichage
      DO i = 0, n/2 - 1
         WRITE (6, 1010) i, V(i), i,   U(i)
      END DO
      DO i = n/2, n - 1
         WRITE (6, 1010) i, V(i), i-n, U(i)
      END DO
 1010 FORMAT ( 2(i3, 2(E12.4) ) )
!*
!* FFT inverse
       CALL ccfft1d(  1, n, U, U )
!*
!* Comparaison
      erreur = zero
      DO i = 0, n - 1
         erreur = MAX( erreur, ABS( U(i) - V(i) ) )
      END DO
!*
 1020 FORMAT( A, E11.4 )
      WRITE (6, 1020) 'Erreur Loo = ', erreur
!*
!*
      CALL ccfft1d( -2, n, U, U )
      DEALLOCATE( U, V )
!*
!*
      STOP
      END PROGRAM MAIN
