Next: Wisdom String Export/Import from Fortran, Previous: Accessing the wisdom API from Fortran, Up: Accessing the wisdom API from Fortran [Contents][Index]

#### 7.6.1 Wisdom File Export/Import from Fortran

The easiest way to export and import wisdom is to do so using `fftw_export_wisdom_to_filename` and `fftw_wisdom_from_filename`. The only trick is that these require you to pass a C string, which is an array of type `CHARACTER(C_CHAR)` that is terminated by `C_NULL_CHAR`. You can call them like this:

      integer(C_INT) :: ret
      ret = fftw_export_wisdom_to_filename(C_CHAR_'my_wisdom.dat' // C_NULL_CHAR)
      if (ret .eq. 0) stop 'error exporting wisdom to file'
      ret = fftw_import_wisdom_from_filename(C_CHAR_'my_wisdom.dat' // C_NULL_CHAR)
      if (ret .eq. 0) stop 'error importing wisdom from file'

Note that prepending ‘`C_CHAR_`’ is needed to specify that the literal string is of kind `C_CHAR`, and we null-terminate the string by appending ‘`// C_NULL_CHAR`’. These functions return an `integer(C_INT)` (`ret`) which is `0` if an error occurred during export/import and nonzero otherwise.

It is also possible to use the lower-level routines `fftw_export_wisdom_to_file` and `fftw_import_wisdom_from_file`, which accept parameters of the C type `FILE*`, expressed in Fortran as `type(C_PTR)`. However, you are then responsible for creating the `FILE*` yourself. You can do this by using `iso_c_binding` to define Fortran intefaces for the C library functions `fopen` and `fclose`, which is a bit strange in Fortran but workable.