33 #ifndef CONNECTION_VIEWER_IO_H
34 #define CONNECTION_VIEWER_IO_H
46 namespace ConnectionViewer{
48 template<
typename matrix_type>
51 std::cout <<
" Reading matrix from " << filename <<
"... ";
52 std::fstream matfile(filename.c_str(), std::ios::in);
53 if(matfile.is_open() ==
false) { std::cout <<
"failed.\n";
return false; }
55 int version=-1, gridsize=-1;
63 assert(dimension == 2 || dimension == 3);
64 assert(gridsize != -1);
66 std::cout <<
"v=" << version <<
" dim=" << dimension <<
" size=" << gridsize;
67 PROGRESS_START(prog, gridsize*2,
"ReadMatrix " << dimension <<
"d from " << filename <<
" , " << gridsize <<
" x " << gridsize);
68 grid.resize(gridsize);
69 for(
int i=0; i<gridsize; i++)
75 std::cout <<
" failed.\n";
79 matfile >> grid[i].x() >> grid[i].y();
80 if(dimension==3) matfile >> grid[i].z();
84 int printStringsInWindow;
85 matfile >> printStringsInWindow;
87 matrix.resize_and_clear(gridsize, gridsize);
88 bool bEOF = matfile.eof();
92 int from, to;
double value;
93 char c = matfile.peek();
94 if(c == -1 || c ==
'c' || c ==
'v' || matfile.eof())
97 matfile >> from >> to >> value;
99 matrix(from, to) = value;
102 bEOF = matfile.eof();
109 template<
typename vector_type>
113 std::cout <<
" Reading std::vector from " << filename <<
"... ";
114 std::fstream matfile(filename.c_str(), std::ios::in);
115 if(matfile.is_open() ==
false) { std::cout <<
"failed.\n";
return false; }
117 int version=-1, gridsize=-1, dimension=-1;
120 matfile >> dimension;
123 assert(version == 1);
124 assert(dimension == 2 || dimension == 3);
125 assert(gridsize != -1);
127 PROGRESS_START(prog, gridsize*2,
"ReadVector " << dimension <<
"d from " << filename <<
" , " << gridsize <<
" x " << gridsize);
128 for(
int i=0; i<gridsize; i++)
133 std::cout <<
" failed.\n";
139 if(dimension==3) matfile >> z;
142 int printStringsInWindow;
143 matfile >> printStringsInWindow;
145 vec.resize(gridsize);
146 bool bEOF = matfile.eof();
149 int from, to;
double value;
150 char c = matfile.peek();
151 if(c == -1 || c ==
'c' || c ==
'v' || matfile.eof())
154 matfile >> from >> to >> value;
158 bEOF = matfile.eof();
a mathematical Vector with N entries.
Definition: math_vector.h:97
Wrapper for sequential matrices to handle them in parallel.
Definition: parallel_matrix.h:65
Definition: progress.h:50
bool ReadVector(std::string filename, vector_type &vec)
Definition: connection_viewer_input.h:110
bool ReadMatrix(std::string filename, matrix_type &matrix, std::vector< MathVector< 3 > > &grid, int &dimension)
Definition: connection_viewer_input.h:49
CPUAlgebra::vector_type vector_type
#define PROGRESS_START(progVarName, dSize, msg)
Definition: progress.h:111
#define PROGRESS_UPDATE(progVarName, d)
Definition: progress.h:117