Previous: Accessing the wisdom API from Fortran, Up: Calling FFTW from Modern Fortran


7.7 Defining an FFTW module

Rather than using the include statement to include the fftw3.f03 interface file in any subroutine where you want to use FFTW, you might prefer to define an FFTW Fortran module. FFTW does not install itself as a module, primarily because fftw3.f03 can be shared between different Fortran compilers while modules (in general) cannot. However, it is trivial to define your own FFTW module if you want. Just create a file containing:

       module FFTW3
         use, intrinsic :: iso_c_binding
         include 'fftw3.f03'
       end module

Compile this file into a module as usual for your compiler (e.g. with gfortran -c you will get a file fftw3.mod). Now, instead of include 'fftw3.f03', whenever you want to use FFTW routines you can just do:

       use FFTW3

as usual for Fortran modules. (You still need to link to the FFTW library, of course.)