| [ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
7.3 FFTW Fortran type reference
The following are the most important type correspondences between the C interface and Fortran:
-
Plans (
fftw_planand variants) aretype(C_PTR)(i.e. an opaque pointer). -
The C floating-point types
double,float, andlong doublecorrespond toreal(C_DOUBLE),real(C_FLOAT), andreal(C_LONG_DOUBLE), respectively. The C complex typesfftw_complex,fftwf_complex, andfftwl_complexcorrespond in Fortran tocomplex(C_DOUBLE_COMPLEX),complex(C_FLOAT_COMPLEX), andcomplex(C_LONG_DOUBLE_COMPLEX), respectively. Just as in C (see section Precision), the FFTW subroutines and types are prefixed with ‘fftw_’,fftwf_, andfftwl_for the different precisions, and link to different libraries (-lfftw3,-lfftw3f, and-lfftw3lon Unix), but use the same include filefftw3.f03and the same constants (all of which begin with ‘FFTW_’). The exception islong doubleprecision, for which you should also includefftw3l.f03(see section Extended and quadruple precision in Fortran). -
The C integer types
intandunsigned(used for planner flags) becomeinteger(C_INT). The C integer typeptrdiff_t(e.g. in the 64-bit Guru Interface) becomesinteger(C_INTPTR_T), andsize_t(infftw_mallocetc.) becomesinteger(C_SIZE_T). -
The
fftw_r2r_kindtype (see section Real-to-Real Transform Kinds) becomesinteger(C_FFTW_R2R_KIND). The various constant values of the C enumerated type (FFTW_R2HCetc.) become simply integer constants of the same names in Fortran. -
Numeric array pointer arguments (e.g.
double *) becomedimension(*), intent(out)arrays of the same type, ordimension(*), intent(in)if they are pointers to constant data (e.g.const int *). There are a few exceptions where numeric pointers refer to scalar outputs (e.g. forfftw_flops), in which case they areintent(out)scalar arguments in Fortran too. For the new-array execute functions (see section New-array Execute Functions), the input arrays are declareddimension(*), intent(inout), since they can be modified in the case of in-place orFFTW_DESTROY_INPUTtransforms. -
Pointer return values (e.g
double *) becometype(C_PTR). (If they are pointers to arrays, as forfftw_alloc_real, you can convert them back to Fortran array pointers with the standard intrinsic functionc_f_pointer.) -
The
fftw_iodimtype in the guru interface (see section Guru vector and transform sizes) becomestype(fftw_iodim)in Fortran, a derived data type (the Fortran analogue of C’sstruct) with threeinteger(C_INT)components:n,is, andos, with the same meanings as in C. Thefftw_iodim64type in the 64-bit guru interface (see section 64-bit Guru Interface) is the same, except that its components are of typeinteger(C_INTPTR_T). -
Using the wisdom import/export functions from Fortran is a bit tricky,
and is discussed in Accessing the wisdom API from Fortran. In
brief, the
FILE *arguments map totype(C_PTR),const char *tocharacter(C_CHAR), dimension(*), intent(in)(null-terminated!), and the generic read-char/write-char functions map totype(C_FUNPTR).
You may be wondering if you need to search-and-replace
real(kind(0.0d0)) (or whatever your favorite Fortran spelling
of “double precision” is) with real(C_DOUBLE) everywhere in
your program, and similarly for complex and integer
types. The answer is no; you can still use your existing types. As
long as these types match their C counterparts, things should work
without a hitch. The worst that can happen, e.g. in the (unlikely)
event of a system where real(kind(0.0d0)) is different from
real(C_DOUBLE), is that the compiler will give you a
type-mismatch error. That is, if you don’t use the
iso_c_binding kinds you need to accept at least the theoretical
possibility of having to change your code in response to compiler
errors on some future machine, but you don’t need to worry about
silently compiling incorrect code that yields runtime errors.
| [ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on March 3, 2012 using texi2html 5.0.
