cannam@127: cannam@127: cannam@127: cannam@127: cannam@127: cannam@127: FFTW 3.3.5: Wisdom Generic Export/Import from Fortran cannam@127: cannam@127: cannam@127: cannam@127: cannam@127: cannam@127: cannam@127: cannam@127: cannam@127: cannam@127: cannam@127: cannam@127: cannam@127: cannam@127: cannam@127: cannam@127: cannam@127: cannam@127: cannam@127: cannam@127: cannam@127:
cannam@127:

cannam@127: Previous: , Up: Accessing the wisdom API from Fortran   [Contents][Index]

cannam@127:
cannam@127:
cannam@127: cannam@127:

7.6.3 Wisdom Generic Export/Import from Fortran

cannam@127: cannam@127:

The most generic wisdom export/import functions allow you to provide cannam@127: an arbitrary callback function to read/write one character at a time cannam@127: in any way you want. However, your callback function must be written cannam@127: in a special way, using the bind(C) attribute to be passed to a cannam@127: C interface. cannam@127:

cannam@127: cannam@127:

In particular, to call the generic wisdom export function cannam@127: fftw_export_wisdom, you would write a callback subroutine of the form: cannam@127:

cannam@127:
cannam@127:
  subroutine my_write_char(c, p) bind(C)
cannam@127:     use, intrinsic :: iso_c_binding
cannam@127:     character(C_CHAR), value :: c
cannam@127:     type(C_PTR), value :: p
cannam@127:     ...write c...
cannam@127:   end subroutine my_write_char
cannam@127: 
cannam@127: cannam@127:

Given such a subroutine (along with the corresponding interface definition), you could then export wisdom using: cannam@127:

cannam@127: cannam@127:
cannam@127:
  call fftw_export_wisdom(c_funloc(my_write_char), p)
cannam@127: 
cannam@127: cannam@127: cannam@127: cannam@127:

The standard c_funloc intrinsic converts a Fortran cannam@127: bind(C) subroutine into a C function pointer. The parameter cannam@127: p is a type(C_PTR) to any arbitrary data that you want cannam@127: to pass to my_write_char (or C_NULL_PTR if none). (Note cannam@127: that you can get a C pointer to Fortran data using the intrinsic cannam@127: c_loc, and convert it back to a Fortran pointer in cannam@127: my_write_char using c_f_pointer.) cannam@127:

cannam@127:

Similarly, to use the generic fftw_import_wisdom, you would cannam@127: define a callback function of the form: cannam@127:

cannam@127: cannam@127:
cannam@127:
  integer(C_INT) function my_read_char(p) bind(C)
cannam@127:     use, intrinsic :: iso_c_binding
cannam@127:     type(C_PTR), value :: p
cannam@127:     character :: c
cannam@127:     ...read a character c...
cannam@127:     my_read_char = ichar(c, C_INT)
cannam@127:   end function my_read_char
cannam@127: 
cannam@127:   ....
cannam@127: 
cannam@127:   integer(C_INT) :: ret
cannam@127:   ret = fftw_import_wisdom(c_funloc(my_read_char), p)
cannam@127:   if (ret .eq. 0) stop 'error importing wisdom'
cannam@127: 
cannam@127: cannam@127:

Your function can return -1 if the end of the input is reached. cannam@127: Again, p is an arbitrary type(C_PTR that is passed cannam@127: through to your function. fftw_import_wisdom returns 0 cannam@127: if an error occurred and nonzero otherwise. cannam@127:

cannam@127:
cannam@127:
cannam@127:

cannam@127: Previous: , Up: Accessing the wisdom API from Fortran   [Contents][Index]

cannam@127:
cannam@127: cannam@127: cannam@127: cannam@127: cannam@127: