VERB_code_2.3
dcovector-io.hpp
1 //=============================================================================
3 inline double& dcovector::operator()(const long& i)
4 {
5 #ifdef CPPL_VERBOSE
6  std::cerr << "# [MARK] dcovector::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] dcovector::operator()(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 double dcovector::operator()(const long& i) const
27 {
28 #ifdef CPPL_VERBOSE
29  std::cerr << "# [MARK] dcovector::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] dcovector::operator()(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 dcovector::set(const long& i, const double& v) const
54 {
55 #ifdef CPPL_VERBOSE
56  std::cerr << "# [MARK] dcovector::set(const long&, const double&) const"
57  << std::endl;
58 #endif//CPPL_VERBOSE
59 
60 #ifdef CPPL_DEBUG
61  if( i<0 || L<=i ){
62  std::cerr << "[ERROR] dcovector::set(long&, 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 dcovector& vec)
80 {
81 #ifdef CPPL_VERBOSE
82  std::cerr << "# [MARK] operator<<(std::ostream&, const dcovector&)"
83  << std::endl;
84 #endif//CPPL_VERBOSE
85 
86  for(long i=0; i<vec.L; i++){
87  s << " " << vec.Array[i] << std::endl;
88  }
89 
90  return s;
91 }
92 
96 
97 //=============================================================================
98 inline void dcovector::write(const char *filename) const
99 {
100 #ifdef CPPL_VERBOSE
101  std::cerr << "# [MARK] dcovector::write(const char*) const"
102  << std::endl;
103 #endif//CPPL_VERBOSE
104 
105  std::ofstream s(filename, std::ios::trunc);
106 
107  s << "dcovector" << " " << L << std::endl;
108  for(long i=0; i<L; i++){
109  s << operator()(i) << std::endl;
110  }
111 
112  s.close();
113 }
114 
115 //=============================================================================
116 inline void dcovector::read(const char *filename)
117 {
118 #ifdef CPPL_VERBOSE
119  std::cerr << "# [MARK] dcovector::read(const char*)"
120  << std::endl;
121 #endif//CPPL_VERBOSE
122 
123  std::ifstream s(filename);
124  if(!s){
125  std::cerr << "[ERROR] dcovector::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 != "dcovector" ){
134  std::cerr << "[ERROR] dcovector::read(const char*) " << std::endl
135  << "The type name of the file \"" << filename
136  << "\" is not dcovector." << 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++) { s >> operator()(i); }
144  if(s.eof()){
145  std::cerr << "[ERROR] dcovector::read(const char*) " << std::endl
146  << "There is something is wrong with the file \""
147  << filename << " ." << std::endl
148  << "Most likely, there is not enough data components, "
149  << "or a linefeed code or space code is missing "
150  << "at the end of the last line." << std::endl;
151  exit(1);
152  }
153 
154  s.close();
155 }
void resize(const long &)
Definition: dcovector-misc.hpp:93
void set(const long &, const double &) const
Definition: dcovector-io.hpp:53
double & operator()(const long &)
Definition: dcovector-io.hpp:3
Real Double-precision Column Vector Class.
Definition: dcovector.hpp:3