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