| 1 | #include <boost/lexical_cast.hpp>
|
|---|
| 2 | #include <boost/numeric/ublas/io.hpp>
|
|---|
| 3 | #include <boost/archive/binary_iarchive.hpp>
|
|---|
| 4 | #include <boost/archive/binary_oarchive.hpp>
|
|---|
| 5 | #include <iostream>
|
|---|
| 6 | #include <string>
|
|---|
| 7 | #include <fstream>
|
|---|
| 8 | #include "throw_with_info.hpp"
|
|---|
| 9 | //#include "boost_extras/serialization/numeric/ublas/include/matrix_sparse.hpp"
|
|---|
| 10 | #include <boost/numeric/ublas/matrix_sparse.hpp>
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 | using namespace std;
|
|---|
| 14 | using namespace boost;
|
|---|
| 15 | using namespace numeric;
|
|---|
| 16 | using namespace ublas;
|
|---|
| 17 |
|
|---|
| 18 | #undef __FUNCT__
|
|---|
| 19 | #define __FUNCT__ "main"
|
|---|
| 20 |
|
|---|
| 21 | int main(int argc,char *argv[]) {
|
|---|
| 22 |
|
|---|
| 23 | if (argc > 2 || argc < 1) {
|
|---|
| 24 | cerr << "\nSyntax:\n\t" << argv[0] << " <file name>\n" << endl;
|
|---|
| 25 | return EXIT_FAILURE;
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
| 28 | string fname(lexical_cast<string>(argv[1]));
|
|---|
| 29 |
|
|---|
| 30 | compressed_matrix<double> M(4,3);
|
|---|
| 31 |
|
|---|
| 32 | M(0,0) = 1.1;
|
|---|
| 33 | M(1,1) = 2.2;
|
|---|
| 34 |
|
|---|
| 35 | cout << "\nM =\n" << M << endl;
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 | ofstream ofs(fname.c_str(),ios::out | ios::binary);
|
|---|
| 39 |
|
|---|
| 40 | {
|
|---|
| 41 | boost::archive::binary_oarchive oa(ofs);
|
|---|
| 42 | oa << M;
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | ofs.close();
|
|---|
| 46 |
|
|---|
| 47 | M.clear();
|
|---|
| 48 |
|
|---|
| 49 | compressed_matrix<double> M2;
|
|---|
| 50 |
|
|---|
| 51 | ifstream ifs(fname.c_str(),ios::in | ios::binary);
|
|---|
| 52 |
|
|---|
| 53 | {
|
|---|
| 54 | boost::archive::binary_iarchive ia(ifs);
|
|---|
| 55 | ia >> M2;
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | ifs.close();
|
|---|
| 59 |
|
|---|
| 60 | cout << "\nre-read matrix:\n" << M2 << endl;
|
|---|
| 61 |
|
|---|
| 62 | cout << "\nDone.\n" << endl;
|
|---|
| 63 |
|
|---|
| 64 | return EXIT_SUCCESS;
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|