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