# | Line 9 | Line 9 | |
---|---|---|
9 | #include <sys/stat.h> | |
10 | ||
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){ | |
25 | < | printf("Cannot open file: %s\n", in_name); |
26 | < | exit(8); |
25 | > | sprintf(painCave.errMsg, |
26 | > | "Cannot open file: %s\n", in_name); |
27 | > | painCave.isFatal = 1; |
28 | > | simError(); |
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 ){ | |
47 | < | fprintf( stderr, "Error closing %s\n", c_in_name ); |
47 | > | sprintf( painCave.errMsg, |
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 |
47 | < | double vx, vy, vz; // velocity placeholders |
48 | < | double q[4]; // the quaternions |
49 | < | double jx, jy, jz; // angular velocity placeholders; |
50 | < | 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; | |
93 | ||
94 | if( n_atoms != entry_plug->n_atoms ){ | |
95 | < | fprintf( stderr, |
95 | > | sprintf( painCave.errMsg, |
96 | "Initialize from File error. %s n_atoms, %d, " | |
97 | "does not match the BASS file's n_atoms, %d.\n", | |
98 | c_in_name, n_atoms, entry_plug->n_atoms ); | |
99 | < | exit(8); |
99 | > | painCave.isFatal = 1; |
100 | > | simError(); |
101 | } | |
102 | ||
103 | //read and toss the comment line | |
104 | ||
105 | eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); | |
106 | if(eof_test == NULL){ | |
107 | < | printf("error in reading commment in %s\n", c_in_name); |
108 | < | exit(8); |
107 | > | sprintf( painCave.errMsg, |
108 | > | "error in reading commment in %s\n", c_in_name); |
109 | > | painCave.isFatal = 1; |
110 | > | simError(); |
111 | } | |
112 | ||
113 | for( i=0; i < n_atoms; i++){ | |
114 | ||
115 | eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); | |
116 | if(eof_test == NULL){ | |
117 | < | printf("error in reading file %s\n" |
118 | < | "natoms = %d; index = %d\n" |
119 | < | "error reading the line from the file.\n", |
120 | < | c_in_name, n_atoms, i ); |
121 | < | exit(8); |
117 | > | sprintf(painCave.errMsg, |
118 | > | "error in reading file %s\n" |
119 | > | "natoms = %d; index = %d\n" |
120 | > | "error reading the line from the file.\n", |
121 | > | c_in_name, n_atoms, i ); |
122 | > | painCave.isFatal = 1; |
123 | > | simError(); |
124 | } | |
125 | ||
89 | – | foo = strtok(read_buffer, " ,;\t"); |
126 | ||
127 | < | // check the atom name to the current atom |
127 | > | parseErr = parseDumpLine( read_buffer, i ); |
128 | > | if( parseErr != NULL ){ |
129 | > | strcpy( painCave.errMsg, parseErr ); |
130 | > | painCave.isFatal = 1; |
131 | > | simError(); |
132 | > | } |
133 | > | } |
134 | ||
93 | – | if( strcmp( foo, atoms[i]->getType() ) ){ |
94 | – | fprintf( stderr, |
95 | – | "Initialize from file error. Atom %s at index %d " |
96 | – | "in file %s does not" |
97 | – | " match the BASS atom %s.\n", |
98 | – | foo, i, c_in_name, atoms[i]->getType() ); |
99 | – | exit(8); |
100 | – | } |
101 | – | |
102 | – | // get the positions |
135 | ||
136 | < | foo = strtok(NULL, " ,;\t"); |
137 | < | if(foo == NULL){ |
106 | < | printf("error in reading postition x from %s\n" |
107 | < | "natoms = %d, index = %d\n", |
108 | < | c_in_name, n_atoms, i ); |
109 | < | exit(8); |
110 | < | } |
111 | < | (void)sscanf( foo, "%lf", &rx ); |
112 | < | |
113 | < | foo = strtok(NULL, " ,;\t"); |
114 | < | if(foo == NULL){ |
115 | < | printf("error in reading postition y from %s\n" |
116 | < | "natoms = %d, index = %d\n", |
117 | < | c_in_name, n_atoms, i ); |
118 | < | exit(8); |
119 | < | } |
120 | < | (void)sscanf( foo, "%lf", &ry ); |
121 | < | |
122 | < | foo = strtok(NULL, " ,;\t"); |
123 | < | if(foo == NULL){ |
124 | < | printf("error in reading postition z from %s\n" |
125 | < | "natoms = %d, index = %d\n", |
126 | < | c_in_name, n_atoms, i ); |
127 | < | exit(8); |
128 | < | } |
129 | < | (void)sscanf( foo, "%lf", &rz ); |
130 | < | |
131 | < | // get the velocities |
136 | > | // MPI Section of code.......... |
137 | > | #else //IS_MPI |
138 | ||
139 | < | foo = strtok(NULL, " ,;\t"); |
140 | < | if(foo == NULL){ |
141 | < | printf("error in reading velocity x from %s\n" |
142 | < | "natoms = %d, index = %d\n", |
143 | < | c_in_name, n_atoms, i ); |
144 | < | exit(8); |
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 reading 1st line of %d \n ",c_in_name); |
152 | > | painCave.isFatal = 1; |
153 | > | simError(); |
154 | } | |
140 | – | (void)sscanf( foo, "%lf", &vx ); |
155 | ||
156 | < | foo = strtok(NULL, " ,;\t"); |
143 | < | if(foo == NULL){ |
144 | < | printf("error in reading velocity y from %s\n" |
145 | < | "natoms = %d, index = %d\n", |
146 | < | c_in_name, n_atoms, i ); |
147 | < | exit(8); |
148 | < | } |
149 | < | (void)sscanf( foo, "%lf", &vy ); |
156 | > | n_atoms = atoi( read_buffer ); |
157 | ||
158 | < | foo = strtok(NULL, " ,;\t"); |
159 | < | if(foo == NULL){ |
160 | < | printf("error in reading velocity z from %s\n" |
161 | < | "natoms = %d, index = %d\n", |
162 | < | c_in_name, n_atoms, i ); |
163 | < | exit(8); |
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 | > | "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 | } | |
158 | – | (void)sscanf( foo, "%lf", &vz ); |
172 | ||
173 | + | //read and toss the comment line |
174 | ||
175 | < | // get the quaternions |
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 commment in %s\n", c_in_name); |
179 | > | painCave.isFatal = 1; |
180 | > | simError(); |
181 | > | } |
182 | > | |
183 | > | // Read Proc 0 share of the xyz file... |
184 | > | masterIndex = 0; |
185 | > | for( i=0; i <= mpiSim->getMyAtomEnd(); i++){ |
186 | ||
187 | < | if( atoms[i]->isDirectional() ){ |
188 | < | |
189 | < | foo = strtok(NULL, " ,;\t"); |
190 | < | if(foo == NULL){ |
191 | < | printf("error in reading quaternion 0 from %s\n" |
192 | < | "natoms = %d, index = %d\n", |
193 | < | c_in_name, n_atoms, i ); |
194 | < | exit(8); |
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 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 | < | printf("error in reading quaternion 1 from %s\n" |
202 | < | "natoms = %d, index = %d\n", |
203 | < | c_in_name, n_atoms, i ); |
204 | < | exit(8); |
205 | < | } |
206 | < | (void)sscanf( foo, "%lf", &q[1] ); |
182 | < | |
183 | < | foo = strtok(NULL, " ,;\t"); |
184 | < | if(foo == NULL){ |
185 | < | printf("error in reading quaternion 2 from %s\n" |
186 | < | "natoms = %d, index = %d\n", |
187 | < | c_in_name, n_atoms, i ); |
188 | < | exit(8); |
189 | < | } |
190 | < | (void)sscanf( foo, "%lf", &q[2] ); |
197 | > | |
198 | > | parseErr = parseDumpLine( read_buffer, i ); |
199 | > | if( parseErr != NULL ){ |
200 | > | strcpy( painCave.errMsg, parseErr ); |
201 | > | painCave.isFatal = 1; |
202 | > | simError(); |
203 | > | } |
204 | > | masterIndex++; |
205 | > | } |
206 | > | } |
207 | ||
208 | < | foo = strtok(NULL, " ,;\t"); |
209 | < | if(foo == NULL){ |
210 | < | printf("error in reading quaternion 3 from %s\n" |
195 | < | "natoms = %d, index = %d\n", |
196 | < | c_in_name, n_atoms, i ); |
197 | < | exit(8); |
198 | < | } |
199 | < | (void)sscanf( foo, "%lf", &q[3] ); |
200 | < | |
201 | < | // get the angular velocities |
202 | < | |
203 | < | foo = strtok(NULL, " ,;\t"); |
204 | < | if(foo == NULL){ |
205 | < | printf("error in reading angular momentum jx from %s\n" |
206 | < | "natoms = %d, index = %d\n", |
207 | < | c_in_name, n_atoms, i ); |
208 | < | exit(8); |
209 | < | } |
210 | < | (void)sscanf( foo, "%lf", &jx ); |
211 | < | |
212 | < | foo = strtok(NULL, " ,;\t"); |
213 | < | if(foo == NULL){ |
214 | < | printf("error in reading angular momentum jy from %s\n" |
215 | < | "natoms = %d, index = %d\n", |
216 | < | c_in_name, n_atoms, i ); |
217 | < | exit(8); |
218 | < | } |
219 | < | (void)sscanf( foo, "%lf", &jy ); |
220 | < | |
221 | < | foo = strtok(NULL, " ,;\t"); |
222 | < | if(foo == NULL){ |
223 | < | printf("error in reading angular momentum jz from %s\n" |
224 | < | "natoms = %d, index = %d\n", |
225 | < | c_in_name, n_atoms, i ); |
226 | < | exit(8); |
227 | < | } |
228 | < | (void)sscanf( foo, "%lf", &jz ); |
229 | < | |
230 | < | dAtom = ( DirectionalAtom* )atoms[i]; |
208 | > | sprintf(checkPointMsg, |
209 | > | "Node 0 has successfully read positions from input file."); |
210 | > | MPIcheckPoint(); |
211 | ||
212 | < | // check that the quaternion vector is normalized |
212 | > | for (procIndex = 1; procIndex < mpiSim->getNumberProcessors(); |
213 | > | procIndex++){ |
214 | > | if (worldRank == 0) { |
215 | ||
216 | < | qSqr = (q[0] * q[0]) + (q[1] * q[1]) + (q[2] * q[2]) + (q[3] * q[3]); |
217 | < | |
236 | < | qLength = sqrt( qSqr ); |
237 | < | q[0] = q[0] / qLength; |
238 | < | q[1] = q[1] / qLength; |
239 | < | q[2] = q[2] / qLength; |
240 | < | q[3] = q[3] / qLength; |
241 | < | |
242 | < | dAtom->setQ( q ); |
243 | < | |
244 | < | // add the angular velocities |
216 | > | mpiErr = MPI_Recv(&nodeAtomsStart,1,MPI_INT,procIndex,MPI_ANY_TAG,MPI_COMM_WORLD, |
217 | > | istatus); |
218 | ||
219 | < | dAtom->setJx( jx ); |
220 | < | dAtom->setJy( jy ); |
221 | < | dAtom->setJz( jz ); |
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 | > | sendError = 0; |
234 | > | mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,MPI_ANY_TAG,MPI_COMM_WORLD); |
235 | > | |
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 | > | 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 |