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