CPPLapack
 All Classes Files Functions Variables Friends Pages
_dgbmatrix-io.hpp
Go to the documentation of this file.
1 //=============================================================================
2 /*! operator() for const object */
3 inline double& _dgbmatrix::operator()(const CPPL_INT& i, const CPPL_INT& j) const
4 {CPPL_VERBOSE_REPORT;
5 #ifdef CPPL_DEBUG
6  if( i<0 || j<0 || m<=i || n<=j || i-j>kl || j-i>ku ){
7  ERROR_REPORT;
8  std::cerr << "The required component is out of the matrix size." << std::endl
9  << "Your input is (" << i << "," << j << "), whereas the matrix size is (" << m << "," << n << " , " << kl << "," << ku << ")." << std::endl;
10  exit(1);
11  }
12 #endif//CPPL_DEBUG
13 
14  //return array[ku+i+(kl+ku)*j];
15  return darray[j][ku-j+i];
16 }
17 
18 ///////////////////////////////////////////////////////////////////////////////
19 ///////////////////////////////////////////////////////////////////////////////
20 ///////////////////////////////////////////////////////////////////////////////
21 
22 //=============================================================================
23 inline std::ostream& operator<<(std::ostream& s, const _dgbmatrix& mat)
24 {CPPL_VERBOSE_REPORT;
25  for(CPPL_INT i=0; i<mat.m; i++){
26  for(CPPL_INT j=0; j<mat.n; j++){
27  if( i-j>mat.kl || j-i>mat.ku ){ s << " x"; }
28  else{ s << " " << mat(i,j); }
29  }
30  s << std::endl;
31  }
32 
33  mat.destroy();
34  return s;
35 }
36 
37 ///////////////////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////////////////
39 ///////////////////////////////////////////////////////////////////////////////
40 
41 //=============================================================================
42 inline void _dgbmatrix::write(const char *filename) const
43 {CPPL_VERBOSE_REPORT;
44  std::ofstream ofs(filename, std::ios::trunc);
45  ofs.setf(std::cout.flags());
46  ofs.precision(std::cout.precision());
47  ofs.width(std::cout.width());
48  ofs.fill(std::cout.fill());
49 
50  ofs << "#dgbmatrix" << " " << m << " " << n << " " << kl << " " << ku << std::endl;
51  for(CPPL_INT i=0; i<m; i++){
52  const CPPL_INT jmax =std::min(n,i+ku+1);
53  for(CPPL_INT j=std::max(CPPL_INT(0),i-kl); j<jmax; j++){
54  ofs << operator()(i,j) << " ";
55  }
56  ofs << std::endl;
57  }
58 
59  ofs.close();
60  destroy();
61 }
friend _dgematrix i(const _dgbmatrix &)
double ** darray
array of pointers of column head addresses
Definition: _dgbmatrix.hpp:14
CPPL_INT ku
upper band width
Definition: _dgbmatrix.hpp:12
std::ostream & operator<<(std::ostream &s, const _dgbmatrix &mat)
void destroy() const
_dgematrix i(const _dgbmatrix &mat)
CPPL_INT kl
lower band width
Definition: _dgbmatrix.hpp:11
CPPL_INT n
matrix column size
Definition: _dgbmatrix.hpp:10
double & operator()(const CPPL_INT &, const CPPL_INT &) const
void write(const char *) const
(DO NOT USE) Smart-temporary Real Double-precision General Band Matrix Class
Definition: _dgbmatrix.hpp:3
CPPL_INT m
matrix row size
Definition: _dgbmatrix.hpp:9