ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/mdtools/md_code/InitializeFromFile.cpp
(Generate patch)

Comparing trunk/mdtools/md_code/InitializeFromFile.cpp (file contents):
Revision 11 by mmeineke, Tue Jul 9 18:40:59 2002 UTC vs.
Revision 260 by chuckv, Fri Jan 31 21:04:27 2003 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines