| 1 |
#include <blitz/array.h> |
| 2 |
#ifdef BZ_HAVE_STD |
| 3 |
#include <fstream> |
| 4 |
#else |
| 5 |
#include <fstream.h> |
| 6 |
#endif |
| 7 |
|
| 8 |
using namespace blitz; |
| 9 |
|
| 10 |
const char* filename = "io.data"; |
| 11 |
|
| 12 |
void write_arrays() |
| 13 |
{ |
| 14 |
ofstream ofs(filename); |
| 15 |
if (ofs.bad()) |
| 16 |
{ |
| 17 |
cerr << "Unable to write to file: " << filename << endl; |
| 18 |
exit(1); |
| 19 |
} |
| 20 |
|
| 21 |
Array<float,3> A(3,4,5); |
| 22 |
A = 111 + tensor::i + 10 * tensor::j + 100 * tensor::k; |
| 23 |
ofs << A << endl; |
| 24 |
|
| 25 |
Array<float,2> B(3,4); |
| 26 |
B = 11 + tensor::i + 10 * tensor::j; |
| 27 |
ofs << B << endl; |
| 28 |
|
| 29 |
Array<float,1> C(4); |
| 30 |
C = 1 + tensor::i; |
| 31 |
ofs << C << endl; |
| 32 |
} |
| 33 |
|
| 34 |
int main() |
| 35 |
{ |
| 36 |
write_arrays(); |
| 37 |
|
| 38 |
ifstream ifs(filename); |
| 39 |
if (ifs.bad()) |
| 40 |
{ |
| 41 |
cerr << "Unable to open file: " << filename << endl; |
| 42 |
exit(1); |
| 43 |
} |
| 44 |
|
| 45 |
Array<float,3> A; |
| 46 |
Array<float,2> B; |
| 47 |
Array<float,1> C; |
| 48 |
|
| 49 |
ifs >> A >> B >> C; |
| 50 |
|
| 51 |
cout << "Arrays restored from file: " << A << B << C << endl; |
| 52 |
|
| 53 |
return 0; |
| 54 |
} |
| 55 |
|