ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/ZConsReader.cpp
Revision: 1074
Committed: Mon Mar 1 20:01:50 2004 UTC (20 years, 4 months ago) by tim
File size: 3481 byte(s)
Log Message:
Adding zsub, a program which can be used to replace atom type for zconstraint into OOPSE

File Contents

# Content
1 #include "ZConsReader.hpp"
2 #include "simError.h"
3
4 ZConsReader::ZConsReader(SimInfo* info)
5 :istream(NULL){
6
7 GenericData* data;
8 StringData* filename;
9
10 assert(info != NULL);
11
12 this->info = info;
13
14 //retrieve output filename of z force
15 data = info->getProperty(ZCONSFILENAME_ID);
16 if(!data) {
17
18
19 sprintf( painCave.errMsg,
20 "ZConsReader error: If you use an ZConstraint\n"
21 " , you must set output filename of z-force.\n");
22 painCave.isFatal = 1;
23 simError();
24
25 }
26 else{
27
28 filename = dynamic_cast<StringData*>(data);
29
30 if(!filename){
31
32 sprintf( painCave.errMsg,
33 "ZConsReader error: Can not get property from SimInfo\n");
34 painCave.isFatal = 1;
35 simError();
36
37 }
38 else{
39 zconsFileName = filename->getData();
40 }
41
42 }
43
44 istream = new ifstream(zconsFileName.c_str());
45
46 if (!istream){
47 cerr << "open " << filename << "error" << endl;
48 exit(1);
49 }
50
51 readHeader();
52 }
53
54 ZConsReader::~ZConsReader(){
55 istream->close();
56 }
57
58 int ZConsReader::getNumZMol(){
59 return nZMol;
60 }
61
62 vector<int> ZConsReader::getZConsIndex(){
63 return index;
64 }
65
66 vector<double> ZConsReader::getZConsPos(){
67 return zconsPos;
68 }
69
70 //double ZConsReader::getKRatio(){
71 // return kRatio;
72 //}
73
74 double ZConsReader::getCurTime(){
75 return curTime;
76 }
77
78 vector<double> ZConsReader::getCurZPos(){
79 return curZPos;
80 }
81
82 vector<double> ZConsReader::getCurFZ(){
83 return curFZ;
84 }
85
86 void ZConsReader::readHeader(){
87 const int MAXBUFFERSIZE = 2000;
88 char line[MAXBUFFERSIZE];
89 int zmolIndex;
90 float zmolPos;
91 int sscanfCount;
92
93 istream->getline(line, MAXBUFFERSIZE);
94
95 cout << line << endl;
96 //skip the comment lines
97 while(line[0] == '#')
98 istream->getline(line, MAXBUFFERSIZE);
99
100 sscanfCount = sscanf(line, "%d", &nZMol);
101
102 if (sscanfCount != 1){
103 cerr << "ZConsReader Error : reading file error" << endl;
104 exit(1);
105 }
106
107 for(int i = 0 ; i < nZMol; i++){
108
109 istream->getline(line, MAXBUFFERSIZE);
110
111 sscanfCount = sscanf(line, "%d\t%f", &zmolIndex, &zmolPos);
112 if (sscanfCount != 2){
113 cerr << "ZConsReader Error : reading file error" << endl;
114 exit(1);
115 }
116
117 index.push_back(zmolIndex);
118 zconsPos.push_back(zmolPos);
119 }
120
121 }
122
123 void ZConsReader::readNextFrame(){
124 const int MAXBUFFERSIZE = 2000;
125 char line[MAXBUFFERSIZE];
126 int tempNZMol;
127 int zmolIndex;
128 float zmolPos;
129 float zmolForce;
130 int sscanfCount;
131
132 istream->getline(line, MAXBUFFERSIZE);
133 sscanfCount = sscanf(line, "%f", curTime);
134 if (sscanfCount != 1){
135 cerr << "ZConsReader Error : reading file error" << endl;
136 exit(1);
137 }
138
139 istream->getline(line, MAXBUFFERSIZE);
140 sscanfCount = sscanf(line, "%d", &tempNZMol);
141 if (sscanfCount != 1){
142 cerr << "ZConsReader Error : reading file error" << endl;
143 exit(1);
144 }
145
146 if (tempNZMol != nZMol){
147 cerr << "ZConsReader Error: reading file error" << endl;
148 exit(1);
149 }
150
151 for(int i = 0; i < nZMol; i++){
152 istream->getline(line, MAXBUFFERSIZE);
153 sscanfCount = sscanf(line, "%d\t%f\t%f", &zmolIndex, &zmolForce, &zmolPos);
154 if (sscanfCount != 3){
155 cerr << "ZConsReader Error : reading file error" << endl;
156 exit(1);
157 }
158 }
159
160 }
161
162 bool ZConsReader::hasNextFrame(){
163 return istream->peek() != EOF ? true : false;
164 }
165

Properties

Name Value
svn:executable *