59 |
|
|
60 |
|
int i; // loop counter |
61 |
|
|
62 |
+ |
const int BUFFERSIZE = 2000; // size of the read buffer |
63 |
|
int n_atoms; // the number of atoms |
64 |
< |
char read_buffer[2000]; //the line buffer for reading |
64 |
> |
char read_buffer[BUFFERSIZE]; //the line buffer for reading |
65 |
|
#ifdef IS_MPI |
66 |
< |
char send_buffer[2000]; |
66 |
> |
char send_buffer[BUFFERSIZE]; |
67 |
|
#endif |
68 |
|
|
69 |
|
char *eof_test; // ptr to see when we reach the end of the file |
70 |
< |
char *foo; // the pointer to the current string token |
70 |
> |
char *parseErr; |
71 |
|
|
71 |
– |
double rx, ry, rz; // position place holders |
72 |
– |
double vx, vy, vz; // velocity placeholders |
73 |
– |
double q[4]; // the quaternions |
74 |
– |
double jx, jy, jz; // angular velocity placeholders; |
75 |
– |
double qSqr, qLength; // needed to normalize the quaternion vector. |
72 |
|
|
73 |
|
entry_plug = the_entry_plug |
74 |
|
|
76 |
|
#ifndef IS_MPI |
77 |
|
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
78 |
|
if( eof_test == NULL ){ |
79 |
< |
std::cerr << "error reading 1st line of" << c_in_name << "\n"; |
79 |
> |
sprintf( painCave.errMsg, |
80 |
> |
"InitializeFromFile error: error reading 1st line of \"%s\"\n", |
81 |
> |
c_in_name ); |
82 |
> |
painCave.isFatal = 1; |
83 |
> |
simError(); |
84 |
|
} |
85 |
|
|
86 |
< |
(void)sscanf(read_buffer, "%d", &n_atoms); |
86 |
> |
n_atoms = atoi( read_buffer ); |
87 |
|
|
88 |
|
Atom **atoms = entry_plug->atoms; |
89 |
|
DirectionalAtom* dAtom; |
120 |
|
simError(); |
121 |
|
} |
122 |
|
|
123 |
– |
foo = strtok(read_buffer, " ,;\t"); |
123 |
|
|
124 |
< |
// check the atom name to the current atom |
125 |
< |
|
126 |
< |
if( strcmp( foo, atoms[i]->getType() ) ){ |
128 |
< |
sprintf( painCave.errMsg, |
129 |
< |
"Initialize from file error. Atom %s at index %d " |
130 |
< |
"in file %s does not" |
131 |
< |
" match the BASS atom %s.\n", |
132 |
< |
foo, i, c_in_name, atoms[i]->getType() ); |
124 |
> |
parseErr = parseDumpLine( read_buffer, i ); |
125 |
> |
if( parseErr != NULL ){ |
126 |
> |
strcpy( painCave.errMsg, parseErr ); |
127 |
|
painCave.isFatal = 1; |
128 |
|
simError(); |
129 |
< |
} |
136 |
< |
|
137 |
< |
// get the positions |
138 |
< |
|
139 |
< |
foo = strtok(NULL, " ,;\t"); |
140 |
< |
if(foo == NULL){ |
141 |
< |
sprintf( painCave.errMsg, |
142 |
< |
"error in reading postition x from %s\n" |
143 |
< |
"natoms = %d, index = %d\n", |
144 |
< |
c_in_name, n_atoms, i ); |
145 |
< |
painCave.isFatal = 1; |
146 |
< |
simError(); |
147 |
< |
} |
148 |
< |
(void)sscanf( foo, "%lf", &rx ); |
149 |
< |
|
150 |
< |
foo = strtok(NULL, " ,;\t"); |
151 |
< |
if(foo == NULL){ |
152 |
< |
sprintf( painCave.errMsg, |
153 |
< |
"error in reading postition y from %s\n" |
154 |
< |
"natoms = %d, index = %d\n", |
155 |
< |
c_in_name, n_atoms, i ); |
156 |
< |
painCave.isFatal = 1; |
157 |
< |
simError(); |
158 |
< |
} |
159 |
< |
(void)sscanf( foo, "%lf", &ry ); |
160 |
< |
|
161 |
< |
foo = strtok(NULL, " ,;\t"); |
162 |
< |
if(foo == NULL){ |
163 |
< |
sprintf( painCave.errMsg, |
164 |
< |
"error in reading postition z from %s\n" |
165 |
< |
"natoms = %d, index = %d\n", |
166 |
< |
c_in_name, n_atoms, i ); |
167 |
< |
painCave.isFatal = 1; |
168 |
< |
simError(); |
169 |
< |
} |
170 |
< |
(void)sscanf( foo, "%lf", &rz ); |
171 |
< |
|
172 |
< |
// get the velocities |
173 |
< |
|
174 |
< |
foo = strtok(NULL, " ,;\t"); |
175 |
< |
if(foo == NULL){ |
176 |
< |
sprintf( painCave.errMsg, |
177 |
< |
"error in reading velocity x from %s\n" |
178 |
< |
"natoms = %d, index = %d\n", |
179 |
< |
c_in_name, n_atoms, i ); |
180 |
< |
painCave.isFatal = 1; |
181 |
< |
simError(); |
182 |
< |
} |
183 |
< |
(void)sscanf( foo, "%lf", &vx ); |
184 |
< |
|
185 |
< |
foo = strtok(NULL, " ,;\t"); |
186 |
< |
if(foo == NULL){ |
187 |
< |
sprintf( painCave.errMsg, |
188 |
< |
"error in reading velocity y from %s\n" |
189 |
< |
"natoms = %d, index = %d\n", |
190 |
< |
c_in_name, n_atoms, i ); |
191 |
< |
painCave.isFatal = 1; |
192 |
< |
simError(); |
193 |
< |
} |
194 |
< |
(void)sscanf( foo, "%lf", &vy ); |
195 |
< |
|
196 |
< |
foo = strtok(NULL, " ,;\t"); |
197 |
< |
if(foo == NULL){ |
198 |
< |
sprintf( painCave.errMsg, |
199 |
< |
"error in reading velocity z from %s\n" |
200 |
< |
"natoms = %d, index = %d\n", |
201 |
< |
c_in_name, n_atoms, i ); |
202 |
< |
painCave.isFatal = 1; |
203 |
< |
simError(); |
204 |
< |
} |
205 |
< |
(void)sscanf( foo, "%lf", &vz ); |
206 |
< |
|
207 |
< |
|
208 |
< |
// get the quaternions |
209 |
< |
|
210 |
< |
if( atoms[i]->isDirectional() ){ |
211 |
< |
|
212 |
< |
foo = strtok(NULL, " ,;\t"); |
213 |
< |
if(foo == NULL){ |
214 |
< |
sprintf(painCave.errMsg, |
215 |
< |
"error in reading quaternion 0 from %s\n" |
216 |
< |
"natoms = %d, index = %d\n", |
217 |
< |
c_in_name, n_atoms, i ); |
218 |
< |
painCave.isFatal = 1; |
219 |
< |
simError(); |
220 |
< |
} |
221 |
< |
(void)sscanf( foo, "%lf", &q[0] ); |
222 |
< |
|
223 |
< |
foo = strtok(NULL, " ,;\t"); |
224 |
< |
if(foo == NULL){ |
225 |
< |
sprintf( painCave.errMsg, |
226 |
< |
"error in reading quaternion 1 from %s\n" |
227 |
< |
"natoms = %d, index = %d\n", |
228 |
< |
c_in_name, n_atoms, i ); |
229 |
< |
painCave.isFatal = 1; |
230 |
< |
simError(); |
231 |
< |
} |
232 |
< |
(void)sscanf( foo, "%lf", &q[1] ); |
233 |
< |
|
234 |
< |
foo = strtok(NULL, " ,;\t"); |
235 |
< |
if(foo == NULL){ |
236 |
< |
sprintf( painCave.errMsg, |
237 |
< |
"error in reading quaternion 2 from %s\n" |
238 |
< |
"natoms = %d, index = %d\n", |
239 |
< |
c_in_name, n_atoms, i ); |
240 |
< |
painCave.isFatal = 1; |
241 |
< |
simError(); |
242 |
< |
} |
243 |
< |
(void)sscanf( foo, "%lf", &q[2] ); |
244 |
< |
|
245 |
< |
foo = strtok(NULL, " ,;\t"); |
246 |
< |
if(foo == NULL){ |
247 |
< |
sprintf( painCave.errMsg, |
248 |
< |
"error in reading quaternion 3 from %s\n" |
249 |
< |
"natoms = %d, index = %d\n", |
250 |
< |
c_in_name, n_atoms, i ); |
251 |
< |
painCave.isFatal = 1; |
252 |
< |
simError(); |
253 |
< |
} |
254 |
< |
(void)sscanf( foo, "%lf", &q[3] ); |
255 |
< |
|
256 |
< |
// get the angular velocities |
257 |
< |
|
258 |
< |
foo = strtok(NULL, " ,;\t"); |
259 |
< |
if(foo == NULL){ |
260 |
< |
sprintf( painCave.errMsg, |
261 |
< |
"error in reading angular momentum jx from %s\n" |
262 |
< |
"natoms = %d, index = %d\n", |
263 |
< |
c_in_name, n_atoms, i ); |
264 |
< |
painCave.isFatal = 1; |
265 |
< |
simError(); |
266 |
< |
} |
267 |
< |
(void)sscanf( foo, "%lf", &jx ); |
268 |
< |
|
269 |
< |
foo = strtok(NULL, " ,;\t"); |
270 |
< |
if(foo == NULL){ |
271 |
< |
sprintf( painCave.errMsg, |
272 |
< |
"error in reading angular momentum jy from %s\n" |
273 |
< |
"natoms = %d, index = %d\n", |
274 |
< |
c_in_name, n_atoms, i ); |
275 |
< |
painCave.isFatal = 1; |
276 |
< |
simError(); |
277 |
< |
} |
278 |
< |
(void)sscanf( foo, "%lf", &jy ); |
279 |
< |
|
280 |
< |
foo = strtok(NULL, " ,;\t"); |
281 |
< |
if(foo == NULL){ |
282 |
< |
sprintf( painCave.errMsg, |
283 |
< |
"error in reading angular momentum jz from %s\n" |
284 |
< |
"natoms = %d, index = %d\n", |
285 |
< |
c_in_name, n_atoms, i ); |
286 |
< |
painCave.isFatal = 1; |
287 |
< |
simError(); |
288 |
< |
} |
289 |
< |
(void)sscanf( foo, "%lf", &jz ); |
290 |
< |
|
291 |
< |
dAtom = ( DirectionalAtom* )atoms[i]; |
292 |
< |
|
293 |
< |
// check that the quaternion vector is normalized |
294 |
< |
|
295 |
< |
qSqr = (q[0] * q[0]) + (q[1] * q[1]) + (q[2] * q[2]) + (q[3] * q[3]); |
296 |
< |
|
297 |
< |
qLength = sqrt( qSqr ); |
298 |
< |
q[0] = q[0] / qLength; |
299 |
< |
q[1] = q[1] / qLength; |
300 |
< |
q[2] = q[2] / qLength; |
301 |
< |
q[3] = q[3] / qLength; |
302 |
< |
|
303 |
< |
dAtom->setQ( q ); |
304 |
< |
|
305 |
< |
// add the angular velocities |
306 |
< |
|
307 |
< |
dAtom->setJx( jx ); |
308 |
< |
dAtom->setJy( jy ); |
309 |
< |
dAtom->setJz( jz ); |
310 |
< |
} |
311 |
< |
|
312 |
< |
// add the positions and velocities to the atom |
313 |
< |
|
314 |
< |
atoms[i]->setX( rx ); |
315 |
< |
atoms[i]->setY( ry ); |
316 |
< |
atoms[i]->setZ( rz ); |
317 |
< |
|
318 |
< |
atoms[i]->set_vx( vx ); |
319 |
< |
atoms[i]->set_vy( vy ); |
320 |
< |
atoms[i]->set_vz( vz ); |
321 |
< |
|
129 |
> |
} |
130 |
|
} |
131 |
|
|
132 |
|
|
133 |
|
// MPI Section of code.......... |
134 |
|
#else //IS_MPI |
135 |
|
|
136 |
+ |
int masterIndex; |
137 |
+ |
int nodeAtomsStart; |
138 |
+ |
int nodeAtomsEnd; |
139 |
+ |
int mpiErr; |
140 |
+ |
int sendError; |
141 |
|
|
142 |
+ |
MPI_Status istatus[MPI_STATUS_SIZE]; |
143 |
|
|
330 |
– |
|
144 |
|
if (worldRank == 0) { |
145 |
|
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
146 |
|
if( eof_test == NULL ){ |
150 |
|
simError(); |
151 |
|
} |
152 |
|
|
153 |
< |
(void)sscanf(read_buffer, "%d", &n_atoms); |
153 |
> |
n_atoms = atoi( read_buffer ); |
154 |
|
|
155 |
|
Atom **atoms = entry_plug->atoms; |
156 |
|
DirectionalAtom* dAtom; |
157 |
+ |
|
158 |
+ |
// Check to see that the number of atoms in the intial configuration file is the |
159 |
+ |
// same as declared in simBass. |
160 |
|
|
161 |
< |
if( n_atoms != entry_plug->n_atoms ){ |
161 |
> |
if( n_atoms != entry_plug->mpiSim->getTotAtoms() ){ |
162 |
|
sprintf( painCave.errMsg, |
163 |
|
"Initialize from File error. %s n_atoms, %d, " |
164 |
|
"does not match the BASS file's n_atoms, %d.\n", |
176 |
|
painCave.isFatal = 1; |
177 |
|
simError(); |
178 |
|
} |
179 |
< |
} |
180 |
< |
for( i=0; i < n_atoms; i++){ |
179 |
> |
|
180 |
> |
// Read Proc 0 share of the xyz file... |
181 |
> |
masterIndex = 0; |
182 |
> |
for( i=0; i <= entry_plug->mpiSim->getMyAtomEnd(); i++){ |
183 |
|
|
184 |
< |
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
185 |
< |
if(eof_test == NULL){ |
186 |
< |
sprintf(painCave.errMsg, |
187 |
< |
"error in reading file %s\n" |
188 |
< |
"natoms = %d; index = %d\n" |
189 |
< |
"error reading the line from the file.\n", |
190 |
< |
c_in_name, n_atoms, i ); |
191 |
< |
painCave.isFatal = 1; |
192 |
< |
simError(); |
184 |
> |
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
185 |
> |
if(eof_test == NULL){ |
186 |
> |
sprintf(painCave.errMsg, |
187 |
> |
"error in reading file %s\n" |
188 |
> |
"natoms = %d; index = %d\n" |
189 |
> |
"error reading the line from the file.\n", |
190 |
> |
c_in_name, n_atoms, i ); |
191 |
> |
painCave.isFatal = 1; |
192 |
> |
simError(); |
193 |
> |
} |
194 |
> |
|
195 |
> |
parseErr = parseDumpLine( read_buffer, i ); |
196 |
> |
if( parseErr != NULL ){ |
197 |
> |
strcpy( painCave.errMsg, parseErr ); |
198 |
> |
painCave.isFatal = 1; |
199 |
> |
simError(); |
200 |
> |
} |
201 |
> |
masterIndex++; |
202 |
|
} |
203 |
+ |
} |
204 |
|
|
205 |
< |
foo = strtok(read_buffer, " ,;\t"); |
206 |
< |
|
207 |
< |
// check the atom name to the current atom |
205 |
> |
sprintf(checkPointMsg, |
206 |
> |
"Node 0 has successfully read positions from input file."); |
207 |
> |
mpiCheckPoint(); |
208 |
|
|
209 |
< |
if( strcmp( foo, atoms[i]->getType() ) ){ |
210 |
< |
sprintf( painCave.errMsg, |
211 |
< |
"Initialize from file error. Atom %s at index %d " |
212 |
< |
"in file %s does not" |
213 |
< |
" match the BASS atom %s.\n", |
214 |
< |
foo, i, c_in_name, atoms[i]->getType() ); |
215 |
< |
painCave.isFatal = 1; |
216 |
< |
simError(); |
209 |
> |
for (procIndex = 1; procIndex < entryPlug->mpiSim->getNumberProcessors(); |
210 |
> |
procIndex++){ |
211 |
> |
if (worldRank == 0) { |
212 |
> |
|
213 |
> |
mpiErr = MPI_Recv(&nodeAtomsStart,1,MPI_INT,procIndex,MPI_ANY_TAG,MPI_COMM_WORLD, |
214 |
> |
istatus); |
215 |
> |
|
216 |
> |
mpiErr = MPI_Recv(&nodeAtomsEnd,1,MPI_INT,procIndex,MPI_ANY_TAG,MPI_COMM_WORLD, |
217 |
> |
istatus); |
218 |
> |
// Make sure where node 0 is reading from, matches where the receiving node |
219 |
> |
// expects it to be. |
220 |
> |
|
221 |
> |
if (masterIndex != nodeAtomsStart){ |
222 |
> |
sendError = 1; |
223 |
> |
mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,MPI_ANY_TAG,MPI_COMM_WORLD); |
224 |
> |
sprintf(painCave.errMsg, |
225 |
> |
"Initialize from file error: atoms start index (%d) for " |
226 |
> |
"node %d not equal to master index (%d)",nodeAtomsStart,procIndex,masterIndex ); |
227 |
> |
painCave.isFatal = 1; |
228 |
> |
simError(); |
229 |
> |
} |
230 |
> |
sendError = 0; |
231 |
> |
mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,MPI_ANY_TAG,MPI_COMM_WORLD); |
232 |
> |
|
233 |
> |
for ( i = nodeAtomStart; i <= nodeAtomEnd, i++){ |
234 |
> |
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
235 |
> |
if(eof_test == NULL){ |
236 |
> |
|
237 |
> |
sprintf(read_buffer,"ERROR"); |
238 |
> |
mpiErr = MPI_Send(read_buffer,BUFFERSIZE,MPI_CHAR,procIndex,MPI_ANY_TAG,MPI_COMM_WORLD); |
239 |
> |
|
240 |
> |
sprintf(painCave.errMsg, |
241 |
> |
"error in reading file %s\n" |
242 |
> |
"natoms = %d; index = %d\n" |
243 |
> |
"error reading the line from the file.\n", |
244 |
> |
c_in_name, n_atoms, i ); |
245 |
> |
painCave.isFatal = 1; |
246 |
> |
simError(); |
247 |
> |
} |
248 |
> |
|
249 |
> |
mpiErr = MPI_Send(read_buffer,BUFFERSIZE,MPI_CHAR,procIndex,MPI_ANY_TAG,MPI_COMM_WORLD); |
250 |
> |
mpiErr = MPI_Recv(&sendError,1,MPI_INT,procIndex,MPI_ANY_TAG,MPI_COMM_WORLD, |
251 |
> |
istatus); |
252 |
> |
if (sendError) mpiCheckpoint(); |
253 |
> |
|
254 |
> |
masterIndex++; |
255 |
> |
} |
256 |
|
} |
390 |
– |
|
391 |
– |
// get the positions |
257 |
|
|
258 |
+ |
|
259 |
+ |
else if(worldRank == procIndex){ |
260 |
+ |
nodeAtomStart = entry_plug->mpiSim->getMyAtomStart(); |
261 |
+ |
nodeAtomEnd = entry_plug->mpiSim->getMyAtomEnd(); |
262 |
+ |
mpiErr = MPI_Send(&nodeAtomsStart,1,MPI_INT,0,MPI_ANY_TAG,MPI_COMM_WORLD); |
263 |
+ |
mpiErr = MPI_Send(&nodeAtomsEnd,1,MPI_INT,0,MPI_ANY_TAG,MPI_COMM_WORLD); |
264 |
+ |
|
265 |
+ |
mpiErr = MPI_Recv(&sendError,1,MPI_INT,0,MPI_ANY_TAG,MPI_COMM_WORLD, |
266 |
+ |
istatus); |
267 |
+ |
if (sendError) mpiCheckpoint(); |
268 |
+ |
|
269 |
+ |
for ( i = 0; i < entry_plug->n_atoms, i++){ |
270 |
+ |
|
271 |
+ |
mpiErr = MPI_Recv(&read_buffer,BUFFERSIZE,MPI_CHAR,0,MPI_ANY_TAG,MPI_COMM_WORLD, |
272 |
+ |
istatus); |
273 |
+ |
|
274 |
+ |
if(!strcmp(read_buffer, "ERROR")) mpiCheckPoint(); |
275 |
+ |
|
276 |
+ |
parseErr = parseDumpLine( read_buffer, i ); |
277 |
+ |
if( parseErr != NULL ){ |
278 |
+ |
sendError = 1; |
279 |
+ |
mpiErr = MPI_Send(&sendError,1,MPI_INT,0,MPI_ANY_TAG,MPI_COMM_WORLD); |
280 |
+ |
|
281 |
+ |
|
282 |
+ |
strcpy( painCave.errMsg, parseErr ); |
283 |
+ |
painCave.isFatal = 1; |
284 |
+ |
simError(); |
285 |
+ |
} |
286 |
+ |
sendError = 0; |
287 |
+ |
mpiErr = MPI_Send(&sendError,1,MPI_INT,0,MPI_ANY_TAG,MPI_COMM_WORLD); |
288 |
+ |
} |
289 |
+ |
} |
290 |
+ |
sprintf(checkPointMsg,"Node %d received initial configuration.",procIndex); |
291 |
+ |
mpiCheckPoint(); |
292 |
+ |
} |
293 |
+ |
|
294 |
+ |
#endif |
295 |
+ |
} |
296 |
+ |
|
297 |
+ |
|
298 |
+ |
char* IntitializeFromFile::parseDumpLine(char* readLine, int atomIndex){ |
299 |
+ |
|
300 |
+ |
char *foo; // the pointer to the current string token |
301 |
+ |
|
302 |
+ |
double rx, ry, rz; // position place holders |
303 |
+ |
double vx, vy, vz; // velocity placeholders |
304 |
+ |
double q[4]; // the quaternions |
305 |
+ |
double jx, jy, jz; // angular velocity placeholders; |
306 |
+ |
double qSqr, qLength; // needed to normalize the quaternion vector. |
307 |
+ |
|
308 |
+ |
Atom **atoms = entry_plug->atoms; |
309 |
+ |
DirectionalAtom* dAtom; |
310 |
+ |
|
311 |
+ |
int n_atoms; |
312 |
+ |
|
313 |
+ |
#ifdef IS_MPI |
314 |
+ |
n_atoms = entry_plug->mpiSim->getTotAtoms(); |
315 |
+ |
#else |
316 |
+ |
n_atoms = entry_plug->n_atoms; |
317 |
+ |
#endi // is_mpi |
318 |
+ |
|
319 |
+ |
|
320 |
+ |
// set the string tokenizer |
321 |
+ |
|
322 |
+ |
foo = strtok(readLine, " ,;\t"); |
323 |
+ |
|
324 |
+ |
// check the atom name to the current atom |
325 |
+ |
|
326 |
+ |
if( strcmp( foo, atoms[atomIndex]->getType() ) ){ |
327 |
+ |
sprintf( painCave.errMsg, |
328 |
+ |
"Initialize from file error. Atom %s at index %d " |
329 |
+ |
"in file %s does not" |
330 |
+ |
" match the BASS atom %s.\n", |
331 |
+ |
foo, atomIndex, c_in_name, atoms[atomIndex]->getType() ); |
332 |
+ |
return strdup( painCave.errMsg ); |
333 |
+ |
} |
334 |
+ |
|
335 |
+ |
// get the positions |
336 |
+ |
|
337 |
+ |
foo = strtok(NULL, " ,;\t"); |
338 |
+ |
if(foo == NULL){ |
339 |
+ |
sprintf( painCave.errMsg, |
340 |
+ |
"error in reading postition x from %s\n" |
341 |
+ |
"natoms = %d, index = %d\n", |
342 |
+ |
c_in_name, n_atoms, atomIndex ); |
343 |
+ |
return strdup( painCave.errMsg ); |
344 |
+ |
} |
345 |
+ |
rx = atof( foo ); |
346 |
+ |
|
347 |
+ |
foo = strtok(NULL, " ,;\t"); |
348 |
+ |
if(foo == NULL){ |
349 |
+ |
sprintf( painCave.errMsg, |
350 |
+ |
"error in reading postition y from %s\n" |
351 |
+ |
"natoms = %d, index = %d\n", |
352 |
+ |
c_in_name, n_atoms, atomIndex ); |
353 |
+ |
return strdup( painCave.errMsg ); |
354 |
+ |
} |
355 |
+ |
ry = atof( foo ); |
356 |
+ |
|
357 |
+ |
foo = strtok(NULL, " ,;\t"); |
358 |
+ |
if(foo == NULL){ |
359 |
+ |
sprintf( painCave.errMsg, |
360 |
+ |
"error in reading postition z from %s\n" |
361 |
+ |
"natoms = %d, index = %d\n", |
362 |
+ |
c_in_name, n_atoms, atomIndex ); |
363 |
+ |
return strdup( painCave.errMsg ); |
364 |
+ |
} |
365 |
+ |
rz = atof( foo ); |
366 |
+ |
|
367 |
+ |
|
368 |
+ |
// get the velocities |
369 |
+ |
|
370 |
+ |
foo = strtok(NULL, " ,;\t"); |
371 |
+ |
if(foo == NULL){ |
372 |
+ |
sprintf( painCave.errMsg, |
373 |
+ |
"error in reading velocity x from %s\n" |
374 |
+ |
"natoms = %d, index = %d\n", |
375 |
+ |
c_in_name, n_atoms, atomIndex ); |
376 |
+ |
return strdup( painCave.errMsg ); |
377 |
+ |
} |
378 |
+ |
vx = atof( foo ); |
379 |
+ |
|
380 |
+ |
foo = strtok(NULL, " ,;\t"); |
381 |
+ |
if(foo == NULL){ |
382 |
+ |
sprintf( painCave.errMsg, |
383 |
+ |
"error in reading velocity y from %s\n" |
384 |
+ |
"natoms = %d, index = %d\n", |
385 |
+ |
c_in_name, n_atoms, atomIndex ); |
386 |
+ |
return strdup( painCave.errMsg ); |
387 |
+ |
} |
388 |
+ |
vy = atof( foo ); |
389 |
+ |
|
390 |
+ |
foo = strtok(NULL, " ,;\t"); |
391 |
+ |
if(foo == NULL){ |
392 |
+ |
sprintf( painCave.errMsg, |
393 |
+ |
"error in reading velocity z from %s\n" |
394 |
+ |
"natoms = %d, index = %d\n", |
395 |
+ |
c_in_name, n_atoms, atomIndex ); |
396 |
+ |
return strdup( painCave.errMsg ); |
397 |
+ |
} |
398 |
+ |
vz = atof( foo ); |
399 |
+ |
|
400 |
+ |
|
401 |
+ |
// get the quaternions |
402 |
+ |
|
403 |
+ |
if( atoms[atomIndex]->isDirectional() ){ |
404 |
+ |
|
405 |
|
foo = strtok(NULL, " ,;\t"); |
406 |
|
if(foo == NULL){ |
407 |
+ |
sprintf(painCave.errMsg, |
408 |
+ |
"error in reading quaternion 0 from %s\n" |
409 |
+ |
"natoms = %d, index = %d\n", |
410 |
+ |
c_in_name, n_atoms, atomIndex ); |
411 |
+ |
return strdup( painCave.errMsg ); |
412 |
+ |
} |
413 |
+ |
q[0] = atof( foo ); |
414 |
+ |
|
415 |
+ |
foo = strtok(NULL, " ,;\t"); |
416 |
+ |
if(foo == NULL){ |
417 |
|
sprintf( painCave.errMsg, |
418 |
< |
"error in reading postition x from %s\n" |
418 |
> |
"error in reading quaternion 1 from %s\n" |
419 |
|
"natoms = %d, index = %d\n", |
420 |
< |
c_in_name, n_atoms, i ); |
421 |
< |
painCave.isFatal = 1; |
400 |
< |
simError(); |
420 |
> |
c_in_name, n_atoms, atomIndex ); |
421 |
> |
return strdup( painCave.errMsg ); |
422 |
|
} |
423 |
< |
(void)sscanf( foo, "%lf", &rx ); |
424 |
< |
|
423 |
> |
q[1] = atof( foo ); |
424 |
> |
|
425 |
|
foo = strtok(NULL, " ,;\t"); |
426 |
|
if(foo == NULL){ |
427 |
|
sprintf( painCave.errMsg, |
428 |
< |
"error in reading postition y from %s\n" |
428 |
> |
"error in reading quaternion 2 from %s\n" |
429 |
|
"natoms = %d, index = %d\n", |
430 |
< |
c_in_name, n_atoms, i ); |
431 |
< |
painCave.isFatal = 1; |
411 |
< |
simError(); |
430 |
> |
c_in_name, n_atoms, atomIndex ); |
431 |
> |
return strdup( painCave.errMsg ); |
432 |
|
} |
433 |
< |
(void)sscanf( foo, "%lf", &ry ); |
434 |
< |
|
433 |
> |
q[2] = atof( foo ); |
434 |
> |
|
435 |
|
foo = strtok(NULL, " ,;\t"); |
436 |
|
if(foo == NULL){ |
437 |
|
sprintf( painCave.errMsg, |
438 |
< |
"error in reading postition z from %s\n" |
438 |
> |
"error in reading quaternion 3 from %s\n" |
439 |
|
"natoms = %d, index = %d\n", |
440 |
< |
c_in_name, n_atoms, i ); |
441 |
< |
painCave.isFatal = 1; |
422 |
< |
simError(); |
440 |
> |
c_in_name, n_atoms, atomIndex ); |
441 |
> |
return strdup( painCave.errMsg ); |
442 |
|
} |
443 |
< |
(void)sscanf( foo, "%lf", &rz ); |
444 |
< |
|
445 |
< |
// get the velocities |
446 |
< |
|
443 |
> |
q[3] = atof( foo ); |
444 |
> |
|
445 |
> |
// get the angular velocities |
446 |
> |
|
447 |
|
foo = strtok(NULL, " ,;\t"); |
448 |
|
if(foo == NULL){ |
449 |
|
sprintf( painCave.errMsg, |
450 |
< |
"error in reading velocity x from %s\n" |
450 |
> |
"error in reading angular momentum jx from %s\n" |
451 |
|
"natoms = %d, index = %d\n", |
452 |
< |
c_in_name, n_atoms, i ); |
453 |
< |
painCave.isFatal = 1; |
435 |
< |
simError(); |
452 |
> |
c_in_name, n_atoms, atomIndex ); |
453 |
> |
return strdup( painCave.errMsg ); |
454 |
|
} |
455 |
< |
(void)sscanf( foo, "%lf", &vx ); |
456 |
< |
|
455 |
> |
jx = atof( foo ); |
456 |
> |
|
457 |
|
foo = strtok(NULL, " ,;\t"); |
458 |
|
if(foo == NULL){ |
459 |
|
sprintf( painCave.errMsg, |
460 |
< |
"error in reading velocity y from %s\n" |
460 |
> |
"error in reading angular momentum jy from %s\n" |
461 |
|
"natoms = %d, index = %d\n", |
462 |
< |
c_in_name, n_atoms, i ); |
463 |
< |
painCave.isFatal = 1; |
446 |
< |
simError(); |
462 |
> |
c_in_name, n_atoms, atomIndex ); |
463 |
> |
return strdup( painCave.errMsg ); |
464 |
|
} |
465 |
< |
(void)sscanf( foo, "%lf", &vy ); |
466 |
< |
|
465 |
> |
jy = atof(foo ); |
466 |
> |
|
467 |
|
foo = strtok(NULL, " ,;\t"); |
468 |
|
if(foo == NULL){ |
469 |
|
sprintf( painCave.errMsg, |
470 |
< |
"error in reading velocity z from %s\n" |
470 |
> |
"error in reading angular momentum jz from %s\n" |
471 |
|
"natoms = %d, index = %d\n", |
472 |
< |
c_in_name, n_atoms, i ); |
473 |
< |
painCave.isFatal = 1; |
457 |
< |
simError(); |
472 |
> |
c_in_name, n_atoms, atomIndex ); |
473 |
> |
return strdup( painCave.errMsg ); |
474 |
|
} |
475 |
< |
(void)sscanf( foo, "%lf", &vz ); |
460 |
< |
|
461 |
< |
|
462 |
< |
// get the quaternions |
463 |
< |
|
464 |
< |
if( atoms[i]->isDirectional() ){ |
475 |
> |
jz = atof( foo ); |
476 |
|
|
477 |
< |
foo = strtok(NULL, " ,;\t"); |
467 |
< |
if(foo == NULL){ |
468 |
< |
sprintf(painCave.errMsg, |
469 |
< |
"error in reading quaternion 0 from %s\n" |
470 |
< |
"natoms = %d, index = %d\n", |
471 |
< |
c_in_name, n_atoms, i ); |
472 |
< |
painCave.isFatal = 1; |
473 |
< |
simError(); |
474 |
< |
} |
475 |
< |
(void)sscanf( foo, "%lf", &q[0] ); |
476 |
< |
|
477 |
< |
foo = strtok(NULL, " ,;\t"); |
478 |
< |
if(foo == NULL){ |
479 |
< |
sprintf( painCave.errMsg, |
480 |
< |
"error in reading quaternion 1 from %s\n" |
481 |
< |
"natoms = %d, index = %d\n", |
482 |
< |
c_in_name, n_atoms, i ); |
483 |
< |
painCave.isFatal = 1; |
484 |
< |
simError(); |
485 |
< |
} |
486 |
< |
(void)sscanf( foo, "%lf", &q[1] ); |
487 |
< |
|
488 |
< |
foo = strtok(NULL, " ,;\t"); |
489 |
< |
if(foo == NULL){ |
490 |
< |
sprintf( painCave.errMsg, |
491 |
< |
"error in reading quaternion 2 from %s\n" |
492 |
< |
"natoms = %d, index = %d\n", |
493 |
< |
c_in_name, n_atoms, i ); |
494 |
< |
painCave.isFatal = 1; |
495 |
< |
simError(); |
496 |
< |
} |
497 |
< |
(void)sscanf( foo, "%lf", &q[2] ); |
498 |
< |
|
499 |
< |
foo = strtok(NULL, " ,;\t"); |
500 |
< |
if(foo == NULL){ |
501 |
< |
sprintf( painCave.errMsg, |
502 |
< |
"error in reading quaternion 3 from %s\n" |
503 |
< |
"natoms = %d, index = %d\n", |
504 |
< |
c_in_name, n_atoms, i ); |
505 |
< |
painCave.isFatal = 1; |
506 |
< |
simError(); |
507 |
< |
} |
508 |
< |
(void)sscanf( foo, "%lf", &q[3] ); |
509 |
< |
|
510 |
< |
// get the angular velocities |
511 |
< |
|
512 |
< |
foo = strtok(NULL, " ,;\t"); |
513 |
< |
if(foo == NULL){ |
514 |
< |
sprintf( painCave.errMsg, |
515 |
< |
"error in reading angular momentum jx from %s\n" |
516 |
< |
"natoms = %d, index = %d\n", |
517 |
< |
c_in_name, n_atoms, i ); |
518 |
< |
painCave.isFatal = 1; |
519 |
< |
simError(); |
520 |
< |
} |
521 |
< |
(void)sscanf( foo, "%lf", &jx ); |
522 |
< |
|
523 |
< |
foo = strtok(NULL, " ,;\t"); |
524 |
< |
if(foo == NULL){ |
525 |
< |
sprintf( painCave.errMsg, |
526 |
< |
"error in reading angular momentum jy from %s\n" |
527 |
< |
"natoms = %d, index = %d\n", |
528 |
< |
c_in_name, n_atoms, i ); |
529 |
< |
painCave.isFatal = 1; |
530 |
< |
simError(); |
531 |
< |
} |
532 |
< |
(void)sscanf( foo, "%lf", &jy ); |
533 |
< |
|
534 |
< |
foo = strtok(NULL, " ,;\t"); |
535 |
< |
if(foo == NULL){ |
536 |
< |
sprintf( painCave.errMsg, |
537 |
< |
"error in reading angular momentum jz from %s\n" |
538 |
< |
"natoms = %d, index = %d\n", |
539 |
< |
c_in_name, n_atoms, i ); |
540 |
< |
painCave.isFatal = 1; |
541 |
< |
simError(); |
542 |
< |
} |
543 |
< |
(void)sscanf( foo, "%lf", &jz ); |
544 |
< |
|
545 |
< |
dAtom = ( DirectionalAtom* )atoms[i]; |
477 |
> |
dAtom = ( DirectionalAtom* )atoms[atomIndex]; |
478 |
|
|
479 |
< |
// check that the quaternion vector is normalized |
479 |
> |
// check that the quaternion vector is normalized |
480 |
|
|
481 |
< |
qSqr = (q[0] * q[0]) + (q[1] * q[1]) + (q[2] * q[2]) + (q[3] * q[3]); |
481 |
> |
qSqr = (q[0] * q[0]) + (q[1] * q[1]) + (q[2] * q[2]) + (q[3] * q[3]); |
482 |
|
|
483 |
< |
qLength = sqrt( qSqr ); |
484 |
< |
q[0] = q[0] / qLength; |
485 |
< |
q[1] = q[1] / qLength; |
486 |
< |
q[2] = q[2] / qLength; |
487 |
< |
q[3] = q[3] / qLength; |
483 |
> |
qLength = sqrt( qSqr ); |
484 |
> |
q[0] = q[0] / qLength; |
485 |
> |
q[1] = q[1] / qLength; |
486 |
> |
q[2] = q[2] / qLength; |
487 |
> |
q[3] = q[3] / qLength; |
488 |
|
|
489 |
< |
dAtom->setQ( q ); |
489 |
> |
dAtom->setQ( q ); |
490 |
|
|
491 |
< |
// add the angular velocities |
491 |
> |
// add the angular velocities |
492 |
|
|
493 |
< |
dAtom->setJx( jx ); |
494 |
< |
dAtom->setJy( jy ); |
495 |
< |
dAtom->setJz( jz ); |
496 |
< |
} |
493 |
> |
dAtom->setJx( jx ); |
494 |
> |
dAtom->setJy( jy ); |
495 |
> |
dAtom->setJz( jz ); |
496 |
> |
} |
497 |
|
|
498 |
< |
// add the positions and velocities to the atom |
498 |
> |
// add the positions and velocities to the atom |
499 |
|
|
500 |
< |
atoms[i]->setX( rx ); |
501 |
< |
atoms[i]->setY( ry ); |
502 |
< |
atoms[i]->setZ( rz ); |
500 |
> |
atoms[atomIndex]->setX( rx ); |
501 |
> |
atoms[atomIndex]->setY( ry ); |
502 |
> |
atoms[atomIndex]->setZ( rz ); |
503 |
|
|
504 |
< |
atoms[i]->set_vx( vx ); |
505 |
< |
atoms[i]->set_vy( vy ); |
506 |
< |
atoms[i]->set_vz( vz ); |
575 |
< |
|
576 |
< |
} |
577 |
< |
#endif |
578 |
< |
} |
504 |
> |
atoms[atomIndex]->set_vx( vx ); |
505 |
> |
atoms[atomIndex]->set_vy( vy ); |
506 |
> |
atoms[atomIndex]->set_vz( vz ); |
507 |
|
|
508 |
< |
char* IntitializeFromFile::parseDumpLine(char* readLine); |
508 |
> |
return NULL; |
509 |
> |
} |