!********************************************************************
!*                   SUBROUTINE SCFFT2D
!********************************************************************
!*
!* Objet      : routine d'interface pour les fft S/C 2D de la lib SGI
!*
!*
!* Methode    :
!*
!* Langage    : Fortran90
!*
!* Auteur     : Guy Moebs
!*
!*
!* $Date$
!*
!********************************************************************
!*
!* $Source$
!*
!* $Log$
!*
!********************************************************************
!*
!* APPELES    :
!*
!********************************************************************
!*
!*
!* ENTREES         :  itrans, ndim, mdim
!*
!* ENTREES/SORTIES :  R, C
!*
!* SORTIES         :
!*
!* CODE ERREUR     :
!*
!*
!********************************************************************
!*
      SUBROUTINE scfft2d (itrans, ndim, mdim, R, C)
!      
!--------------------
! modules necessaires
!--------------------
      use numerics
      use modfft
!
      IMPLICIT NONE
!
!--------------------------
! description des arguments
!--------------------------
!     * itrans (E ,I ) Entier definissant la transformation
!     * ndim   (E ,I ) Nombre de points de la transformantion
!     * mdim   (E ,I ) Nombre de points de la transformantion
!     * R      (ES,R ) Tableau des valeurs reelles
!     * C      (ES,CX) Tableau des valeurs complexes
!
!--------------------------
! declaration des arguments
!--------------------------
      INTEGER,  INTENT(IN)  ::  itrans
      INTEGER,  INTENT(IN)  ::  ndim
      INTEGER,  INTENT(IN)  ::  mdim
!
      REAL(rp),     DIMENSION(0:ndim,   0:mdim-1),  INTENT(INOUT)  ::  R
      COMPLEX(rp),  DIMENSION(0:ndim/2, 0:mdim-1),  INTENT(INOUT)  ::  C
!
!----------------------------------
! declaration des variables locales
!----------------------------------
      REAL(rp)  ::  usnm
!
!-----------------------
! debut de la subroutine
!-----------------------
!
      SELECT CASE (itrans)
!
!----------------------------------------------------
! Passage de l'espace physique dans l'espace spectral
!----------------------------------------------------
!
      CASE ( 1)
!          usnm = un / ( REAL(ndim, rp) * REAL(mdim, rp) )
           CALL DZFFT2D (  1, ndim, mdim, un,   R, ndim+1, C, ndim/2+1, CTRIGS, CWK, 0)
!
!----------------------------------------------------
! Passage de l'espace spectral dans l'espace physique
!----------------------------------------------------
!
      CASE (-1)
           usnm = un / ( REAL(ndim, rp) * REAL(mdim, rp) )
           CALL ZDFFT2D ( -1, ndim, mdim, usnm, C, ndim/2+1, R, ndim+1, CTRIGS, CWK, 0)
!
!--------------------------
! Initialisations des TRIGS
!--------------------------
!
      CASE (0)
           ALLOCATE( CTRIGS(ndim+2*mdim+45), &
                     CWK(ndim+4*mdim),       &
                     STAT = ierr)
           IF( ierr /= 0 ) THEN
              WRITE (6,'(A)') ' Probleme allocation CTRIGS, CWK'
              STOP
           END IF
!
           CALL DZFFT2D (  0, ndim, mdim, un,   R, ndim+1, C, ndim/2+1, CTRIGS, CWK, 0)
!
!-----------------------
! Finalisation des TRIGS
!-----------------------
!
      CASE (-2)
           DEALLOCATE( CTRIGS, CWK )
!
!-------
! Erreur
!-------
!
      CASE DEFAULT
           WRITE (6,'(A)') 'ERREUR : PARAMETRE itrans INCONNU'
           STOP
!
      END SELECT
!
!---------------------
! Fin de la subroutine
!---------------------
!
      RETURN
      END SUBROUTINE scfft2d
