Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: FFTW 3.3.5: Wisdom Generic Export/Import from Fortran Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42:
Chris@42:

Chris@42: Previous: , Up: Accessing the wisdom API from Fortran   [Contents][Index]

Chris@42:
Chris@42:
Chris@42: Chris@42:

7.6.3 Wisdom Generic Export/Import from Fortran

Chris@42: Chris@42:

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

Chris@42: Chris@42:

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

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

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

Chris@42: Chris@42:
Chris@42:
  call fftw_export_wisdom(c_funloc(my_write_char), p)
Chris@42: 
Chris@42: Chris@42: Chris@42: Chris@42:

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

Chris@42:

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

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

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

Chris@42:
Chris@42:
Chris@42:

Chris@42: Previous: , Up: Accessing the wisdom API from Fortran   [Contents][Index]

Chris@42:
Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: