module fftwrot
!--------------------------------------------------
! FFTW
!

implicit none

!integer*8,pointer,private	   			:: planF3(:),planI3(:)
integer*8,private	   				:: planF1,planI1,planF2,planI2,planF3,planI3

contains

!-------------------------------------------------------------------------
subroutine fftw3d(tfld3)

complex						:: tfld3(:,:,:)

integer, parameter   				:: FFTW_R2HC=0,FTW_HC2R=1,FFTW_DHT=2,FFTW_REDFT00=3,FFTW_REDFT01=4
integer, parameter   				:: FFTW_REDFT10=5,FFTW_REDFT11=6,FFTW_RODFT00=7,FFTW_RODFT01=8,FFTW_RODFT10=9
integer, parameter   				:: FFTW_RODFT11=10,FFTW_FORWARD=-1,FFTW_BACKWARD=+1,FFTW_DESTROY_INPUT=1
integer, parameter   				:: FFTW_UNALIGNED=2,FFTW_CONSERVE_MEMORY=4,FFTW_EXHAUSTIVE=8,FTW_PRESERVE_INPUT=16
integer, parameter   				:: FFTW_PATIENT=32,FFTW_ESTIMATE=64,FFTW_ESTIMATE_PATIENT=128
integer, parameter   				:: FFTW_BELIEVE_PCOST=256,FFTW_DFT_R2HC_ICKY=512,FFTW_NONTHREADED_ICKY=1024
integer, parameter   				:: FFTW_NO_BUFFERING=2048,FFTW_NO_INDIRECT_OP=4096,FFTW_ALLOW_LARGE_GENERIC=8192
integer, parameter   				:: FFTW_NO_RANK_SPLITS=16384,FFTW_NO_VRANK_SPLITS=32768,FFTW_NO_VRECURSE=65536

   call sfftw_plan_dft_3D(planF3,3,(/size(tfld3,1),size(tfld3,2),size(tfld3,3)/),tfld3,tfld3,fftW_FORWARD,fftW_PATIENT)
   call sfftw_plan_dft_3D(planI3,3,(/size(tfld3,1),size(tfld3,2),size(tfld3,3)/),tfld3,tfld3,fftw_BACKWARD,fftW_PATIENT)

end subroutine
!-------------------------------------------------------------------------
subroutine fftw2d(tfld2)

complex						:: tfld2(:,:)

integer, parameter   				:: FFTW_R2HC=0,FTW_HC2R=1,FFTW_DHT=2,FFTW_REDFT00=3,FFTW_REDFT01=4
integer, parameter   				:: FFTW_REDFT10=5,FFTW_REDFT11=6,FFTW_RODFT00=7,FFTW_RODFT01=8,FFTW_RODFT10=9
integer, parameter   				:: FFTW_RODFT11=10,FFTW_FORWARD=-1,FFTW_BACKWARD=+1,FFTW_DESTROY_INPUT=1
integer, parameter   				:: FFTW_UNALIGNED=2,FFTW_CONSERVE_MEMORY=4,FFTW_EXHAUSTIVE=8,FTW_PRESERVE_INPUT=16
integer, parameter   				:: FFTW_PATIENT=32,FFTW_ESTIMATE=64,FFTW_ESTIMATE_PATIENT=128
integer, parameter   				:: FFTW_BELIEVE_PCOST=256,FFTW_DFT_R2HC_ICKY=512,FFTW_NONTHREADED_ICKY=1024
integer, parameter   				:: FFTW_NO_BUFFERING=2048,FFTW_NO_INDIRECT_OP=4096,FFTW_ALLOW_LARGE_GENERIC=8192
integer, parameter   				:: FFTW_NO_RANK_SPLITS=16384,FFTW_NO_VRANK_SPLITS=32768,FFTW_NO_VRECURSE=65536

   call sfftw_plan_dft(planF2,2,(/size(tfld2,1),size(tfld2,2)/),tfld2,tfld2,fftW_FORWARD,fftW_PATIENT)
   call sfftw_plan_dft(planI2,2,(/size(tfld2,1),size(tfld2,2)/),tfld2,tfld2,fftw_BACKWARD,fftW_PATIENT)

end subroutine

!-------------------------------------------------------------------------
subroutine fftw1d(tfld1)

complex						:: tfld1(:)

integer, parameter   				:: FFTW_R2HC=0,FTW_HC2R=1,FFTW_DHT=2,FFTW_REDFT00=3,FFTW_REDFT01=4
integer, parameter   				:: FFTW_REDFT10=5,FFTW_REDFT11=6,FFTW_RODFT00=7,FFTW_RODFT01=8,FFTW_RODFT10=9
integer, parameter   				:: FFTW_RODFT11=10,FFTW_FORWARD=-1,FFTW_BACKWARD=+1,FFTW_DESTROY_INPUT=1
integer, parameter   				:: FFTW_UNALIGNED=2,FFTW_CONSERVE_MEMORY=4,FFTW_EXHAUSTIVE=8,FTW_PRESERVE_INPUT=16
integer, parameter   				:: FFTW_PATIENT=32,FFTW_ESTIMATE=64,FFTW_ESTIMATE_PATIENT=128
integer, parameter   				:: FFTW_BELIEVE_PCOST=256,FFTW_DFT_R2HC_ICKY=512,FFTW_NONTHREADED_ICKY=1024
integer, parameter   				:: FFTW_NO_BUFFERING=2048,FFTW_NO_INDIRECT_OP=4096,FFTW_ALLOW_LARGE_GENERIC=8192
integer, parameter   				:: FFTW_NO_RANK_SPLITS=16384,FFTW_NO_VRANK_SPLITS=32768,FFTW_NO_VRECURSE=65536

   call sfftw_plan_dft(planF1,1,(/size(tfld1)/),tfld1,tfld1,fftW_FORWARD,fftW_PATIENT)
   call sfftw_plan_dft(planI1,1,(/size(tfld1)/),tfld1,tfld1,fftw_BACKWARD,fftW_PATIENT)

end subroutine
!!----------------------------------------------------------------------------
subroutine fftexe3(tfld3)
complex				:: tfld3(:,:,:)
!integer				:: inode

call sfftw_execute(planF3)

end subroutine
!!----------------------------------------------------------------------------
subroutine ifftexe3(tfld3)
complex				:: tfld3(:,:,:)
!integer				:: inode

call sfftw_execute(planI3)

end subroutine
!!----------------------------------------------------------------------------
subroutine fftexe2(tfld2)!,inode)
complex				:: tfld2(:,:)
!integer				:: inode

call sfftw_execute(planF2)

end subroutine
!!----------------------------------------------------------------------------
subroutine ifftexe2(tfld2) !,inode)
complex				:: tfld2(:,:)
!integer				:: inode

call sfftw_execute(planI2)

end subroutine
!!----------------------------------------------------------------------------
subroutine fftexe1(tfld1)!,inode)
complex				:: tfld1(:)
!integer				:: inode

call sfftw_execute(planF1)

end subroutine
!!----------------------------------------------------------------------------
subroutine ifftexe1(tfld1) !,inode)
complex				:: tfld1(:)
!integer				:: inode

call sfftw_execute(planI1)

end subroutine
!----------------------------------------------------------------------------
subroutine owfftdestroy3()

call sfftw_destroy_plan(planF3)
call sfftw_destroy_plan(planI3)

end subroutine
!----------------------------------------------------------------------------
subroutine owfftdestroy2()

call sfftw_destroy_plan(planF2)
call sfftw_destroy_plan(planI2)

end subroutine
!----------------------------------------------------------------------------
subroutine owfftdestroy1()

call sfftw_destroy_plan(planF1)
call sfftw_destroy_plan(planI1)

end subroutine
!----------------------------------------------------------------------------
end module
