CPPLapack
 All Classes Files Functions Variables Friends Pages
zgbmatrix-io.hpp
Go to the documentation of this file.
1 //=============================================================================
2 /*! operator() for non-const object */
3 inline comple& zgbmatrix::operator()(const CPPL_INT& i, const CPPL_INT& j)
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 << "x" << n << " with kl=" << kl << ", ku=" << 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 /*! operator() for const object */
20 inline comple zgbmatrix::operator()(const CPPL_INT& i, const CPPL_INT& j) const
21 {CPPL_VERBOSE_REPORT;
22 #ifdef CPPL_DEBUG
23  if( i<0 || j<0 || m<=i || n<=j || i-j>kl || j-i>ku ){
24  ERROR_REPORT;
25  std::cerr << "The required component is out of the matrix size." << std::endl
26  << "Your input is (" << i << "," << j << "), whereas the matrix size is " << m << "x" << n << " with kl=" << kl << ", ku=" << ku << "." << std::endl;
27  exit(1);
28  }
29 #endif//CPPL_DEBUG
30 
31  //return array[ku+i+(kl+ku)*j];
32  return darray[j][ku-j+i];
33 }
34 
35 ///////////////////////////////////////////////////////////////////////////////
36 ///////////////////////////////////////////////////////////////////////////////
37 ///////////////////////////////////////////////////////////////////////////////
38 
39 //=============================================================================
40 /*! set value for const object */
41 inline zgbmatrix& zgbmatrix::set(const CPPL_INT& i, const CPPL_INT& j, const comple& v)
42 {CPPL_VERBOSE_REPORT;
43 #ifdef CPPL_DEBUG
44  if( i<0 || j<0 || m<=i || n<=j || i-j>kl || j-i>ku ){
45  ERROR_REPORT;
46  std::cerr << "The required component is out of the matrix size." << std::endl
47  << "Your input is (" << i << "," << j << "), whereas the matrix size is " << m << "x" << n << " with kl=" << kl << ", ku=" << ku << "." << std::endl;
48  exit(1);
49  }
50 #endif//CPPL_DEBUG
51 
52  //array[ku+i+(kl+ku)*j] =v;
53  darray[j][ku-j+i] =v;
54 
55  return *this;
56 }
57 
58 ///////////////////////////////////////////////////////////////////////////////
59 ///////////////////////////////////////////////////////////////////////////////
60 ///////////////////////////////////////////////////////////////////////////////
61 
62 //=============================================================================
63 inline std::ostream& operator<<(std::ostream& s, const zgbmatrix& mat)
64 {CPPL_VERBOSE_REPORT;
65  for(CPPL_INT i=0; i<mat.m; i++){
66  for(CPPL_INT j=0; j<mat.n; j++){
67  if( i-j>mat.kl || j-i>mat.ku ){ s << " x"; }
68  else{ s << " " << mat(i,j); }
69  }
70  s << std::endl;
71  }
72 
73  return s;
74 }
75 
76 ///////////////////////////////////////////////////////////////////////////////
77 ///////////////////////////////////////////////////////////////////////////////
78 ///////////////////////////////////////////////////////////////////////////////
79 
80 //=============================================================================
81 inline void zgbmatrix::write(const char* filename) const
82 {CPPL_VERBOSE_REPORT;
83  std::ofstream ofs(filename, std::ios::trunc);
84  ofs.setf(std::cout.flags());
85  ofs.precision(std::cout.precision());
86  ofs.width(std::cout.width());
87  ofs.fill(std::cout.fill());
88 
89  ofs << "#zgbmatrix" << " " << m << " " << n << " " << kl << " " << ku << std::endl;
90  for(CPPL_INT i=0; i<m; i++){
91  const CPPL_INT jmax =std::min(n,i+ku+1);
92  for(CPPL_INT j=std::max(CPPL_INT(0),i-kl); j<jmax; j++){
93  ofs << operator()(i,j) << " ";
94  }
95  ofs << std::endl;
96  }
97 
98  ofs.close();
99 }
100 
101 //=============================================================================
102 inline void zgbmatrix::read(const char* filename)
103 {CPPL_VERBOSE_REPORT;
104  std::ifstream s( filename );
105  if(!s){
106  ERROR_REPORT;
107  std::cerr << "The file \"" << filename << "\" can not be opened." << std::endl;
108  exit(1);
109  }
110 
111  std::string id;
112  s >> id;
113  if( id != "zgbmatrix" && id != "#zgbmatrix" ){
114  ERROR_REPORT;
115  std::cerr << "The type name of the file \"" << filename << "\" is not zgbmatrix." << std::endl
116  << "Its type name was " << id << " ." << std::endl;
117  exit(1);
118  }
119 
120  s >> m >> n >> kl >> ku;
121  resize(m, n, kl, ku);
122  for(CPPL_INT i=0; i<m; i++){
123  const CPPL_INT jmax =std::min(n,i+ku+1);
124  for(CPPL_INT j=std::max(CPPL_INT(0),i-kl); j<jmax; j++){
125  s >> operator()(i,j);
126  }
127  }
128  if(s.eof()){
129  ERROR_REPORT;
130  std::cerr << "There is something is wrong with the file \"" << filename << "\"." << std::endl
131  << "Most likely, there is not enough data components, or a linefeed code or space code is missing at the end of the last line." << std::endl;
132  exit(1);
133  }
134 
135  s >> id;
136  if(!s.eof()){
137  ERROR_REPORT;
138  std::cerr << "There is something is wrong with the file \"" << filename << "\"." << std::endl
139  << "Most likely, there are extra data components." << std::endl;
140  exit(1);
141  }
142 
143  s.close();
144 }
void read(const char *)
comple & operator()(const CPPL_INT &, const CPPL_INT &)
Definition: zgbmatrix-io.hpp:3
std::ostream & operator<<(std::ostream &s, const zgbmatrix &mat)
friend _zgematrix i(const zgbmatrix &)
zgbmatrix & set(const CPPL_INT &, const CPPL_INT &, const comple &)
comple ** darray
array of pointers of column head addresses
Definition: zgbmatrix.hpp:14
_dgematrix i(const _dgbmatrix &mat)
CPPL_INT n
matrix column size
Definition: zgbmatrix.hpp:10
CPPL_INT ku
upper band width
Definition: zgbmatrix.hpp:12
void resize(const CPPL_INT &, const CPPL_INT &, const CPPL_INT &, const CPPL_INT &)
CPPL_INT m
matrix row size
Definition: zgbmatrix.hpp:9
Complex Double-precision General Band Matrix Class.
Definition: zgbmatrix.hpp:3
void write(const char *) const
CPPL_INT kl
lower band width
Definition: zgbmatrix.hpp:11