- Import and Export of Data in Xi -
Xi's file handling is similar to the C++ stream concept. Xi has also input and output stream variables. I.e. the line
( 1)>os=ostream("test.data",\ascii);
declares the output stream variable "os" as an ascii-stream. Use
the "<<" operator to write something to the file and delete the stream variable
to close the file
( 2)>os << dincarr(10); ( 3)>delete os; ( 4)>$cat test.data 0 1 2 3 4 5 6 7 8 9Xi is able to handle the following stream types:
| Stream Type | Example |
| ASCII | os=ostream("test.data",\ascii); |
| Binary | os=ostream("test.data",\bin); |
| Fortran 77 unformatted | os=ostream("test.data",\fortran); |
Use input streams and the ">>" operator in the same way. Detect whenn the end of a file is reached by using the function eof.
( 5)>i=darr(10);
( 6)>is=istream("test.data",\ascii);
( 7)>print(eof(is));
<int> 0
( 8)>is >> i;
( 9)>print(i);
<dblarr>
0 1 2 3 4 5 6 7 8 9
( 10)>print(eof(is));
<int> 0
( 11)>is >> i
Non-Fatal I/O error
( 12)>print(eof(is));
<int> 1
( 13)>delete is;