CPPLapack
 All Classes Files Functions Variables Friends Pages
zrovector-io.hpp
Go to the documentation of this file.
1 //=============================================================================
2 /*! operator() for non-const object */
3 inline comple& zrovector::operator()(const CPPL_INT& i)
4 {CPPL_VERBOSE_REPORT;
5 #ifdef CPPL_DEBUG
6  if( i<0 || l<=i ){
7  ERROR_REPORT;
8  std::cerr << "The required component is out of the vector size." << std::endl
9  << "Your input is (" << i << "), whereas the vector size is " << l << "." << std::endl;
10  exit(1);
11  }
12 #endif//CPPL_DEBUG
13 
14  return array[i];
15 }
16 
17 //=============================================================================
18 /*! operator() for const object */
19 inline comple zrovector::operator()(const CPPL_INT& i) const
20 {CPPL_VERBOSE_REPORT;
21 #ifdef CPPL_DEBUG
22  if( i<0 || l<=i ){
23  ERROR_REPORT;
24  std::cerr << "The required component is out of the vector size." << std::endl
25  << "Your input is (" << i << "), whereas the vector size is " << l << "." << std::endl;
26  exit(1);
27  }
28 #endif//CPPL_DEBUG
29 
30  return array[i];
31 }
32 
33 ///////////////////////////////////////////////////////////////////////////////
34 ///////////////////////////////////////////////////////////////////////////////
35 ///////////////////////////////////////////////////////////////////////////////
36 
37 //=============================================================================
38 /*! set value for const object */
39 inline zrovector& zrovector::set(const CPPL_INT& i, const comple& v) //const
40 {CPPL_VERBOSE_REPORT;
41 #ifdef CPPL_DEBUG
42  if( i<0 || l<=i ){
43  ERROR_REPORT;
44  std::cerr << "The required component is out of the vector size." << std::endl
45  << "Your input is (" << i << "), whereas the vector size is " << l << "." << std::endl;
46  exit(1);
47  }
48 #endif//CPPL_DEBUG
49 
50  array[i] =v;
51  return *this;
52 }
53 
54 ///////////////////////////////////////////////////////////////////////////////
55 ///////////////////////////////////////////////////////////////////////////////
56 ///////////////////////////////////////////////////////////////////////////////
57 
58 //=============================================================================
59 inline std::ostream& operator<<(std::ostream& s, const zrovector& vec)
60 {CPPL_VERBOSE_REPORT;
61  for(CPPL_INT i=0; i<vec.l; i++){ s << " " << vec.array[i]; }
62  s << std::endl;
63 
64  return s;
65 }
66 
67 ///////////////////////////////////////////////////////////////////////////////
68 ///////////////////////////////////////////////////////////////////////////////
69 ///////////////////////////////////////////////////////////////////////////////
70 
71 //=============================================================================
72 inline void zrovector::write(const char* filename) const
73 {CPPL_VERBOSE_REPORT;
74  std::ofstream ofs(filename, std::ios::trunc);
75  ofs.setf(std::cout.flags());
76  ofs.precision(std::cout.precision());
77  ofs.width(std::cout.width());
78  ofs.fill(std::cout.fill());
79 
80  ofs << "#zrovector" << " " << l << std::endl;
81  for(CPPL_INT i=0; i<l; i++){
82  ofs << operator()(i) << " ";
83  }
84  ofs << std::endl;
85 
86  ofs.close();
87 }
88 
89 //=============================================================================
90 inline void zrovector::read(const char* filename)
91 {CPPL_VERBOSE_REPORT;
92  std::ifstream s( filename );
93  if(!s){
94  ERROR_REPORT;
95  std::cerr << "The file \"" << filename << "\" can not be opened." << std::endl;
96  exit(1);
97  }
98 
99  std::string id;
100  s >> id;
101  if( id != "zrovector" && id != "#zrovector" ){
102  ERROR_REPORT;
103  std::cerr << "The type name of the file \"" << filename << "\" is not zrovector." << std::endl
104  << "Its type name was " << id << " ." << std::endl;
105  exit(1);
106  }
107 
108  s >> l;
109  resize(l);
110  for(CPPL_INT i=0; i<l; i++){
111  s >> operator()(i);
112  }
113  if(s.eof()){
114  ERROR_REPORT;
115  std::cerr << "There is something is wrong with the file \"" << filename << "\"." << std::endl
116  << "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;
117  exit(1);
118  }
119 
120  s >> id;
121  if(!s.eof()){
122  ERROR_REPORT;
123  std::cerr << "There is something is wrong with the file \"" << filename << "\"." << std::endl
124  << "Most likely, there are extra data components." << std::endl;
125  exit(1);
126  }
127 
128 
129  s.close();
130 }
std::ostream & operator<<(std::ostream &s, const zrovector &vec)
CPPL_INT l
vector size
Definition: zrovector.hpp:9
void read(const char *)
void resize(const CPPL_INT &)
_dgematrix i(const _dgbmatrix &mat)
Complex Double-precision Row Vector Class.
Definition: zrovector.hpp:3
comple & operator()(const CPPL_INT &)
Definition: zrovector-io.hpp:3
zrovector & set(const CPPL_INT &, const comple &)
void write(const char *) const
comple * array
1D array to store vector data
Definition: zrovector.hpp:10