root/doc/latex/itfile.tex @ 261

Revision 261, 1.8 kB (checked in by smidl, 16 years ago)

doc

Line 
1Here we will use the {\tt it\_\-file} class to store some data. The program {\tt write\_\-it\_\-file.cpp} looks as follows:
2
3
4
5\begin{DocInclude}\begin{verbatim}#include <itpp/itcomm.h>
6
7using namespace itpp;
8
9int main()
10{
11  // Declare the it_file class
12  it_file ff;
13
14  // Open a file with the name "it_file_test.it"
15  ff.open("it_file_test.it");
16
17  // Create some data to put into the file
18  vec a = linspace(1, 20, 20);
19
20  // Put the variable a into the file. The Name("a") tells the file class
21  // that the next variable shall be named "a".
22  ff << Name("a") << a;
23
24  // Force the file to be written to disc. This is useful when performing
25  // iterations and ensures that the information is not stored in any cache
26  // memory. In this simple example it is not necessary to flush the file.
27  ff.flush();
28
29  // Close the file
30  ff.close();
31
32  // Exit program
33  return 0;
34}
35\end{verbatim}
36\end{DocInclude}
37
38
39When you run this program you will obtain a file called {\tt it\_\-file\_\-test.it} in your current directory. You can read the file into Matlab/Octave to view the data by using the following commands:
40
41
42
43\begin{Code}\begin{verbatim}itload('it_file_test.it')
44figure(1); clf;
45plot(a)
46\end{verbatim}
47\end{Code}
48
49
50
51Note: Make sure that {\tt \$PREFIX/share/itpp} is in your Matlab/Octave path and that you run the code above from the directory where {\tt it\_\-file\_\-test.it} is located ({\tt \$PREFIX} is the IT++ installation prefix; {\tt /usr/local} by default).
52
53The IT++ program {\tt read\_\-it\_\-file.cpp} that reads the file and prints its content can look like this:
54
55
56
57\begin{DocInclude}\begin{verbatim}\end{verbatim}
58\end{DocInclude}
59
60
61Here is the output of the program:
62
63
64
65\footnotesize\begin{verbatim}
66a = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20]
67\end{verbatim}
68\normalsize
69 
Note: See TracBrowser for help on using the browser.