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){ |
11 |
|
this->info = info; |
12 |
|
|
13 |
|
//retrieve output filename of z force |
14 |
< |
data = info->getProperty(ZCONSFILENAME_ID); |
14 |
> |
data = info->getPropertyByName(ZCONSFILENAME_ID); |
15 |
|
if(!data) { |
16 |
|
|
17 |
|
|
40 |
|
|
41 |
|
} |
42 |
|
|
43 |
< |
istream = new ifstream(zconsFileName.c_str()); |
43 |
> |
istream = new std::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){ |
54 |
< |
istream = new ifstream(zconsFileName.c_str()); |
53 |
> |
ZConsReader::ZConsReader(const std::string& filename){ |
54 |
> |
istream = new std::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 |
|
|
103 |
– |
cout << line << endl; |
105 |
|
//skip the comment lines |
106 |
|
while(line[0] == '#') |
107 |
|
istream->getline(line, MAXBUFFERSIZE); |
109 |
|
sscanfCount = sscanf(line, "%d", &nZMol); |
110 |
|
|
111 |
|
if (sscanfCount != 1){ |
112 |
< |
cerr << "ZConsReader Error : reading file error" << endl; |
112 |
> |
std::cerr << "ZConsReader Error : reading file error" << std::endl; |
113 |
|
exit(1); |
114 |
|
} |
115 |
|
|
119 |
|
|
120 |
|
sscanfCount = sscanf(line, "%d\t%f", &zmolIndex, &zmolPos); |
121 |
|
if (sscanfCount != 2){ |
122 |
< |
cerr << "ZConsReader Error : reading file error" << endl; |
122 |
> |
std::cerr << "ZConsReader Error : reading file error" << std::endl; |
123 |
|
exit(1); |
124 |
|
} |
125 |
|
|
145 |
|
istream->getline(line, MAXBUFFERSIZE); |
146 |
|
sscanfCount = sscanf(line, "%f", &tempCurTime); |
147 |
|
if (sscanfCount != 1){ |
148 |
< |
cerr << "ZConsReader Error : reading file error" << endl; |
148 |
> |
std::cerr << "ZConsReader Error : reading file error" << std::endl; |
149 |
|
exit(1); |
150 |
|
} |
151 |
|
curTime = tempCurTime; |
153 |
|
istream->getline(line, MAXBUFFERSIZE); |
154 |
|
sscanfCount = sscanf(line, "%d", &tempNZMol); |
155 |
|
if (sscanfCount != 1){ |
156 |
< |
cerr << "ZConsReader Error : reading file error" << endl; |
156 |
> |
std::cerr << "ZConsReader Error : reading file error" << std::endl; |
157 |
|
exit(1); |
158 |
|
} |
159 |
|
|
160 |
|
if (tempNZMol != nZMol){ |
161 |
< |
cerr << "ZConsReader Error: reading file error" << endl; |
161 |
> |
std::cerr << "ZConsReader Error: reading file error" << std::endl; |
162 |
|
exit(1); |
163 |
|
} |
164 |
|
|
166 |
|
istream->getline(line, MAXBUFFERSIZE); |
167 |
|
sscanfCount = sscanf(line, "%d\t%f\t%f\t%f", &tempIndex, &tempFZ, &tempCurZPos,&tempZconsPos); |
168 |
|
if (sscanfCount != 4){ |
169 |
< |
cerr << "ZConsReader Error : reading file error" << endl; |
169 |
> |
std::cerr << "ZConsReader Error : reading file error" << std::endl; |
170 |
|
exit(1); |
171 |
|
} |
172 |
|
|
182 |
|
return istream->peek() != EOF ? true : false; |
183 |
|
} |
184 |
|
|
185 |
+ |
} |