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