Chris@82: Chris@82: Chris@82: Chris@82: Chris@82:
Chris@82:Chris@82: Previous: Wisdom String Export/Import from Fortran, Up: Accessing the wisdom API from Fortran [Contents][Index]
Chris@82:The most generic wisdom export/import functions allow you to provide
Chris@82: an arbitrary callback function to read/write one character at a time
Chris@82: in any way you want. However, your callback function must be written
Chris@82: in a special way, using the bind(C)
attribute to be passed to a
Chris@82: C interface.
Chris@82:
In particular, to call the generic wisdom export function
Chris@82: fftw_export_wisdom
, you would write a callback subroutine of the form:
Chris@82:
subroutine my_write_char(c, p) bind(C) Chris@82: use, intrinsic :: iso_c_binding Chris@82: character(C_CHAR), value :: c Chris@82: type(C_PTR), value :: p Chris@82: ...write c... Chris@82: end subroutine my_write_char Chris@82:
Given such a subroutine (along with the corresponding interface definition), you could then export wisdom using: Chris@82:
Chris@82: Chris@82:call fftw_export_wisdom(c_funloc(my_write_char), p) Chris@82:
The standard c_funloc
intrinsic converts a Fortran
Chris@82: bind(C)
subroutine into a C function pointer. The parameter
Chris@82: p
is a type(C_PTR)
to any arbitrary data that you want
Chris@82: to pass to my_write_char
(or C_NULL_PTR
if none). (Note
Chris@82: that you can get a C pointer to Fortran data using the intrinsic
Chris@82: c_loc
, and convert it back to a Fortran pointer in
Chris@82: my_write_char
using c_f_pointer
.)
Chris@82:
Similarly, to use the generic fftw_import_wisdom
, you would
Chris@82: define a callback function of the form:
Chris@82:
integer(C_INT) function my_read_char(p) bind(C) Chris@82: use, intrinsic :: iso_c_binding Chris@82: type(C_PTR), value :: p Chris@82: character :: c Chris@82: ...read a character c... Chris@82: my_read_char = ichar(c, C_INT) Chris@82: end function my_read_char Chris@82: Chris@82: .... Chris@82: Chris@82: integer(C_INT) :: ret Chris@82: ret = fftw_import_wisdom(c_funloc(my_read_char), p) Chris@82: if (ret .eq. 0) stop 'error importing wisdom' Chris@82:
Your function can return -1
if the end of the input is reached.
Chris@82: Again, p
is an arbitrary type(C_PTR
that is passed
Chris@82: through to your function. fftw_import_wisdom
returns 0
Chris@82: if an error occurred and nonzero otherwise.
Chris@82:
Chris@82: Previous: Wisdom String Export/Import from Fortran, Up: Accessing the wisdom API from Fortran [Contents][Index]
Chris@82: