Index: LMDZ4/trunk/libf/filtrez/mod_fft_fftw.F90
===================================================================
--- LMDZ4/trunk/libf/filtrez/mod_fft_fftw.F90	(revision 986)
+++ LMDZ4/trunk/libf/filtrez/mod_fft_fftw.F90	(revision 1403)
@@ -1,39 +1,84 @@
+!
+! $Id$
+!
+
 MODULE mod_fft_fftw
 
 #ifdef FFT_FFTW
 
-  REAL,SAVE,ALLOCATABLE    :: Table_forward(:)
-  REAL,SAVE,ALLOCATABLE    :: Table_backward(:)
-  REAL,SAVE                :: scale_factor
-  INTEGER,SAVE             :: vsize
-  INTEGER,PARAMETER        :: inc=1
+  REAL, SAVE                   :: scale_factor
+  INTEGER, SAVE                :: vsize
+  INTEGER, PARAMETER           :: inc=1
   
-  INTEGER,SAVE             :: plan_forward
-  INTEGER,SAVE             :: plan_backward
+  INTEGER*8, ALLOCATABLE, DIMENSION(:), SAVE :: plan_forward
+  INTEGER*8, ALLOCATABLE, DIMENSION(:), SAVE :: plan_backward
   
 CONTAINS
   
-  SUBROUTINE Init_fft(iim)
+  SUBROUTINE Init_fft(iim,nvectmax)
   IMPLICIT NONE
-#include <rfftw.h>
+#include <fftw3.f>
     INTEGER :: iim
-    REAL    :: rtmp=1.
-    COMPLEX*16 :: ctmp
-    INTEGER :: itmp=1
-    INTEGER :: isign=0
-    INTEGER :: ierr
+    INTEGER :: nvectmax
+
+    INTEGER :: itmp
+
+    INTEGER               :: rank
+    INTEGER               :: howmany
+    INTEGER               :: istride, idist
+    INTEGER               :: ostride, odist
+    INTEGER, DIMENSION(1) :: n_array, inembed, onembed
+
+    REAL,    DIMENSION(iim+1,nvectmax) :: dbidon
+    COMPLEX, DIMENSION(iim/2+1,nvectmax) :: cbidon
+
+    vsize = iim
+    scale_factor = 1./SQRT(1.*vsize)
+
+    dbidon = 0
+    cbidon = 0
+
+    ALLOCATE(plan_forward(nvectmax))
+    ALLOCATE(plan_backward(nvectmax))
     
-    vsize=iim
-    scale_factor=1./SQRT(1.*vsize)
-    ALLOCATE(Table_forward(2*vsize+64))
-    ALLOCATE(Table_backward(2*vsize+64))
+    WRITE(*,*)"!---------------------!"
+    WRITE(*,*)"!                     !"
+    WRITE(*,*)"! INITIALISATION FFTW !"
+    WRITE(*,*)"!                     !"
+    WRITE(*,*)"!---------------------!"
     
-!    CALL DZFFTM(isign,vsize,itmp,scale_factor,rtmp,vsize+inc,ctmp,vsize/2+1,table_forward,rtmp,ierr)
-    
-!    CALL ZDFFTM(isign,vsize,itmp,scale_factor,ctmp,vsize/2+1,rtmp,vsize+inc,table_backward,rtmp,ierr)
+! On initialise tous les plans 
+    DO itmp = 1, nvectmax
+       rank       = 1
+       n_array(1) = iim
+       howmany    = itmp
+       inembed(1) = iim + 1 ; onembed(1) = iim/2 + 1
+       istride    = 1       ; ostride    = 1
+       idist      = iim + 1 ; odist      = iim/2 + 1
 
-    CALL rfftw_f77_create_plan(plan_forward,iim,FFTW_REAL_TO_COMPLEX,FFTW_ESTIMATE)
-    CALL rfftw_f77_create_plan(plan_backward,iim,FFTW_COMPLEX_TO_REAL,FFTW_ESTIMATE)
-    
+       CALL dfftw_plan_many_dft_r2c(plan_forward(itmp), rank, n_array, howmany, &
+            & dbidon, inembed, istride, idist, &
+            & cbidon, onembed, ostride, odist, &
+            & FFTW_ESTIMATE)
+
+       rank       = 1
+       n_array(1) = iim
+       howmany    = itmp
+       inembed(1) = iim/2 + 1 ; onembed(1) = iim + 1
+       istride    = 1         ; ostride    = 1
+       idist      = iim/2 + 1 ; odist      = iim + 1
+       CALL dfftw_plan_many_dft_c2r(plan_backward(itmp), rank, n_array, howmany, &
+            & cbidon, inembed, istride, idist, &
+            & dbidon, onembed, ostride, odist, &
+            & FFTW_ESTIMATE)
+
+    ENDDO
+
+    WRITE(*,*)"!-------------------------!"
+    WRITE(*,*)"!                         !"
+    WRITE(*,*)"! FIN INITIALISATION FFTW !"
+    WRITE(*,*)"!                         !"
+    WRITE(*,*)"!-------------------------!"
+
   END SUBROUTINE Init_fft
   
@@ -41,29 +86,25 @@
   SUBROUTINE fft_forward(vect,TF_vect,nb_vect)
     IMPLICIT NONE
-#include <rfftw.h>
-    INTEGER,INTENT(IN)  :: nb_vect
-    REAL,INTENT(IN)     :: vect(vsize+inc,nb_vect)
-    COMPLEX*16,INTENT(OUT) :: TF_vect(vsize/2+1,nb_vect)
-    REAL                :: work(4*vsize*nb_vect)
-    INTEGER             :: ierr
-    INTEGER, PARAMETER :: isign=-1
-  
-!    CALL DZFFTM(isign,vsize,nb_vect,scale_factor,vect,vsize+inc,TF_vect,vsize/2+1,table_forward,work,ierr)
-     CALL rfftwnd_f77_real_to_complex(plan_forward,nb_vect,vect, 1, vsize+inc , TF_vect, 1, vsize/2+1);  
-    
+#include <fftw3.f>
+    INTEGER,INTENT(IN)     :: nb_vect
+    REAL,INTENT(IN)        :: vect(vsize+inc,nb_vect)
+    COMPLEX,INTENT(OUT) :: TF_vect(vsize/2+1,nb_vect)
+
+    CALL dfftw_execute_dft_r2c(plan_forward(nb_vect),vect,TF_vect)
+
+    TF_vect = scale_factor * TF_vect
+
   END SUBROUTINE fft_forward
   
   SUBROUTINE fft_backward(TF_vect,vect,nb_vect)
     IMPLICIT NONE
-#include <rfftw.h>
-    INTEGER,INTENT(IN)  :: nb_vect
-    REAL,INTENT(OUT)    :: vect(vsize+inc,nb_vect)
-    COMPLEX*16,INTENT(IN ) :: TF_vect(vsize/2+1,nb_vect)
-    REAL                :: work(4*vsize*nb_vect)
-    INTEGER             :: ierr
-    INTEGER, PARAMETER :: isign=1
-  
-!    CALL ZDFFTM(isign,vsize,nb_vect,scale_factor,TF_vect,vsize/2+1,vect,vsize+inc,table_backward,work,ierr)
-    CALL rfftwnd_f77_complex_to_real(plan_forward,nb_vect,TF_vect, 1, vsize/2+1 , vect, 1, vsize+inc);  
+#include <fftw3.f>
+    INTEGER,INTENT(IN)     :: nb_vect
+    REAL,INTENT(OUT)       :: vect(vsize+inc,nb_vect)
+    COMPLEX,INTENT(IN ) :: TF_vect(vsize/2+1,nb_vect)
+
+    CALL dfftw_execute_dft_c2r(plan_backward(nb_vect),TF_vect,vect)
+
+    vect = scale_factor * vect
 
   END SUBROUTINE fft_backward
@@ -72,3 +113,2 @@
   
 END MODULE mod_fft_fftw
-
