
@node Array I/O
@section Inputting and Outputting Arrays

@subsection Output formatting

@cindex persistence
@cindex Array persistence
@cindex output formatting
@cindex Array output formatting
@cindex saving arrays
@cindex writing arrays to output streams
@cindex Array saving to output stream
@cindex Array writing to output stream

The current version of Blitz++ includes rudimentary output formatting for
arrays.  Here's an example:

@smallexample
@include examples/output.texi
@end smallexample

And the output:

@smallexample
@include examples/output.out
@end smallexample

@subsection Inputting arrays

@cindex inputting arrays from an input stream
@cindex Array inputting from istream
@cindex restoring arrays from an input stream
@cindex Array restoring from istream

Arrays may be restored from an istream using the @code{>>} operator.
@strong{Note:} you must know the dimensionality of the array being restored
from the stream.  The @code{>>} operator expects an array in the same input
format as generated by the @code{<<} operator, namely:

@cindex Array persistence format

@itemize @bullet

@item  The size of the array, for example ``32'' for a 1-dimensional array of
32 elements, ``12 x 64 x 128'' for a 3-dimensional array of size 12x64x128.

@item  The symbol @code{'['} indicating the start of the array data

@item  The array elements, listed in memory storage order

@item  The symbol @code{']'} indicating the end of the array data

@end itemize

The operator prototype is:

@example 
template<class T, int N>
istream& operator>>(istream&, Array<T,N>&);
@end example 

Here is an example of saving and restoring arrays from files.  You can find
this example in the Blitz++ distribution as @file{examples/io.cpp}.

@smallexample
@include examples/io.texi
@end smallexample

@strong{Note:} The storage order and starting indices are not restored from
the input stream.  If you are restoring (for example) a Fortran-style array,
you must create a Fortran-style array, and then restore it.  For example,
this code restores a Fortran-style array from the standard input stream:

@example 
Array<float,2> B(fortranArray);
cin >> B;
@end example 
