cannam@95: cannam@95:
cannam@95:cannam@95: Next: Reversing array dimensions, cannam@95: Previous: Calling FFTW from Modern Fortran, cannam@95: Up: Calling FFTW from Modern Fortran cannam@95:
FFTW provides a file fftw3.f03 that defines Fortran 2003
cannam@95: interfaces for all of its C routines, except for the MPI routines
cannam@95: described elsewhere, which can be found in the same directory as
cannam@95: fftw3.h (the C header file).  In any Fortran subroutine where
cannam@95: you want to use FFTW functions, you should begin with:
cannam@95: 
cannam@95:    
use, intrinsic :: iso_c_binding cannam@95: include 'fftw3.f03' cannam@95:cannam@95:
This includes the interface definitions and the standard
cannam@95: iso_c_binding module (which defines the equivalents of C
cannam@95: types).  You can also put the FFTW functions into a module if you
cannam@95: prefer (see Defining an FFTW module).
cannam@95: 
cannam@95:    
At this point, you can now call anything in the FFTW C interface cannam@95: directly, almost exactly as in C other than minor changes in syntax. cannam@95: For example: cannam@95: cannam@95:
type(C_PTR) :: plan cannam@95: complex(C_DOUBLE_COMPLEX), dimension(1024,1000) :: in, out cannam@95: plan = fftw_plan_dft_2d(1000,1024, in,out, FFTW_FORWARD,FFTW_ESTIMATE) cannam@95: ... cannam@95: call fftw_execute_dft(plan, in, out) cannam@95: ... cannam@95: call fftw_destroy_plan(plan) cannam@95:cannam@95:
A few important things to keep in mind are: cannam@95: cannam@95:
type(C_PTR).  Other C types are mapped in the
cannam@95: obvious way via the iso_c_binding standard: int turns
cannam@95: into integer(C_INT), fftw_complex turns into
cannam@95: complex(C_DOUBLE_COMPLEX), double turns into
cannam@95: real(C_DOUBLE), and so on. See FFTW Fortran type reference.
cannam@95: 
cannam@95:      fftw_execute
cannam@95: but rather using the more specialized functions like
cannam@95: fftw_execute_dft (see New-array Execute Functions). 
cannam@95: However, you should execute the plan on the same arrays as the
cannam@95: ones for which you created the plan, unless you are especially
cannam@95: careful.  See Plan execution in Fortran.  To prevent
cannam@95: you from using fftw_execute by mistake, the fftw3.f03
cannam@95: file does not provide an fftw_execute interface declaration.
cannam@95: 
cannam@95:      ior (equivalent to ‘|’ in C).  e.g. FFTW_MEASURE | FFTW_DESTROY_INPUT becomes ior(FFTW_MEASURE, FFTW_DESTROY_INPUT).  (You can also use ‘+’ as long as you don't try to include a given flag more than once.)
cannam@95: 
cannam@95: