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) { |
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[2000]; |
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 |
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. |
78 |
> |
entry_plug = the_entry_plug; |
79 |
|
|
77 |
– |
entry_plug = the_entry_plug |
80 |
|
|
79 |
– |
|
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 |
|
|
123 |
– |
foo = strtok(read_buffer, " ,;\t"); |
128 |
|
|
129 |
< |
// check the atom name to the current atom |
130 |
< |
|
131 |
< |
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() ); |
129 |
> |
parseErr = parseDumpLine( read_buffer, i ); |
130 |
> |
if( parseErr != NULL ){ |
131 |
> |
strcpy( painCave.errMsg, parseErr ); |
132 |
|
painCave.isFatal = 1; |
133 |
|
simError(); |
134 |
< |
} |
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 |
< |
|
134 |
> |
} |
135 |
|
} |
136 |
|
|
137 |
|
|
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 |
|
|
330 |
– |
|
149 |
|
if (worldRank == 0) { |
150 |
|
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
151 |
|
if( eof_test == NULL ){ |
155 |
|
simError(); |
156 |
|
} |
157 |
|
|
158 |
< |
(void)sscanf(read_buffer, "%d", &n_atoms); |
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 != entry_plug->n_atoms ){ |
166 |
> |
if( n_atoms != mpiSim->getTotAtoms() ){ |
167 |
|
sprintf( painCave.errMsg, |
168 |
|
"Initialize from File error. %s n_atoms, %d, " |
169 |
|
"does not match the BASS file's n_atoms, %d.\n", |
181 |
|
painCave.isFatal = 1; |
182 |
|
simError(); |
183 |
|
} |
184 |
< |
} |
185 |
< |
for( i=0; i < n_atoms; i++){ |
184 |
> |
|
185 |
> |
// Read Proc 0 share of the xyz file... |
186 |
> |
masterIndex = 0; |
187 |
> |
for( i=0; i <= mpiSim->getMyAtomEnd(); i++){ |
188 |
|
|
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 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(); |
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 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 |
> |
|
200 |
> |
parseErr = parseDumpLine( read_buffer, i ); |
201 |
> |
if( parseErr != NULL ){ |
202 |
> |
strcpy( painCave.errMsg, parseErr ); |
203 |
> |
painCave.isFatal = 1; |
204 |
> |
simError(); |
205 |
> |
} |
206 |
> |
masterIndex++; |
207 |
|
} |
208 |
+ |
} |
209 |
|
|
210 |
< |
foo = strtok(read_buffer, " ,;\t"); |
211 |
< |
|
212 |
< |
// check the atom name to the current atom |
210 |
> |
sprintf(checkPointMsg, |
211 |
> |
"Node 0 has successfully read positions from input file."); |
212 |
> |
MPIcheckPoint(); |
213 |
|
|
214 |
< |
if( strcmp( foo, atoms[i]->getType() ) ){ |
215 |
< |
sprintf( painCave.errMsg, |
216 |
< |
"Initialize from file error. Atom %s at index %d " |
217 |
< |
"in file %s does not" |
218 |
< |
" match the BASS atom %s.\n", |
219 |
< |
foo, i, c_in_name, atoms[i]->getType() ); |
220 |
< |
painCave.isFatal = 1; |
221 |
< |
simError(); |
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 |
> |
sendError = 0; |
236 |
> |
mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,TAKE_THIS_TAG,MPI_COMM_WORLD); |
237 |
> |
|
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 |
> |
masterIndex++; |
260 |
> |
} |
261 |
|
} |
262 |
< |
|
263 |
< |
// get the positions |
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 |
+ |
// 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 |
+ |
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 |
+ |
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 postition x from %s\n" |
423 |
> |
"error in reading quaternion 1 from %s\n" |
424 |
|
"natoms = %d, index = %d\n", |
425 |
< |
c_in_name, n_atoms, i ); |
426 |
< |
painCave.isFatal = 1; |
400 |
< |
simError(); |
425 |
> |
c_in_name, n_atoms, atomIndex ); |
426 |
> |
return strdup( painCave.errMsg ); |
427 |
|
} |
428 |
< |
(void)sscanf( foo, "%lf", &rx ); |
429 |
< |
|
428 |
> |
q[1] = atof( foo ); |
429 |
> |
|
430 |
|
foo = strtok(NULL, " ,;\t"); |
431 |
|
if(foo == NULL){ |
432 |
|
sprintf( painCave.errMsg, |
433 |
< |
"error in reading postition y from %s\n" |
433 |
> |
"error in reading quaternion 2 from %s\n" |
434 |
|
"natoms = %d, index = %d\n", |
435 |
< |
c_in_name, n_atoms, i ); |
436 |
< |
painCave.isFatal = 1; |
411 |
< |
simError(); |
435 |
> |
c_in_name, n_atoms, atomIndex ); |
436 |
> |
return strdup( painCave.errMsg ); |
437 |
|
} |
438 |
< |
(void)sscanf( foo, "%lf", &ry ); |
439 |
< |
|
438 |
> |
q[2] = atof( foo ); |
439 |
> |
|
440 |
|
foo = strtok(NULL, " ,;\t"); |
441 |
|
if(foo == NULL){ |
442 |
|
sprintf( painCave.errMsg, |
443 |
< |
"error in reading postition z from %s\n" |
443 |
> |
"error in reading quaternion 3 from %s\n" |
444 |
|
"natoms = %d, index = %d\n", |
445 |
< |
c_in_name, n_atoms, i ); |
446 |
< |
painCave.isFatal = 1; |
422 |
< |
simError(); |
445 |
> |
c_in_name, n_atoms, atomIndex ); |
446 |
> |
return strdup( painCave.errMsg ); |
447 |
|
} |
448 |
< |
(void)sscanf( foo, "%lf", &rz ); |
449 |
< |
|
450 |
< |
// get the velocities |
451 |
< |
|
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 velocity x from %s\n" |
455 |
> |
"error in reading angular momentum jx from %s\n" |
456 |
|
"natoms = %d, index = %d\n", |
457 |
< |
c_in_name, n_atoms, i ); |
458 |
< |
painCave.isFatal = 1; |
435 |
< |
simError(); |
457 |
> |
c_in_name, n_atoms, atomIndex ); |
458 |
> |
return strdup( painCave.errMsg ); |
459 |
|
} |
460 |
< |
(void)sscanf( foo, "%lf", &vx ); |
461 |
< |
|
460 |
> |
jx = atof( foo ); |
461 |
> |
|
462 |
|
foo = strtok(NULL, " ,;\t"); |
463 |
|
if(foo == NULL){ |
464 |
|
sprintf( painCave.errMsg, |
465 |
< |
"error in reading velocity y from %s\n" |
465 |
> |
"error in reading angular momentum jy from %s\n" |
466 |
|
"natoms = %d, index = %d\n", |
467 |
< |
c_in_name, n_atoms, i ); |
468 |
< |
painCave.isFatal = 1; |
446 |
< |
simError(); |
467 |
> |
c_in_name, n_atoms, atomIndex ); |
468 |
> |
return strdup( painCave.errMsg ); |
469 |
|
} |
470 |
< |
(void)sscanf( foo, "%lf", &vy ); |
471 |
< |
|
470 |
> |
jy = atof(foo ); |
471 |
> |
|
472 |
|
foo = strtok(NULL, " ,;\t"); |
473 |
|
if(foo == NULL){ |
474 |
|
sprintf( painCave.errMsg, |
475 |
< |
"error in reading velocity z from %s\n" |
475 |
> |
"error in reading angular momentum jz from %s\n" |
476 |
|
"natoms = %d, index = %d\n", |
477 |
< |
c_in_name, n_atoms, i ); |
478 |
< |
painCave.isFatal = 1; |
457 |
< |
simError(); |
477 |
> |
c_in_name, n_atoms, atomIndex ); |
478 |
> |
return strdup( painCave.errMsg ); |
479 |
|
} |
480 |
< |
(void)sscanf( foo, "%lf", &vz ); |
460 |
< |
|
461 |
< |
|
462 |
< |
// get the quaternions |
463 |
< |
|
464 |
< |
if( atoms[i]->isDirectional() ){ |
480 |
> |
jz = atof( foo ); |
481 |
|
|
482 |
< |
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]; |
482 |
> |
dAtom = ( DirectionalAtom* )atoms[atomIndex]; |
483 |
|
|
484 |
< |
// check that the quaternion vector is normalized |
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]); |
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; |
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 ); |
494 |
> |
dAtom->setQ( q ); |
495 |
|
|
496 |
< |
// add the angular velocities |
496 |
> |
// add the angular velocities |
497 |
|
|
498 |
< |
dAtom->setJx( jx ); |
499 |
< |
dAtom->setJy( jy ); |
500 |
< |
dAtom->setJz( jz ); |
501 |
< |
} |
498 |
> |
dAtom->setJx( jx ); |
499 |
> |
dAtom->setJy( jy ); |
500 |
> |
dAtom->setJz( jz ); |
501 |
> |
} |
502 |
|
|
503 |
< |
// add the positions and velocities to the atom |
503 |
> |
// add the positions and velocities to the atom |
504 |
|
|
505 |
< |
atoms[i]->setX( rx ); |
506 |
< |
atoms[i]->setY( ry ); |
507 |
< |
atoms[i]->setZ( rz ); |
505 |
> |
atoms[atomIndex]->setX( rx ); |
506 |
> |
atoms[atomIndex]->setY( ry ); |
507 |
> |
atoms[atomIndex]->setZ( rz ); |
508 |
|
|
509 |
< |
atoms[i]->set_vx( vx ); |
510 |
< |
atoms[i]->set_vy( vy ); |
511 |
< |
atoms[i]->set_vz( vz ); |
575 |
< |
|
576 |
< |
} |
577 |
< |
#endif |
578 |
< |
} |
509 |
> |
atoms[atomIndex]->set_vx( vx ); |
510 |
> |
atoms[atomIndex]->set_vy( vy ); |
511 |
> |
atoms[atomIndex]->set_vz( vz ); |
512 |
|
|
513 |
< |
char* IntitializeFromFile::parseDumpLine(char* readLine); |
513 |
> |
return NULL; |
514 |
> |
} |