annotate src/fftw-3.3.3/doc/html/Wisdom-String-Export_002fImport-from-Fortran.html @ 169:223a55898ab9 tip default

Add null config files
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 02 Mar 2020 14:03:47 +0000
parents 89f5e221ed7b
children
rev   line source
cannam@95 1 <html lang="en">
cannam@95 2 <head>
cannam@95 3 <title>Wisdom String 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-File-Export_002fImport-from-Fortran.html#Wisdom-File-Export_002fImport-from-Fortran" title="Wisdom File Export/Import from Fortran">
cannam@95 10 <link rel="next" href="Wisdom-Generic-Export_002fImport-from-Fortran.html#Wisdom-Generic-Export_002fImport-from-Fortran" title="Wisdom Generic Export/Import from Fortran">
cannam@95 11 <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
cannam@95 12 <!--
cannam@95 13 This manual is for FFTW
cannam@95 14 (version 3.3.3, 25 November 2012).
cannam@95 15
cannam@95 16 Copyright (C) 2003 Matteo Frigo.
cannam@95 17
cannam@95 18 Copyright (C) 2003 Massachusetts Institute of Technology.
cannam@95 19
cannam@95 20 Permission is granted to make and distribute verbatim copies of
cannam@95 21 this manual provided the copyright notice and this permission
cannam@95 22 notice are preserved on all copies.
cannam@95 23
cannam@95 24 Permission is granted to copy and distribute modified versions of
cannam@95 25 this manual under the conditions for verbatim copying, provided
cannam@95 26 that the entire resulting derived work is distributed under the
cannam@95 27 terms of a permission notice identical to this one.
cannam@95 28
cannam@95 29 Permission is granted to copy and distribute translations of this
cannam@95 30 manual into another language, under the above conditions for
cannam@95 31 modified versions, except that this permission notice may be
cannam@95 32 stated in a translation approved by the Free Software Foundation.
cannam@95 33 -->
cannam@95 34 <meta http-equiv="Content-Style-Type" content="text/css">
cannam@95 35 <style type="text/css"><!--
cannam@95 36 pre.display { font-family:inherit }
cannam@95 37 pre.format { font-family:inherit }
cannam@95 38 pre.smalldisplay { font-family:inherit; font-size:smaller }
cannam@95 39 pre.smallformat { font-family:inherit; font-size:smaller }
cannam@95 40 pre.smallexample { font-size:smaller }
cannam@95 41 pre.smalllisp { font-size:smaller }
cannam@95 42 span.sc { font-variant:small-caps }
cannam@95 43 span.roman { font-family:serif; font-weight:normal; }
cannam@95 44 span.sansserif { font-family:sans-serif; font-weight:normal; }
cannam@95 45 --></style>
cannam@95 46 </head>
cannam@95 47 <body>
cannam@95 48 <div class="node">
cannam@95 49 <a name="Wisdom-String-Export%2fImport-from-Fortran"></a>
cannam@95 50 <a name="Wisdom-String-Export_002fImport-from-Fortran"></a>
cannam@95 51 <p>
cannam@95 52 Next:&nbsp;<a rel="next" accesskey="n" href="Wisdom-Generic-Export_002fImport-from-Fortran.html#Wisdom-Generic-Export_002fImport-from-Fortran">Wisdom Generic Export/Import from Fortran</a>,
cannam@95 53 Previous:&nbsp;<a rel="previous" accesskey="p" href="Wisdom-File-Export_002fImport-from-Fortran.html#Wisdom-File-Export_002fImport-from-Fortran">Wisdom File Export/Import from Fortran</a>,
cannam@95 54 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 55 <hr>
cannam@95 56 </div>
cannam@95 57
cannam@95 58 <h4 class="subsection">7.6.2 Wisdom String Export/Import from Fortran</h4>
cannam@95 59
cannam@95 60 <p><a name="index-fftw_005fexport_005fwisdom_005fto_005fstring-568"></a>Dealing with FFTW's C string export/import is a bit more painful. In
cannam@95 61 particular, the <code>fftw_export_wisdom_to_string</code> function requires
cannam@95 62 you to deal with a dynamically allocated C string. To get its length,
cannam@95 63 you must define an interface to the C <code>strlen</code> function, and to
cannam@95 64 deallocate it you must define an interface to C <code>free</code>:
cannam@95 65
cannam@95 66 <pre class="example"> use, intrinsic :: iso_c_binding
cannam@95 67 interface
cannam@95 68 integer(C_INT) function strlen(s) bind(C, name='strlen')
cannam@95 69 import
cannam@95 70 type(C_PTR), value :: s
cannam@95 71 end function strlen
cannam@95 72 subroutine free(p) bind(C, name='free')
cannam@95 73 import
cannam@95 74 type(C_PTR), value :: p
cannam@95 75 end subroutine free
cannam@95 76 end interface
cannam@95 77 </pre>
cannam@95 78 <p>Given these definitions, you can then export wisdom to a Fortran
cannam@95 79 character array:
cannam@95 80
cannam@95 81 <pre class="example"> character(C_CHAR), pointer :: s(:)
cannam@95 82 integer(C_SIZE_T) :: slen
cannam@95 83 type(C_PTR) :: p
cannam@95 84 p = fftw_export_wisdom_to_string()
cannam@95 85 if (.not. c_associated(p)) stop 'error exporting wisdom'
cannam@95 86 slen = strlen(p)
cannam@95 87 call c_f_pointer(p, s, [slen+1])
cannam@95 88 ...
cannam@95 89 call free(p)
cannam@95 90 </pre>
cannam@95 91 <p><a name="index-c_005fassociated-569"></a><a name="index-c_005ff_005fpointer-570"></a>
cannam@95 92 Note that <code>slen</code> is the length of the C string, but the length of
cannam@95 93 the array is <code>slen+1</code> because it includes the terminating null
cannam@95 94 character. (You can omit the &lsquo;<samp><span class="samp">+1</span></samp>&rsquo; if you don't want Fortran to
cannam@95 95 know about the null character.) The standard <code>c_associated</code> function
cannam@95 96 checks whether <code>p</code> is a null pointer, which is returned by
cannam@95 97 <code>fftw_export_wisdom_to_string</code> if there was an error.
cannam@95 98
cannam@95 99 <p><a name="index-fftw_005fimport_005fwisdom_005ffrom_005fstring-571"></a>To import wisdom from a string, use
cannam@95 100 <code>fftw_import_wisdom_from_string</code> as usual; note that the argument
cannam@95 101 of this function must be a <code>character(C_CHAR)</code> that is terminated
cannam@95 102 by the <code>C_NULL_CHAR</code> character, like the <code>s</code> array above.
cannam@95 103
cannam@95 104 <!-- =========> -->
cannam@95 105 </body></html>
cannam@95 106