cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: FFTW 3.3.8: Wisdom Generic Export/Import from Fortran cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167:
cannam@167:

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

cannam@167:
cannam@167:
cannam@167: cannam@167:

7.6.3 Wisdom Generic Export/Import from Fortran

cannam@167: cannam@167:

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

cannam@167: cannam@167:

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

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

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

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

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

cannam@167:

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

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

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

cannam@167:
cannam@167:
cannam@167:

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

cannam@167:
cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: