My Project
_dgbmatrix-io.hpp
1 //=============================================================================
3 inline double& _dgbmatrix::operator()(const long& i, const long& j) const
4 {
5 #ifdef CPPL_VERBOSE
6  std::cerr << "# [MARK] _dgbmatrix::operator()(const long&, const long&) const"
7  << std::endl;
8 #endif//CPPL_VERBOSE
9 
10 #ifdef CPPL_DEBUG
11  if( i<0 || j<0 || M<=i || N<=j || i-j>KL || j-i>KU ){
12  std::cerr << "[ERROR] _dgbmatrix::operator()(long, long)" << std::endl
13  << "The required component is out of the matrix size."
14  << std::endl
15  << "Your input was (" << i << "," << j << ")." << std::endl;
16  exit(1);
17  }
18 #endif//CPPL_DEBUG
19 
20  //return Array[KU+i+(KL+KU)*j];
21  return Darray[j][KU-j+i];
22 }
23 
27 
28 //=============================================================================
29 inline std::ostream& operator<<(std::ostream& s, const _dgbmatrix& mat)
30 {
31 #ifdef CPPL_VERBOSE
32  std::cerr << "# [MARK] operator<<(std::ostream&, const _dgbmatrix&)"
33  << std::endl;
34 #endif//CPPL_VERBOSE
35 
36  for(long i=0; i<mat.M; i++){
37  for(long j=0; j<mat.N; j++){
38  if( i-j>mat.KL || j-i>mat.KU ){ s << " x"; }
39  else{ s << " " << mat(i,j); }
40  }
41  s << std::endl;
42  }
43 
44  mat.destroy();
45  return s;
46 }
47 
51 
52 //=============================================================================
53 inline void _dgbmatrix::write(const char *filename) const
54 {
55 #ifdef CPPL_VERBOSE
56  std::cerr << "# [MARK] _dgbmatrix::write(const char*) const"
57  << std::endl;
58 #endif//CPPL_VERBOSE
59 
60  std::ofstream s(filename, std::ios::trunc);
61 
62  s << "dgbmatrix" << " "
63  << M << " " << N << " " << KL << " " << KU << std::endl;
64  for(long i=0; i<M; i++){
65  for(long j=max(0,i-KL); j<min(N,i+KU+1); j++){
66  s << operator()(i,j) << " ";
67  }
68  s << std::endl;
69  }
70 
71  s.close();
72  destroy();
73 }
double ** Darray
array of pointers of column head addresses
Definition: _dgbmatrix.hpp:12
friend _dgematrix i(const _dgbmatrix &)
Definition: _dgbmatrix-calc.hpp:23
long KL
lower band width
Definition: _dgbmatrix.hpp:9
long M
matrix row size
Definition: _dgbmatrix.hpp:7
void destroy() const
Definition: _dgbmatrix-misc.hpp:3
long N
matrix column size
Definition: _dgbmatrix.hpp:8
double & operator()(const long &, const long &) const
Definition: _dgbmatrix-io.hpp:3
(DO NOT USE) Smart-temporary Real Double-precision General Band Matrix Class
Definition: _dgbmatrix.hpp:3
long KU
upper band width
Definition: _dgbmatrix.hpp:10