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 |
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[2000]; |
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 |
|
|
71 |
– |
double rx, ry, rz; // position place holders |
72 |
– |
double vx, vy, vz; // velocity placeholders |
73 |
– |
double q[4]; // the quaternions |
74 |
– |
double jx, jy, jz; // angular velocity placeholders; |
75 |
– |
double qSqr, qLength; // needed to normalize the quaternion vector. |
75 |
|
|
76 |
< |
entry_plug = the_entry_plug |
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; |
123 |
|
simError(); |
124 |
|
} |
125 |
|
|
123 |
– |
foo = strtok(read_buffer, " ,;\t"); |
126 |
|
|
127 |
< |
// check the atom name to the current atom |
128 |
< |
|
129 |
< |
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() ); |
127 |
> |
parseErr = parseDumpLine( read_buffer, i ); |
128 |
> |
if( parseErr != NULL ){ |
129 |
> |
strcpy( painCave.errMsg, parseErr ); |
130 |
|
painCave.isFatal = 1; |
131 |
|
simError(); |
132 |
< |
} |
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 |
< |
|
132 |
> |
} |
133 |
|
} |
134 |
|
|
135 |
|
|
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 |
|
|
330 |
– |
|
147 |
|
if (worldRank == 0) { |
148 |
|
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
149 |
|
if( eof_test == NULL ){ |
153 |
|
simError(); |
154 |
|
} |
155 |
|
|
156 |
< |
(void)sscanf(read_buffer, "%d", &n_atoms); |
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 != entry_plug->n_atoms ){ |
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", |
179 |
|
painCave.isFatal = 1; |
180 |
|
simError(); |
181 |
|
} |
182 |
< |
} |
183 |
< |
for( i=0; i < n_atoms; i++){ |
182 |
> |
|
183 |
> |
// Read Proc 0 share of the xyz file... |
184 |
> |
masterIndex = 0; |
185 |
> |
for( i=0; i <= mpiSim->getMyAtomEnd(); i++){ |
186 |
|
|
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(); |
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 |
> |
|
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(read_buffer, " ,;\t"); |
209 |
< |
|
210 |
< |
// check the atom name to the current atom |
208 |
> |
sprintf(checkPointMsg, |
209 |
> |
"Node 0 has successfully read positions from input file."); |
210 |
> |
mpiCheckPoint(); |
211 |
|
|
212 |
< |
if( strcmp( foo, atoms[i]->getType() ) ){ |
213 |
< |
sprintf( painCave.errMsg, |
214 |
< |
"Initialize from file error. Atom %s at index %d " |
215 |
< |
"in file %s does not" |
216 |
< |
" match the BASS atom %s.\n", |
217 |
< |
foo, i, c_in_name, atoms[i]->getType() ); |
218 |
< |
painCave.isFatal = 1; |
219 |
< |
simError(); |
212 |
> |
for (procIndex = 1; procIndex < entryPlug->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 |
> |
sendError = 0; |
234 |
> |
mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,MPI_ANY_TAG,MPI_COMM_WORLD); |
235 |
> |
|
236 |
> |
for ( i = nodeAtomStart; i <= nodeAtomEnd, 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 |
< |
// get the positions |
260 |
> |
|
261 |
> |
|
262 |
> |
else if(worldRank == procIndex){ |
263 |
> |
nodeAtomStart = mpiSim->getMyAtomStart(); |
264 |
> |
nodeAtomEnd = 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 |
+ |
// 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 |
+ |
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 |
+ |
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 postition x from %s\n" |
421 |
> |
"error in reading quaternion 1 from %s\n" |
422 |
|
"natoms = %d, index = %d\n", |
423 |
< |
c_in_name, n_atoms, i ); |
424 |
< |
painCave.isFatal = 1; |
400 |
< |
simError(); |
423 |
> |
c_in_name, n_atoms, atomIndex ); |
424 |
> |
return strdup( painCave.errMsg ); |
425 |
|
} |
426 |
< |
(void)sscanf( foo, "%lf", &rx ); |
427 |
< |
|
426 |
> |
q[1] = atof( foo ); |
427 |
> |
|
428 |
|
foo = strtok(NULL, " ,;\t"); |
429 |
|
if(foo == NULL){ |
430 |
|
sprintf( painCave.errMsg, |
431 |
< |
"error in reading postition y from %s\n" |
431 |
> |
"error in reading quaternion 2 from %s\n" |
432 |
|
"natoms = %d, index = %d\n", |
433 |
< |
c_in_name, n_atoms, i ); |
434 |
< |
painCave.isFatal = 1; |
411 |
< |
simError(); |
433 |
> |
c_in_name, n_atoms, atomIndex ); |
434 |
> |
return strdup( painCave.errMsg ); |
435 |
|
} |
436 |
< |
(void)sscanf( foo, "%lf", &ry ); |
437 |
< |
|
436 |
> |
q[2] = atof( foo ); |
437 |
> |
|
438 |
|
foo = strtok(NULL, " ,;\t"); |
439 |
|
if(foo == NULL){ |
440 |
|
sprintf( painCave.errMsg, |
441 |
< |
"error in reading postition z from %s\n" |
441 |
> |
"error in reading quaternion 3 from %s\n" |
442 |
|
"natoms = %d, index = %d\n", |
443 |
< |
c_in_name, n_atoms, i ); |
444 |
< |
painCave.isFatal = 1; |
422 |
< |
simError(); |
443 |
> |
c_in_name, n_atoms, atomIndex ); |
444 |
> |
return strdup( painCave.errMsg ); |
445 |
|
} |
446 |
< |
(void)sscanf( foo, "%lf", &rz ); |
447 |
< |
|
448 |
< |
// get the velocities |
449 |
< |
|
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 velocity x from %s\n" |
453 |
> |
"error in reading angular momentum jx from %s\n" |
454 |
|
"natoms = %d, index = %d\n", |
455 |
< |
c_in_name, n_atoms, i ); |
456 |
< |
painCave.isFatal = 1; |
435 |
< |
simError(); |
455 |
> |
c_in_name, n_atoms, atomIndex ); |
456 |
> |
return strdup( painCave.errMsg ); |
457 |
|
} |
458 |
< |
(void)sscanf( foo, "%lf", &vx ); |
459 |
< |
|
458 |
> |
jx = atof( foo ); |
459 |
> |
|
460 |
|
foo = strtok(NULL, " ,;\t"); |
461 |
|
if(foo == NULL){ |
462 |
|
sprintf( painCave.errMsg, |
463 |
< |
"error in reading velocity y from %s\n" |
463 |
> |
"error in reading angular momentum jy from %s\n" |
464 |
|
"natoms = %d, index = %d\n", |
465 |
< |
c_in_name, n_atoms, i ); |
466 |
< |
painCave.isFatal = 1; |
446 |
< |
simError(); |
465 |
> |
c_in_name, n_atoms, atomIndex ); |
466 |
> |
return strdup( painCave.errMsg ); |
467 |
|
} |
468 |
< |
(void)sscanf( foo, "%lf", &vy ); |
469 |
< |
|
468 |
> |
jy = atof(foo ); |
469 |
> |
|
470 |
|
foo = strtok(NULL, " ,;\t"); |
471 |
|
if(foo == NULL){ |
472 |
|
sprintf( painCave.errMsg, |
473 |
< |
"error in reading velocity z from %s\n" |
473 |
> |
"error in reading angular momentum jz from %s\n" |
474 |
|
"natoms = %d, index = %d\n", |
475 |
< |
c_in_name, n_atoms, i ); |
476 |
< |
painCave.isFatal = 1; |
457 |
< |
simError(); |
475 |
> |
c_in_name, n_atoms, atomIndex ); |
476 |
> |
return strdup( painCave.errMsg ); |
477 |
|
} |
478 |
< |
(void)sscanf( foo, "%lf", &vz ); |
460 |
< |
|
461 |
< |
|
462 |
< |
// get the quaternions |
463 |
< |
|
464 |
< |
if( atoms[i]->isDirectional() ){ |
478 |
> |
jz = atof( foo ); |
479 |
|
|
480 |
< |
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]; |
480 |
> |
dAtom = ( DirectionalAtom* )atoms[atomIndex]; |
481 |
|
|
482 |
< |
// check that the quaternion vector is normalized |
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]); |
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; |
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 ); |
492 |
> |
dAtom->setQ( q ); |
493 |
|
|
494 |
< |
// add the angular velocities |
494 |
> |
// add the angular velocities |
495 |
|
|
496 |
< |
dAtom->setJx( jx ); |
497 |
< |
dAtom->setJy( jy ); |
498 |
< |
dAtom->setJz( jz ); |
499 |
< |
} |
496 |
> |
dAtom->setJx( jx ); |
497 |
> |
dAtom->setJy( jy ); |
498 |
> |
dAtom->setJz( jz ); |
499 |
> |
} |
500 |
|
|
501 |
< |
// add the positions and velocities to the atom |
501 |
> |
// add the positions and velocities to the atom |
502 |
|
|
503 |
< |
atoms[i]->setX( rx ); |
504 |
< |
atoms[i]->setY( ry ); |
505 |
< |
atoms[i]->setZ( rz ); |
503 |
> |
atoms[atomIndex]->setX( rx ); |
504 |
> |
atoms[atomIndex]->setY( ry ); |
505 |
> |
atoms[atomIndex]->setZ( rz ); |
506 |
|
|
507 |
< |
atoms[i]->set_vx( vx ); |
508 |
< |
atoms[i]->set_vy( vy ); |
509 |
< |
atoms[i]->set_vz( vz ); |
575 |
< |
|
576 |
< |
} |
577 |
< |
#endif |
578 |
< |
} |
507 |
> |
atoms[atomIndex]->set_vx( vx ); |
508 |
> |
atoms[atomIndex]->set_vy( vy ); |
509 |
> |
atoms[atomIndex]->set_vz( vz ); |
510 |
|
|
511 |
< |
char* IntitializeFromFile::parseDumpLine(char* readLine); |
511 |
> |
return NULL; |
512 |
> |
} |