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