1 |
+ |
#include "constraints/ZconsData.hpp" |
2 |
|
#include "io/ZConsReader.hpp" |
3 |
|
#include "utils/simError.h" |
4 |
+ |
namespace oopse { |
5 |
|
|
6 |
|
ZConsReader::ZConsReader(SimInfo* info) |
7 |
|
:istream(NULL){ |
43 |
|
istream = new ifstream(zconsFileName.c_str()); |
44 |
|
|
45 |
|
if (!istream){ |
46 |
< |
cerr << "open " << filename << "error" << endl; |
46 |
> |
std::cerr << "open " << filename << "error" << std::endl; |
47 |
|
exit(1); |
48 |
|
} |
49 |
|
|
50 |
|
readHeader(); |
51 |
|
} |
52 |
|
|
53 |
< |
ZConsReader::ZConsReader(const string& filename){ |
53 |
> |
ZConsReader::ZConsReader(const std::string& filename){ |
54 |
|
istream = new ifstream(zconsFileName.c_str()); |
55 |
|
|
56 |
|
if (!istream){ |
57 |
< |
cerr << "open " << filename << "error" << endl; |
57 |
> |
std::cerr << "open " << filename << "error" << std::endl; |
58 |
|
exit(1); |
59 |
|
} |
60 |
|
|
69 |
|
return nZMol; |
70 |
|
} |
71 |
|
|
72 |
< |
vector<int> ZConsReader::getZConsIndex(){ |
72 |
> |
std::vector<int> ZConsReader::getZConsIndex(){ |
73 |
|
return index; |
74 |
|
} |
75 |
|
|
76 |
< |
vector<double> ZConsReader::getZConsPos(){ |
76 |
> |
std::vector<double> ZConsReader::getZConsPos(){ |
77 |
|
return zconsPos; |
78 |
|
} |
79 |
|
|
85 |
|
return curTime; |
86 |
|
} |
87 |
|
|
88 |
< |
vector<double> ZConsReader::getCurZPos(){ |
88 |
> |
std::vector<double> ZConsReader::getCurZPos(){ |
89 |
|
return curZPos; |
90 |
|
} |
91 |
|
|
92 |
< |
vector<double> ZConsReader::getCurFZ(){ |
92 |
> |
std::vector<double> ZConsReader::getCurFZ(){ |
93 |
|
return curFZ; |
94 |
|
} |
95 |
|
|
102 |
|
|
103 |
|
istream->getline(line, MAXBUFFERSIZE); |
104 |
|
|
105 |
< |
cout << line << endl; |
105 |
> |
cout << line << std::endl; |
106 |
|
//skip the comment lines |
107 |
|
while(line[0] == '#') |
108 |
|
istream->getline(line, MAXBUFFERSIZE); |
110 |
|
sscanfCount = sscanf(line, "%d", &nZMol); |
111 |
|
|
112 |
|
if (sscanfCount != 1){ |
113 |
< |
cerr << "ZConsReader Error : reading file error" << endl; |
113 |
> |
std::cerr << "ZConsReader Error : reading file error" << std::endl; |
114 |
|
exit(1); |
115 |
|
} |
116 |
|
|
120 |
|
|
121 |
|
sscanfCount = sscanf(line, "%d\t%f", &zmolIndex, &zmolPos); |
122 |
|
if (sscanfCount != 2){ |
123 |
< |
cerr << "ZConsReader Error : reading file error" << endl; |
123 |
> |
std::cerr << "ZConsReader Error : reading file error" << std::endl; |
124 |
|
exit(1); |
125 |
|
} |
126 |
|
|
146 |
|
istream->getline(line, MAXBUFFERSIZE); |
147 |
|
sscanfCount = sscanf(line, "%f", &tempCurTime); |
148 |
|
if (sscanfCount != 1){ |
149 |
< |
cerr << "ZConsReader Error : reading file error" << endl; |
149 |
> |
std::cerr << "ZConsReader Error : reading file error" << std::endl; |
150 |
|
exit(1); |
151 |
|
} |
152 |
|
curTime = tempCurTime; |
154 |
|
istream->getline(line, MAXBUFFERSIZE); |
155 |
|
sscanfCount = sscanf(line, "%d", &tempNZMol); |
156 |
|
if (sscanfCount != 1){ |
157 |
< |
cerr << "ZConsReader Error : reading file error" << endl; |
157 |
> |
std::cerr << "ZConsReader Error : reading file error" << std::endl; |
158 |
|
exit(1); |
159 |
|
} |
160 |
|
|
161 |
|
if (tempNZMol != nZMol){ |
162 |
< |
cerr << "ZConsReader Error: reading file error" << endl; |
162 |
> |
std::cerr << "ZConsReader Error: reading file error" << std::endl; |
163 |
|
exit(1); |
164 |
|
} |
165 |
|
|
167 |
|
istream->getline(line, MAXBUFFERSIZE); |
168 |
|
sscanfCount = sscanf(line, "%d\t%f\t%f\t%f", &tempIndex, &tempFZ, &tempCurZPos,&tempZconsPos); |
169 |
|
if (sscanfCount != 4){ |
170 |
< |
cerr << "ZConsReader Error : reading file error" << endl; |
170 |
> |
std::cerr << "ZConsReader Error : reading file error" << std::endl; |
171 |
|
exit(1); |
172 |
|
} |
173 |
|
|
183 |
|
return istream->peek() != EOF ? true : false; |
184 |
|
} |
185 |
|
|
186 |
+ |
} |