ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/ZConsReader.cpp
Revision: 1108
Committed: Wed Apr 14 15:37:41 2004 UTC (20 years, 4 months ago) by tim
File size: 3745 byte(s)
Log Message:
Change DumpWriter and InitFromFile

File Contents

# User Rev Content
1 tim 1074 #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 tim 1108 curZPos.resize(nZMol);
122     curFZ.resize(nZMol);
123 tim 1074 }
124    
125     void ZConsReader::readNextFrame(){
126     const int MAXBUFFERSIZE = 2000;
127     char line[MAXBUFFERSIZE];
128     int tempNZMol;
129     int sscanfCount;
130 tim 1108 int tempIndex;
131     float tempCurTime;
132     float tempFZ;
133     float tempCurZPos;
134     float tempZconsPos;
135    
136 tim 1074 istream->getline(line, MAXBUFFERSIZE);
137 tim 1108 sscanfCount = sscanf(line, "%f", &tempCurTime);
138 tim 1074 if (sscanfCount != 1){
139     cerr << "ZConsReader Error : reading file error" << endl;
140     exit(1);
141     }
142 tim 1108 curTime = tempCurTime;
143 tim 1074
144     istream->getline(line, MAXBUFFERSIZE);
145     sscanfCount = sscanf(line, "%d", &tempNZMol);
146     if (sscanfCount != 1){
147     cerr << "ZConsReader Error : reading file error" << endl;
148     exit(1);
149     }
150    
151     if (tempNZMol != nZMol){
152     cerr << "ZConsReader Error: reading file error" << endl;
153     exit(1);
154     }
155    
156     for(int i = 0; i < nZMol; i++){
157     istream->getline(line, MAXBUFFERSIZE);
158 tim 1108 sscanfCount = sscanf(line, "%d\t%f\t%f\t%f", &tempIndex, &tempFZ, &tempCurZPos,&tempZconsPos);
159     if (sscanfCount != 4){
160 tim 1074 cerr << "ZConsReader Error : reading file error" << endl;
161     exit(1);
162     }
163 tim 1108
164     index[i] = tempIndex;
165     curFZ[i] = tempFZ;
166     curZPos[i]= tempCurZPos;
167     zconsPos[i] = tempZconsPos;
168 tim 1074 }
169    
170     }
171    
172     bool ZConsReader::hasNextFrame(){
173     return istream->peek() != EOF ? true : false;
174     }
175    

Properties

Name Value
svn:executable *