3
<title>Reading and writing vectors - GNU Scientific Library -- Reference Manual</title>
4
<meta http-equiv="Content-Type" content="text/html">
5
<meta name="description" content="GNU Scientific Library -- Reference Manual">
6
<meta name="generator" content="makeinfo 4.8">
7
<link title="Top" rel="start" href="index.html#Top">
8
<link rel="up" href="Vectors.html#Vectors" title="Vectors">
9
<link rel="prev" href="Initializing-vector-elements.html#Initializing-vector-elements" title="Initializing vector elements">
10
<link rel="next" href="Vector-views.html#Vector-views" title="Vector views">
11
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
13
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 The GSL Team.
15
Permission is granted to copy, distribute and/or modify this document
16
under the terms of the GNU Free Documentation License, Version 1.2 or
17
any later version published by the Free Software Foundation; with the
18
Invariant Sections being ``GNU General Public License'' and ``Free Software
19
Needs Free Documentation'', the Front-Cover text being ``A GNU Manual'',
20
and with the Back-Cover Text being (a) (see below). A copy of the
21
license is included in the section entitled ``GNU Free Documentation
24
(a) The Back-Cover Text is: ``You have freedom to copy and modify this
25
GNU Manual, like GNU software.''-->
26
<meta http-equiv="Content-Style-Type" content="text/css">
27
<style type="text/css"><!--
28
pre.display { font-family:inherit }
29
pre.format { font-family:inherit }
30
pre.smalldisplay { font-family:inherit; font-size:smaller }
31
pre.smallformat { font-family:inherit; font-size:smaller }
32
pre.smallexample { font-size:smaller }
33
pre.smalllisp { font-size:smaller }
34
span.sc { font-variant:small-caps }
35
span.roman { font-family:serif; font-weight:normal; }
36
span.sansserif { font-family:sans-serif; font-weight:normal; }
42
<a name="Reading-and-writing-vectors"></a>
43
Next: <a rel="next" accesskey="n" href="Vector-views.html#Vector-views">Vector views</a>,
44
Previous: <a rel="previous" accesskey="p" href="Initializing-vector-elements.html#Initializing-vector-elements">Initializing vector elements</a>,
45
Up: <a rel="up" accesskey="u" href="Vectors.html#Vectors">Vectors</a>
49
<h4 class="subsection">8.3.4 Reading and writing vectors</h4>
51
<p>The library provides functions for reading and writing vectors to a file
52
as binary data or formatted text.
55
— Function: int <b>gsl_vector_fwrite</b> (<var>FILE * stream, const gsl_vector * v</var>)<var><a name="index-gsl_005fvector_005ffwrite-842"></a></var><br>
56
<blockquote><p>This function writes the elements of the vector <var>v</var> to the stream
57
<var>stream</var> in binary format. The return value is 0 for success and
58
<code>GSL_EFAILED</code> if there was a problem writing to the file. Since the
59
data is written in the native binary format it may not be portable
60
between different architectures.
61
</p></blockquote></div>
64
— Function: int <b>gsl_vector_fread</b> (<var>FILE * stream, gsl_vector * v</var>)<var><a name="index-gsl_005fvector_005ffread-843"></a></var><br>
65
<blockquote><p>This function reads into the vector <var>v</var> from the open stream
66
<var>stream</var> in binary format. The vector <var>v</var> must be preallocated
67
with the correct length since the function uses the size of <var>v</var> to
68
determine how many bytes to read. The return value is 0 for success and
69
<code>GSL_EFAILED</code> if there was a problem reading from the file. The
70
data is assumed to have been written in the native binary format on the
72
</p></blockquote></div>
75
— Function: int <b>gsl_vector_fprintf</b> (<var>FILE * stream, const gsl_vector * v, const char * format</var>)<var><a name="index-gsl_005fvector_005ffprintf-844"></a></var><br>
76
<blockquote><p>This function writes the elements of the vector <var>v</var> line-by-line to
77
the stream <var>stream</var> using the format specifier <var>format</var>, which
78
should be one of the <code>%g</code>, <code>%e</code> or <code>%f</code> formats for
79
floating point numbers and <code>%d</code> for integers. The function returns
80
0 for success and <code>GSL_EFAILED</code> if there was a problem writing to
82
</p></blockquote></div>
85
— Function: int <b>gsl_vector_fscanf</b> (<var>FILE * stream, gsl_vector * v</var>)<var><a name="index-gsl_005fvector_005ffscanf-845"></a></var><br>
86
<blockquote><p>This function reads formatted data from the stream <var>stream</var> into the
87
vector <var>v</var>. The vector <var>v</var> must be preallocated with the correct
88
length since the function uses the size of <var>v</var> to determine how many
89
numbers to read. The function returns 0 for success and
90
<code>GSL_EFAILED</code> if there was a problem reading from the file.
91
</p></blockquote></div>