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