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