My Project
zrovector-io.hpp
1 //=============================================================================
3 inline std::complex<double>& zrovector::operator()(const long& i)
4 {
5 #ifdef CPPL_VERBOSE
6  std::cerr << "# [MARK] zrovector::operator()(const long&)"
7  << std::endl;
8 #endif//CPPL_VERBOSE
9 
10 #ifdef CPPL_DEBUG
11  if( i<0 || L<=i ){
12  std::cerr << "[ERROR] zrovector::operator()(const long&)"
13  << std::endl
14  << "The required component is out of the vector size."
15  << std::endl
16  << "Your input was (" << i << ")." << std::endl;
17  exit(1);
18  }
19 #endif//CPPL_DEBUG
20 
21  return Array[i];
22 }
23 
24 //=============================================================================
26 inline std::complex<double> zrovector::operator()(const long& i) const
27 {
28 #ifdef CPPL_VERBOSE
29  std::cerr << "# [MARK] zrovector::operator()(const long&) const"
30  << std::endl;
31 #endif//CPPL_VERBOSE
32 
33 #ifdef CPPL_DEBUG
34  if( i<0 || L<=i ){
35  std::cerr << "[ERROR] zrovector::operator()(const long&) const"
36  << std::endl
37  << "The required component is out of the vector size."
38  << std::endl
39  << "Your input was (" << i << ")." << std::endl;
40  exit(1);
41  }
42 #endif//CPPL_DEBUG
43 
44  return Array[i];
45 }
46 
50 
51 //=============================================================================
53 inline void zrovector::set(const long& i, const std::complex<double>& v) const
54 {
55 #ifdef CPPL_VERBOSE
56  std::cerr << "# [MARK] zrovector::set(const long&, const std::complex<double>&) const"
57  << std::endl;
58 #endif//CPPL_VERBOSE
59 
60 #ifdef CPPL_DEBUG
61  if( i<0 || L<=i ){
62  std::cerr << "[ERROR] zrovector::set(const long&, const std::complex<double>&) const"
63  << std::endl
64  << "The required component is out of the vector size."
65  << std::endl
66  << "Your input was (" << i << ")." << std::endl;
67  exit(1);
68  }
69 #endif//CPPL_DEBUG
70 
71  Array[i] =v;
72 }
73 
77 
78 //=============================================================================
79 inline std::ostream& operator<<(std::ostream& s, const zrovector& vec)
80 {
81 #ifdef CPPL_VERBOSE
82  std::cerr << "# [MARK] operator<<(std::ostream&, const zrovector&)"
83  << std::endl;
84 #endif//CPPL_VERBOSE
85 
86  for(long i=0; i<vec.L; i++){ s << " " << vec.Array[i]; }
87  s << std::endl;
88 
89  return s;
90 }
91 
95 
96 //=============================================================================
97 inline void zrovector::write(const char* filename) const
98 {
99 #ifdef CPPL_VERBOSE
100  std::cerr << "# [MARK] zrovector::write(const char*) const"
101  << std::endl;
102 #endif//CPPL_VERBOSE
103 
104  std::ofstream s(filename, std::ios::trunc);
105 
106  s << "zrovector" << " " << L << std::endl;
107  for(long i=0; i<L; i++){
108  s << operator()(i) << " ";
109  }
110  s << std::endl;
111 
112  s.close();
113 }
114 
115 //=============================================================================
116 inline void zrovector::read(const char* filename)
117 {
118 #ifdef CPPL_VERBOSE
119  std::cerr << "# [MARK] zrovector::read(const char*)"
120  << std::endl;
121 #endif//CPPL_VERBOSE
122 
123  std::ifstream s( filename );
124  if(!s){
125  std::cerr << "[ERROR] zrovector::read(const char*) " << std::endl
126  << "The file \"" << filename << "\" can not be opened."
127  << std::endl;
128  exit(1);
129  }
130 
131  std::string id;
132  s >> id;
133  if( id != "zrovector" ){
134  std::cerr << "[ERROR] zrovector::read(const char*) " << std::endl
135  << "The type name of the file \"" << filename
136  << "\" is not zrovector." << std::endl
137  << "Its type name was " << id << " ." << std::endl;
138  exit(1);
139  }
140 
141  s >> L;
142  resize(L);
143  for(long i=0; i<L; i++){
144  s >> operator()(i);
145  }
146  if(s.eof()){
147  std::cerr << "[ERROR] zrovector::read(const char*) " << std::endl
148  << "There is something is wrong with the file \""
149  << filename << " ." << std::endl
150  << "Most likely, there is not enough data components, "
151  << "or a linefeed code or space code is missing "
152  << "at the end of the last line." << std::endl;
153  exit(1);
154  }
155 
156  s.close();
157 }
long L
vector size
Definition: _zrovector.hpp:7
std::complex< double > & operator()(const long &)
Definition: zrovector-io.hpp:3
Complex Double-precision Row Vector Class.
Definition: zrovector.hpp:3
void resize(const long &)
Definition: zrovector-misc.hpp:93
void set(const long &, const std::complex< double > &) const
Definition: zrovector-io.hpp:53
std::complex< double > * Array
1D Array to store vector data
Definition: _zrovector.hpp:8