!********************************************************************
!*                   PROGRAM RCMAIN1D
!********************************************************************
!*
!* Objet      : test les fft R/C 1D de la librairie ESSL, IBM
!*
!*
!* Methode    :
!* 
!* Langage    : Fortran90
!*   
!* Auteur     : $Author$  
!*               
!*
!* $Date$
!*
!********************************************************************
!*
!* $Source$
!*
!* $Log$
!*
!********************************************************************
!*
!* APPELES    :
!*
!********************************************************************
!*
!*
!* ENTREES    :
!*
!* ENTREES/SORTIES :
!*
!* SORTIES    :
!*
!* CODE ERREUR :
!*
!*
!********************************************************************
!*
      PROGRAM RCMAIN1D
!*
      USE numerics
!*
      IMPLICIT NONE
!*
      REAL(rp),     DIMENSION(:,:),  ALLOCATABLE  ::  UR
      COMPLEX(rp),  DIMENSION(:,:),  ALLOCATABLE  ::  UC
!*
      REAL(rp),     DIMENSION(:,:),  ALLOCATABLE  ::  VR
!*
!*
      INTEGER  ::  i, j
      INTEGER  ::  n, m
!*
!*
      REAL(rp)  ::  erreur
      REAL(rp)  ::  PI2n
!*
!*
      INTERFACE
!*
      INCLUDE 'i_rcfft1d.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)
!*
      ALLOCATE ( UR(0:n, 1:m), UC(0:n/2, 1:m), VR(0:n, 1:m), STAT = ierr)
      IF (ierr /= 0) THEN
         WRITE (6,'(A)') ' Probleme allocation UR, UC, VR'
         STOP
      END IF
!*
!* Initialisation des TRIGS
      CALL rcfft1d(  0, n, m, UR, UC )
!*
!* Initialisation et sauvegarde du signal
      PI2n = 2.0_rp * ACOS (-un) / REAL (n,rp)
!*
      WRITE (6,'(A)') 'SIGNAL EN ENTREE'
      DO j = 1, m
         DO i = 0, n - 1
            UR(i,j) = REAL(j, rp) * SIN( PI2n * REAL(i,rp) )
            VR(i,j) = UR(i,j)
            WRITE (6,1010) j, i, UR(i, j)
         END DO
         UR(n,j) = zero
         VR(n,j) = zero
      END DO
!*
!* FFT directe
      CALL rcfft1d(  1, n, m, UR, UC )
!*
!* Affichage
      WRITE (6,'(A)') 'SIGNAL TRANSFORME'
      DO j = 1, m
         DO i = 0, n/2
            WRITE (6, 1010) j, i, VR(i,j), j, i, UC(i,j)
         END DO
      END DO
 1010 FORMAT ( (2i5, E12.4), (2i5, 2(E12.4) ) )
 1030 FORMAT ( (2i5, E12.4), (2i5, 2(E12.4) ), E12.4 )
!*
!* FFT inverse
      CALL rcfft1d( -1, n, m, UR, UC )
!*
!* Comparaison
      WRITE (6,'(A)') 'SIGNAL EN SORTIE'
      erreur = zero
      DO j = 1, m
         DO i = 0, n - 1
            erreur = MAX( erreur, ABS( UR(i,j) - VR(i,j) ) )
            WRITE (6,1030) j, i, UR(i,j), j, i, VR(i,j), ABS( UR(i,j) - VR(i,j) )
         END DO
      END DO
!*
 1020 FORMAT( A, E11.4 )
      WRITE (6,1020) 'Erreur Loo = ', erreur
!*
!*
      CALL rcfft1d( -2, n, m, UR, UC )
!
      DEALLOCATE( UR, UC, VR )
!*
!*
      STOP
      END PROGRAM RCMAIN1D
