!********************************************************************
!*                   PROGRAM MAIN
!********************************************************************
!*
!* Objet      : test les fft R/C 2D de la librairie ESSL, IBM
!*
!*
!* Methode    :
!* 
!* Langage    : Fortran90
!*   
!* Auteur     : $Author$  
!*               
!*
!* $Date$
!*
!********************************************************************
!*
!* $Source$
!*
!* $Log$
!*
!********************************************************************
!*
!* APPELES    :
!*
!********************************************************************
!*
!*
!* ENTREES    :
!*
!* ENTREES/SORTIES :
!*
!* SORTIES    :
!*
!* CODE ERREUR :
!*
!*
!********************************************************************

      PROGRAM RCMAIN2D
!*
      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     ::  erreur
      REAL     ::  PI2n, PI2m
!*
!*
      INTERFACE
!*
      INCLUDE 'i_rcfft2d.h'
!*
      END INTERFACE
!*
!********************************************************************
!*
!* DEBUT DU PROGRAMME
!*
!********************************************************************
!*
!* Lecture des dimensions
      OPEN (19, file = 'FFT2D.DAT', STATUS = 'OLD', FORM = 'FORMATTED')
      READ (19, *) n
      READ (19, *) m
      CLOSE (19)
!*
      ALLOCATE ( UR(0:n+1, 0:m-1), UC(0:n/2, 0:m-1),VR (0:n, 0:m-1), &
                 STAT = ierr)
      IF (ierr /= 0) THEN
         WRITE (6,'(A)') ' Probleme allocation UR, UC, VR'
         STOP
      END IF
!*
!*
      PI2n = 2.0_rp * ACOS( -un ) / REAL (n, rp)
      PI2m = 2.0_rp * ACOS( -un ) / REAL (m, rp)
!*
!*
!* Initialisation et sauvegarde du signal
      DO j = 0, m - 1
         DO i = 0, n - 1
!           UR(i,j) = SIN( PI2n * REAL(i,rp) ) * COS( PI2m * REAL(j,rp) )
            UR(i,j) = COS( PI2n * REAL(i,rp) )
            VR(i,j) = UR(i,j)
         END DO
         UR(n,j) = zero
         VR(n,j) = zero
      END DO
!*
!* Initialisation des trigs
      CALL rcfft2d(  0, n, m, UR, UC )
!*
!* FFT directe
      CALL rcfft2d( -1, n, m, UR, UC )
!*
!*
!* Affichage
      DO j = 0, m - 1
         DO i = 0, n - 1
            WRITE (6, 1010) j, i, VR(i,j)
            UR(i,j) = zero
         END DO
         WRITE (6,*) ' '
      END DO
!
      DO j = 0, m - 1
         DO i = 0, n / 2
            WRITE (6, 1010) j, i, UC(i,j)
            UR(i,j) = zero
         END DO
         WRITE (6,*) ' '
      END DO
 1010 FORMAT ( 2i4, 2E12.4 )
!*
!*
!* FFT inverse
      CALL rcfft2d(  1, n, m, UR, UC )
!*
!* Comparaison
      erreur = zero
      DO j = 0, m - 1
         DO i = 0, n - 1
            erreur = MAX( erreur, ABS( UR(i,j) - VR(i,j) ) )
            write (6,1030) j, i, UR(i,j), VR(i,j), ABS( UR(i,j) - VR(i,j) )
 1030 FORMAT ( 2i5, 3E13.4 )
         END DO
      END DO
!*
 1020 FORMAT( A, E11.4 )
      WRITE (6, 1020) 'Erreur Loo = ', erreur
!*
!*
      CALL rcfft2d( -2, n, m, UR, UC )
      DEALLOCATE( UR, UC, VR )
!*
!*
      STOP
      END PROGRAM RCMAIN2D
