Next: FFTW Constants in Fortran, Previous: Calling FFTW from Legacy Fortran, Up: Calling FFTW from Legacy Fortran [Contents][Index]

### 8.1 Fortran-interface routines

Nearly all of the FFTW functions have Fortran-callable equivalents. The name of the legacy Fortran routine is the same as that of the corresponding C routine, but with the ‘`fftw_`’ prefix replaced by ‘`dfftw_`’.9 The single and long-double precision versions use ‘`sfftw_`’ and ‘`lfftw_`’, respectively, instead of ‘`fftwf_`’ and ‘`fftwl_`’; quadruple precision (`real*16`) is available on some systems as ‘`fftwq_`’ (see Precision). (Note that `long double` on x86 hardware is usually at most 80-bit extended precision, not quadruple precision.)

For the most part, all of the arguments to the functions are the same, with the following exceptions:

- `plan` variables (what would be of type `fftw_plan` in C), must be declared as a type that is at least as big as a pointer (address) on your machine. We recommend using `integer*8` everywhere, since this should always be big enough.
- Any function that returns a value (e.g. `fftw_plan_dft`) is converted into a subroutine. The return value is converted into an additional first parameter of this subroutine.10
- The Fortran routines expect multi-dimensional arrays to be in column-major order, which is the ordinary format of Fortran arrays (see Multi-dimensional Array Format). They do this transparently and costlessly simply by reversing the order of the dimensions passed to FFTW, but this has one important consequence for multi-dimensional real-complex transforms, discussed below.
- Wisdom import and export is somewhat more tricky because one cannot easily pass files or strings between C and Fortran; see Wisdom of Fortran?.
- Legacy Fortran cannot use the `fftw_malloc` dynamic-allocation routine. If you want to exploit the SIMD FFTW (see SIMD alignment and fftw_malloc), you’ll need to figure out some other way to ensure that your arrays are at least 16-byte aligned.
- Since Fortran 77 does not have data structures, the `fftw_iodim` structure from the guru interface (see Guru vector and transform sizes) must be split into separate arguments. In particular, any `fftw_iodim` array arguments in the C guru interface become three integer array arguments (`n`, `is`, and `os`) in the Fortran guru interface, all of whose lengths should be equal to the corresponding `rank` argument.
- The guru planner interface in Fortran does not do any automatic translation between column-major and row-major; you are responsible for setting the strides etcetera to correspond to your Fortran arrays. However, as a slight bug that we are preserving for backwards compatibility, the ‘`plan_guru_r2r`’ in Fortran does reverse the order of its `kind` array parameter, so the `kind` array of that routine should be in the reverse of the order of the iodim arrays (see above).

In general, you should take care to use Fortran data types that correspond to (i.e. are the same size as) the C types used by FFTW. In practice, this correspondence is usually straightforward (i.e. `integer` corresponds to `int`, `real` corresponds to `float`, etcetera). The native Fortran double/single-precision complex type should be compatible with `fftw_complex`/`fftwf_complex`. Such simple correspondences are assumed in the examples below.

#### Footnotes

### (9)

Technically, Fortran 77 identifiers are not allowed to have more than 6 characters, nor may they contain underscores. Any compiler that enforces this limitation doesn’t deserve to link to FFTW.

### (10)

The reason for this is that some Fortran implementations seem to have trouble with C function return values, and vice versa.

Next: FFTW Constants in Fortran, Previous: Calling FFTW from Legacy Fortran, Up: Calling FFTW from Legacy Fortran [Contents][Index]