!********************************************************************
!*                   PROGRAM MAIN
!********************************************************************
!*
!* Objet      : test les fft C/C 1D de la librairie ESSL, IBM
!*
!*
!* Methode    :
!* 
!* Langage    : Fortran90
!*   
!* Auteur     : $Author$  
!*               
!*
!* $Date$
!*
!********************************************************************
!*
!* $Source$
!*
!* $Log$
!*
!********************************************************************
!*
!* APPELES    :
!*
!********************************************************************
!*
!*
!* ENTREES    :
!*
!* ENTREES/SORTIES :
!*
!* SORTIES    :
!*
!* CODE ERREUR :
!*
!*
!********************************************************************
!*
      PROGRAM MAIN
!*
      USE numerics
!*
      IMPLICIT NONE
!*
      COMPLEX(rp), DIMENSION(:,:), ALLOCATABLE  ::  U
      COMPLEX(rp), DIMENSION(:,:), ALLOCATABLE  ::  V
!*
      INTEGER   ::  i, n, j, m
!*
      REAL(rp)  ::  erreur
      REAL(rp)  ::  usn
      REAL(rp)  ::  PI2n
!*
!*
      INTERFACE
!*
      INCLUDE 'i_ccfft1d.h'
!*
      END INTERFACE
!*
!********************************************************************
!*
!* DEBUT DU PROGRAMME
!*
!********************************************************************
!*
!* Lecture de la dimension
      OPEN (19, file = 'FFT1D.DAT', STATUS = 'OLD', FORM = 'FORMATTED')
      READ (19, *) n, m
      CLOSE (19)
!*
      WRITE (6,*) 'Nombre de points par transformation : ', n
      WRITE (6,*) 'Nombre de transformations a effectuer : ', m
!*
      ALLOCATE( V(0:n,1:m), U(0:n,1:m), STAT = ierr)
      IF( ierr /= 0 ) THEN
         WRITE (6,*) ' Probleme allocation U, V'
         STOP
      END IF
!*
!* Initialisation des TRIGS
      CALL ccfft1d(  0, n, m, U )
!*
!* Initialisation et sauvegarde du signal
      usn = un / REAL( n, rp )
      PI2n = 2.0_rp * ACOS( -un ) * usn
!*
      DO j = 1, m
         DO i = 0, n - 1
            U(i,j) = REAL(j, rp) * COS( PI2n * REAL( i,rp ) )
            V(i,j) = U(i,j)
         END DO
         U(n,j) = zero
         V(n,j) = zero
      END DO
!*
!* FFT directe
      CALL ccfft1d( -1, n, m, U )
!*
!* Affichage
      DO i = 0, n/2 - 1
         WRITE (6, 1010) i, V(i,m), i,   U(i,m)
      END DO
      DO i = n/2, n - 1
         WRITE (6, 1010) i, V(i,m), i-n, U(i,m)
      END DO
 1010 FORMAT ( 2(i5, 2(E12.4) ) )
!*
!* FFT inverse
       CALL ccfft1d(  1, n, m, U )
!*
!* Comparaison
      erreur = zero
      DO j = 1, m
         DO i = 0, n - 1
            erreur = MAX( erreur, ABS( U(i,j) - V(i,j) ) )
         END DO
      END DO
!*
 1020 FORMAT( A, E11.4 )
      WRITE (6, 1020) 'Erreur Loo = ', erreur
!*
!*
      CALL ccfft1d( -2, n, m, U )
      DEALLOCATE( U, V )
!*
!*
      STOP
      END PROGRAM MAIN
