annotate src/fftw-3.3.3/doc/html/Wisdom-Generic-Export_002fImport-from-Fortran.html @ 95:89f5e221ed7b

Add FFTW3
author Chris Cannam <cannam@all-day-breakfast.com>
date Wed, 20 Mar 2013 15:35:50 +0000
parents
children
rev   line source
cannam@95 1 <html lang="en">
cannam@95 2 <head>
cannam@95 3 <title>Wisdom Generic Export/Import from Fortran - FFTW 3.3.3</title>
cannam@95 4 <meta http-equiv="Content-Type" content="text/html">
cannam@95 5 <meta name="description" content="FFTW 3.3.3">
cannam@95 6 <meta name="generator" content="makeinfo 4.13">
cannam@95 7 <link title="Top" rel="start" href="index.html#Top">
cannam@95 8 <link rel="up" href="Accessing-the-wisdom-API-from-Fortran.html#Accessing-the-wisdom-API-from-Fortran" title="Accessing the wisdom API from Fortran">
cannam@95 9 <link rel="prev" href="Wisdom-String-Export_002fImport-from-Fortran.html#Wisdom-String-Export_002fImport-from-Fortran" title="Wisdom String Export/Import from Fortran">
cannam@95 10 <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
cannam@95 11 <!--
cannam@95 12 This manual is for FFTW
cannam@95 13 (version 3.3.3, 25 November 2012).
cannam@95 14
cannam@95 15 Copyright (C) 2003 Matteo Frigo.
cannam@95 16
cannam@95 17 Copyright (C) 2003 Massachusetts Institute of Technology.
cannam@95 18
cannam@95 19 Permission is granted to make and distribute verbatim copies of
cannam@95 20 this manual provided the copyright notice and this permission
cannam@95 21 notice are preserved on all copies.
cannam@95 22
cannam@95 23 Permission is granted to copy and distribute modified versions of
cannam@95 24 this manual under the conditions for verbatim copying, provided
cannam@95 25 that the entire resulting derived work is distributed under the
cannam@95 26 terms of a permission notice identical to this one.
cannam@95 27
cannam@95 28 Permission is granted to copy and distribute translations of this
cannam@95 29 manual into another language, under the above conditions for
cannam@95 30 modified versions, except that this permission notice may be
cannam@95 31 stated in a translation approved by the Free Software Foundation.
cannam@95 32 -->
cannam@95 33 <meta http-equiv="Content-Style-Type" content="text/css">
cannam@95 34 <style type="text/css"><!--
cannam@95 35 pre.display { font-family:inherit }
cannam@95 36 pre.format { font-family:inherit }
cannam@95 37 pre.smalldisplay { font-family:inherit; font-size:smaller }
cannam@95 38 pre.smallformat { font-family:inherit; font-size:smaller }
cannam@95 39 pre.smallexample { font-size:smaller }
cannam@95 40 pre.smalllisp { font-size:smaller }
cannam@95 41 span.sc { font-variant:small-caps }
cannam@95 42 span.roman { font-family:serif; font-weight:normal; }
cannam@95 43 span.sansserif { font-family:sans-serif; font-weight:normal; }
cannam@95 44 --></style>
cannam@95 45 </head>
cannam@95 46 <body>
cannam@95 47 <div class="node">
cannam@95 48 <a name="Wisdom-Generic-Export%2fImport-from-Fortran"></a>
cannam@95 49 <a name="Wisdom-Generic-Export_002fImport-from-Fortran"></a>
cannam@95 50 <p>
cannam@95 51 Previous:&nbsp;<a rel="previous" accesskey="p" href="Wisdom-String-Export_002fImport-from-Fortran.html#Wisdom-String-Export_002fImport-from-Fortran">Wisdom String Export/Import from Fortran</a>,
cannam@95 52 Up:&nbsp;<a rel="up" accesskey="u" href="Accessing-the-wisdom-API-from-Fortran.html#Accessing-the-wisdom-API-from-Fortran">Accessing the wisdom API from Fortran</a>
cannam@95 53 <hr>
cannam@95 54 </div>
cannam@95 55
cannam@95 56 <h4 class="subsection">7.6.3 Wisdom Generic Export/Import from Fortran</h4>
cannam@95 57
cannam@95 58 <p>The most generic wisdom export/import functions allow you to provide
cannam@95 59 an arbitrary callback function to read/write one character at a time
cannam@95 60 in any way you want. However, your callback function must be written
cannam@95 61 in a special way, using the <code>bind(C)</code> attribute to be passed to a
cannam@95 62 C interface.
cannam@95 63
cannam@95 64 <p><a name="index-fftw_005fexport_005fwisdom-572"></a>In particular, to call the generic wisdom export function
cannam@95 65 <code>fftw_export_wisdom</code>, you would write a callback subroutine of the form:
cannam@95 66
cannam@95 67 <pre class="example"> subroutine my_write_char(c, p) bind(C)
cannam@95 68 use, intrinsic :: iso_c_binding
cannam@95 69 character(C_CHAR), value :: c
cannam@95 70 type(C_PTR), value :: p
cannam@95 71 <em>...write c...</em>
cannam@95 72 end subroutine my_write_char
cannam@95 73 </pre>
cannam@95 74 <p>Given such a subroutine (along with the corresponding interface definition), you could then export wisdom using:
cannam@95 75
cannam@95 76 <p><a name="index-c_005ffunloc-573"></a>
cannam@95 77 <pre class="example"> call fftw_export_wisdom(c_funloc(my_write_char), p)
cannam@95 78 </pre>
cannam@95 79 <p><a name="index-c_005floc-574"></a><a name="index-c_005ff_005fpointer-575"></a>The standard <code>c_funloc</code> intrinsic converts a Fortran
cannam@95 80 <code>bind(C)</code> subroutine into a C function pointer. The parameter
cannam@95 81 <code>p</code> is a <code>type(C_PTR)</code> to any arbitrary data that you want
cannam@95 82 to pass to <code>my_write_char</code> (or <code>C_NULL_PTR</code> if none). (Note
cannam@95 83 that you can get a C pointer to Fortran data using the intrinsic
cannam@95 84 <code>c_loc</code>, and convert it back to a Fortran pointer in
cannam@95 85 <code>my_write_char</code> using <code>c_f_pointer</code>.)
cannam@95 86
cannam@95 87 <p>Similarly, to use the generic <code>fftw_import_wisdom</code>, you would
cannam@95 88 define a callback function of the form:
cannam@95 89
cannam@95 90 <p><a name="index-fftw_005fimport_005fwisdom-576"></a>
cannam@95 91 <pre class="example"> integer(C_INT) function my_read_char(p) bind(C)
cannam@95 92 use, intrinsic :: iso_c_binding
cannam@95 93 type(C_PTR), value :: p
cannam@95 94 character :: c
cannam@95 95 <em>...read a character c...</em>
cannam@95 96 my_read_char = ichar(c, C_INT)
cannam@95 97 end function my_read_char
cannam@95 98
cannam@95 99 ....
cannam@95 100
cannam@95 101 integer(C_INT) :: ret
cannam@95 102 ret = fftw_import_wisdom(c_funloc(my_read_char), p)
cannam@95 103 if (ret .eq. 0) stop 'error importing wisdom'
cannam@95 104 </pre>
cannam@95 105 <p>Your function can return <code>-1</code> if the end of the input is reached.
cannam@95 106 Again, <code>p</code> is an arbitrary <code>type(C_PTR</code> that is passed
cannam@95 107 through to your function. <code>fftw_import_wisdom</code> returns <code>0</code>
cannam@95 108 if an error occurred and nonzero otherwise.
cannam@95 109
cannam@95 110 <!-- -->
cannam@95 111 </body></html>
cannam@95 112