ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/DumpReader.cpp
(Generate patch)

Comparing trunk/OOPSE/libmdtools/DumpReader.cpp (file contents):
Revision 847 by mmeineke, Fri Oct 31 18:28:52 2003 UTC vs.
Revision 1130 by tim, Thu Apr 22 14:55:17 2004 UTC

# Line 1 | Line 1
1 + #define _LARGEFILE_SOURCE64
2   #define _FILE_OFFSET_BITS 64
3  
4   #include <sys/types.h>
# Line 21 | Line 22 | namespace dumpRead{
22   #define TAKE_THIS_TAG_INT 1
23   #endif // is_mpi
24  
24 namespace dumpRead{
25  
26 < #ifdef IS_MPI
27 <  void nodeZeroError( void );
28 <  void anonymousNodeDie( void );
29 < #endif // is_mpi
30 <  
31 < }
26 > DumpReader :: DumpReader(const char *in_name ){
27  
33 using namespace dumpRead;
34
35
36 DumpReader :: DumpReader( char *in_name ){
37
28    isScanned = false;
39  headFP = new FilePos;
29  
30   #ifdef IS_MPI
31    if (worldRank == 0) {
# Line 50 | Line 39 | DumpReader :: DumpReader( char *in_name ){
39      simError();
40    }
41    
42 <  strcpy( inName, in_name);
42 >  inFileName = in_name;
43   #ifdef IS_MPI
44    }
45    strcpy( checkPointMsg, "Dump file opened for reading successfully." );
# Line 63 | Line 52 | DumpReader :: ~DumpReader( ){
52   #ifdef IS_MPI
53    if (worldRank == 0) {
54   #endif
55 +  vector<fpos_t*>::iterator i;
56 +
57    int error;
58    error = fclose( inFile );
59    if( error ){
60      sprintf( painCave.errMsg,
61 <             "Error closing %s\n", inName );
61 >             "Error closing %s\n", inFileName.c_str());
62      simError();
63    }
64 +
65 +  for(i = framePos.begin(); i != framePos.end(); ++i)
66 +    delete *i;
67 +  framePos.clear();
68 +  
69   #ifdef IS_MPI
70    }
71    strcpy( checkPointMsg, "Dump file closed successfully." );
# Line 81 | Line 77 | int DumpReader::getNframes( void ){
77  
78   int DumpReader::getNframes( void ){
79  
80 <  if( !isScanned ) scanFile();
81 <  return nFrames;
80 >  if( !isScanned )
81 >    scanFile();
82 >  return framePos.size();
83   }
84  
85   void DumpReader::scanFile( void ){
# Line 95 | Line 92 | void DumpReader::scanFile( void ){
92    fpos_t *currPos;
93    double time;
94  
98  FilePos *currFP;
95  
96  
97   #ifdef IS_MPI
# Line 111 | Line 107 | void DumpReader::scanFile( void ){
107      if( feof( inFile ) ){
108        sprintf( painCave.errMsg,
109                 "File \"%s\" ended unexpectedly at line %d\n",
110 <               inName,
110 >               inFileName.c_str(),
111                 lineNum );
112        painCave.isFatal = 1;
113        simError();
114      }
115 <    
120 <    nFrames = 0;
115 >
116      while( !feof( inFile ) ){
117 +      
118 +      framePos.push_back(currPos);
119  
123      headFP->add( currPos );
124      nFrames++;
125
120        i = atoi(readBuffer);
121        
122        fgets( readBuffer, sizeof( readBuffer ), inFile );
# Line 130 | Line 124 | void DumpReader::scanFile( void ){
124        if( feof( inFile ) ){
125          sprintf( painCave.errMsg,
126                   "File \"%s\" ended unexpectedly at line %d\n",
127 <                 inName,
127 >                 inFileName.c_str(),
128                   lineNum );
129          painCave.isFatal = 1;
130          simError();
131        }
132 <      
139 < //       if(outTime){
140 < //      foo = strtok( readBuffer, " ,;\t" );
141 < //      time = atof( foo );
142 < //       }
143 <      
132 >            
133        for(j=0; j<i; j++){
134          
135          fgets( readBuffer, sizeof( readBuffer ), inFile );
# Line 149 | Line 138 | void DumpReader::scanFile( void ){
138            sprintf( painCave.errMsg,
139                     "File \"%s\" ended unexpectedly at line %d,"
140                     " with atom %d\n",
141 <                   inName,
141 >                   inFileName.c_str(),
142                     lineNum,
143                     j );
144            painCave.isFatal = 1;
# Line 166 | Line 155 | void DumpReader::scanFile( void ){
155      
156      delete currPos;
157      rewind( inFile );
158 <    
170 <    frameStart = new FilePos*[nFrames];
171 <    currFP = headFP;
172 <    for(i=0; i<nFrames; i++){
173 <      
174 <      currFP = currFP->getNext();
175 <      if( currFP == NULL ){
176 <        sprintf( painCave.errMsg,
177 <                 "DumpReader error: scanFile FilePos mismatch at "
178 <                 "nFrames = %d\n",
179 <                 i );
180 <        painCave.isFatal = 1;
181 <        simError();
182 <      }
183 <      
184 <      frameStart[i] = currFP;
185 <    }
186 <
158 >    
159      isScanned = true;
160  
161   #ifdef IS_MPI
# Line 204 | Line 176 | void DumpReader :: readSet( int whichFrame ){
176  
177   void DumpReader :: readSet( int whichFrame ){
178  
179 <  int i, j, done, which_node, which_atom; // loop counter
179 >   int i, j;
180  
209  const int BUFFERSIZE = 2000; // size of the read buffer
210  int n_atoms; // the number of atoms
211  char read_buffer[BUFFERSIZE]; //the line buffer for reading
181   #ifdef IS_MPI
182 <  char send_buffer[BUFFERSIZE];
183 < #endif
182 >  int done, which_node, which_atom; // loop counter
183 > #endif //is_mpi
184  
185 <  char *eof_test; // ptr to see when we reach the end of the file
185 >  const int BUFFERSIZE = 2000; // size of the read buffer
186 >  int nTotObjs; // the number of atoms
187 >  char read_buffer[BUFFERSIZE]; //the line buffer for reading
188 >
189 >  char *eof_test; // ptr to see when we reach the end of the file
190    char *parseErr;
218  int procIndex;
219  double boxMat[9];
220  double theBoxMat3[3][3];
221  double time;
191  
192 <  fpos_t *framePos;
224 <  
225 < #ifndef IS_MPI
226 <  
227 <  framePos = frameStart[whichFrame]->getPos();
192 >  vector<StuntDouble*> integrableObjects;
193  
229  
194  
195 + #ifndef IS_MPI
196  
197 +  fsetpos(inFile, framePos[whichFrame]);
198    eof_test = fgets(read_buffer, sizeof(read_buffer), inFile);
199    if( eof_test == NULL ){
200      sprintf( painCave.errMsg,
201               "DumpReader error: error reading 1st line of \"%s\"\n",
202 <             inName );
202 >             inFileName.c_str() );
203      painCave.isFatal = 1;
204      simError();
205    }
240  
241  n_atoms = atoi( read_buffer );
206  
207 <  Atom **atoms = simnfo->atoms;
244 <  DirectionalAtom* dAtom;
207 >  nTotObjs = atoi( read_buffer );
208  
209 <  if( n_atoms != simnfo->n_atoms ){
209 >  if( nTotObjs != simnfo->getTotIntegrableObjects() ){
210      sprintf( painCave.errMsg,
211               "DumpReader error. %s n_atoms, %d, "
212               "does not match the BASS file's n_atoms, %d.\n",
213 <             inName, n_atoms, simnfo->n_atoms );
213 >             inFileName.c_str(), nTotObjs, simnfo->getTotIntegrableObjects());
214      painCave.isFatal = 1;
215      simError();
216    }
217 <  
218 <  //read the box mat from the comment line
219 <  
217 >
218 >  //read the box mat from the comment line
219 >
220    eof_test = fgets(read_buffer, sizeof(read_buffer), inFile);
221    if(eof_test == NULL){
222      sprintf( painCave.errMsg,
223 <             "error in reading commment in %s\n", inName);
223 >             "error in reading commment in %s\n", inFileName.c_str());
224      painCave.isFatal = 1;
225      simError();
226    }
227  
228 <  parseErr = parseCommentLine( read_buffer, time, boxMat );
228 >  parseErr = parseCommentLine( read_buffer, simnfo);
229    if( parseErr != NULL ){
230      strcpy( painCave.errMsg, parseErr );
231      painCave.isFatal = 1;
232      simError();
233    }
234  
235 <  simnfo->setTime( time );
273 <  
274 <  for(i=0;i<3;i++)
275 <    for(j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i];
276 <  
235 >  //parse dump lines
236  
237 <  simnfo->setBoxM( theBoxMat3 );
279 <  
237 >  for( i=0; i < simnfo->n_mol; i++){
238  
239 <  for( i=0; i < n_atoms; i++){
282 <    
283 <    eof_test = fgets(read_buffer, sizeof(read_buffer), inFile);
284 <    if(eof_test == NULL){
285 <      sprintf(painCave.errMsg,
286 <              "error in reading file %s\n"
287 <              "natoms  = %d; index = %d\n"
288 <              "error reading the line from the file.\n",
289 <              inName, n_atoms, i );
290 <      painCave.isFatal = 1;
291 <      simError();
292 <    }
239 >    integrableObjects = (simnfo->molecules[i]).getIntegrableObjects();
240  
241 <    
242 <    parseErr = parseDumpLine( read_buffer, i );
243 <    if( parseErr != NULL ){
244 <      strcpy( painCave.errMsg, parseErr );
245 <      painCave.isFatal = 1;
246 <      simError();
241 >    for(j = 0; j < integrableObjects.size(); j++){
242 >
243 >      eof_test = fgets(read_buffer, sizeof(read_buffer), inFile);
244 >      if(eof_test == NULL){
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 >              inFileName.c_str(), nTotObjs, i );
250 >        painCave.isFatal = 1;
251 >        simError();
252 >      }
253 >      
254 >      parseErr = parseDumpLine( read_buffer, integrableObjects[j]);
255 >      if( parseErr != NULL ){
256 >        strcpy( painCave.errMsg, parseErr );
257 >        painCave.isFatal = 1;
258 >        simError();
259 >      }
260      }
261    }
262  
303
263    // MPI Section of code..........
264   #else //IS_MPI
265  
# Line 309 | Line 268 | void DumpReader :: readSet( int whichFrame ){
268  
269    int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone
270    int haveError;
271 <  
271 >
272    MPI_Status istatus;
273 <  int *AtomToProcMap = mpiSim->getAtomToProcMap();
273 >  int *MolToProcMap = mpiSim->getMolToProcMap();
274 >  int localIndex;
275 >  int nCurObj;
276 >  int nitems;
277  
278 <  
278 >  nTotObjs = simnfo->getTotIntegrableObjects();
279    haveError = 0;
280    if (worldRank == 0) {
281 +     fsetpos(inFile,  framePos[whichFrame]);
282  
283      eof_test = fgets(read_buffer, sizeof(read_buffer), inFile);
284      if( eof_test == NULL ){
285        sprintf( painCave.errMsg,
286 <               "Error reading 1st line of %d \n ",inName);
286 >               "Error reading 1st line of %s \n ",inFileName.c_str());
287        haveError = 1;
288        simError();
289      }
290 <    
291 <    n_atoms = atoi( read_buffer );
292 <    
293 <    Atom **atoms = simnfo->atoms;
331 <    DirectionalAtom* dAtom;
332 <
333 <    // Check to see that the number of atoms in the intial configuration file is the
290 >
291 >    nitems = atoi( read_buffer );
292 >
293 >    // Check to see that the number of integrable objects  in the intial configuration file is the
294      // same as declared in simBass.
295 <    
296 <    if( n_atoms != mpiSim->getTotAtoms() ){
295 >
296 >    if( nTotObjs != nitems){
297        sprintf( painCave.errMsg,
298 <               "Initialize from File error. %s n_atoms, %d, "
298 >               "DumpReadererror. %s n_atoms, %d, "
299                 "does not match the BASS file's n_atoms, %d.\n",
300 <               inName, n_atoms, simnfo->n_atoms );
300 >               inFileName.c_str(), nTotObjs, simnfo->getTotIntegrableObjects());
301        haveError= 1;
302        simError();
303      }
304 <    
305 <    //read the time and boxMat from the comment line
306 <    
304 >
305 >    //read the boxMat from the comment line
306 >
307      eof_test = fgets(read_buffer, sizeof(read_buffer), inFile);
308      if(eof_test == NULL){
309        sprintf( painCave.errMsg,
310 <               "error in reading commment in %s\n", inName);
310 >               "error in reading commment in %s\n", inFileName.c_str());
311        haveError = 1;
312        simError();
313      }
314 <    
315 <    parseErr = parseCommentLine( read_buffer, time, boxMat );
314 >
315 >    //Every single processor will parse the comment line by itself
316 >    //By using this way, we might lose some efficiency, but if we want to add
317 >    //more parameters into comment line, we only need to modify function
318 >    //parseCommentLine
319 >
320 >    MPI_Bcast(read_buffer, BUFFERSIZE, MPI_CHAR, 0, MPI_COMM_WORLD);
321 >
322 >    parseErr = parseCommentLine( read_buffer, simnfo);
323 >
324      if( parseErr != NULL ){
325        strcpy( painCave.errMsg, parseErr );
326        haveError = 1;
327        simError();
328      }
329  
330 <    MPI_Bcast(&time, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD );
331 <    
332 <    MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD );
333 <    
334 <    if(haveError) nodeZeroError();
335 <    
336 <    for (i=0 ; i < mpiSim->getTotAtoms(); i++) {
337 <      
338 <      eof_test = fgets(read_buffer, sizeof(read_buffer), inFile);
339 <      if(eof_test == NULL){
340 <        sprintf(painCave.errMsg,
373 <                "error in reading file %s\n"
374 <                "natoms  = %d; index = %d\n"
375 <                "error reading the line from the file.\n",
376 <                inName, n_atoms, i );
377 <        haveError= 1;
378 <        simError();
330 >    for (i=0 ; i < mpiSim->getTotNmol(); i++) {
331 >      which_node = MolToProcMap[i];
332 >      if(which_node == 0){
333 >       //molecules belong to master node
334 >
335 >      localIndex = mpiSim->getGlobalToLocalMol(i);
336 >
337 >      if(localIndex == -1) {
338 >        strcpy(painCave.errMsg, "Molecule not found on node 0!");
339 >        haveError = 1;
340 >        simError();
341        }
380    
381      if(haveError) nodeZeroError();
342  
343 <      // Get the Node number which wants this atom:
344 <      which_node = AtomToProcMap[i];    
345 <      if (which_node == 0) {
346 <        parseErr = parseDumpLine( read_buffer, i );
347 <        if( parseErr != NULL ){
348 <          strcpy( painCave.errMsg, parseErr );
349 <          haveError = 1;
350 <          simError();
351 <        }    
352 <        if(haveError) nodeZeroError();
353 <      }
343 >       integrableObjects = (simnfo->molecules[localIndex]).getIntegrableObjects();
344 >       for(j=0; j < integrableObjects.size(); j++){
345 >        
346 >          eof_test = fgets(read_buffer, sizeof(read_buffer), inFile);
347 >          if(eof_test == NULL){
348 >                sprintf(painCave.errMsg,
349 >                    "error in reading file %s\n"
350 >                    "natoms  = %d; index = %d\n"
351 >                    "error reading the line from the file.\n",
352 >                    inFileName.c_str(), nTotObjs, i );
353 >                haveError= 1;
354 >                simError();
355 >          }
356 >          
357 >          if(haveError) nodeZeroError();
358 >
359 >          parseDumpLine(read_buffer, integrableObjects[j]);
360 >          
361 >       }
362 >
363 >
364 >      }
365 >      else{
366 >      //molecule belongs to slave nodes
367 >
368 >        MPI_Recv(&nCurObj, 1, MPI_INT, which_node,
369 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
370        
371 <      else {
372 <      
373 <        myStatus = 1;
374 <        MPI_Send(&myStatus, 1, MPI_INT, which_node,
375 <                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
376 <        MPI_Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node,
377 <                 TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD);
378 <        MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT,
379 <                 MPI_COMM_WORLD);
380 <        MPI_Recv(&myStatus, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT,
381 <                 MPI_COMM_WORLD, &istatus);
382 <        
383 <        if(!myStatus) nodeZeroError();
371 >       for(j=0; j < nCurObj; j++){
372 >        
373 >          eof_test = fgets(read_buffer, sizeof(read_buffer), inFile);
374 >          if(eof_test == NULL){
375 >                sprintf(painCave.errMsg,
376 >                    "error in reading file %s\n"
377 >                    "natoms  = %d; index = %d\n"
378 >                    "error reading the line from the file.\n",
379 >                    inFileName.c_str(), nTotObjs, i );
380 >                haveError= 1;
381 >                simError();
382 >          }
383 >          
384 >          if(haveError) nodeZeroError();
385 >
386 >            MPI_Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node,
387 >                      TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD);
388 >          
389 >       }
390 >
391        }
392 +      
393      }
410    myStatus = -1;
411    for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
412      MPI_Send( &myStatus, 1, MPI_INT, j,
413                TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
414    }
394      
395 <  } else {
396 <    
397 <    MPI_Bcast(&time, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
398 <    MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD);
395 >  }
396 >  else{
397 >  //actions taken at slave nodes
398 >    MPI_Bcast(read_buffer, BUFFERSIZE, MPI_CHAR, 0, MPI_COMM_WORLD);
399  
400 <    done = 0;
422 <    while (!done) {
400 >    parseErr = parseCommentLine( read_buffer, simnfo);
401  
402 <      MPI_Recv(&myStatus, 1, MPI_INT, 0,
403 <               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
402 >    if( parseErr != NULL ){
403 >      strcpy( painCave.errMsg, parseErr );
404 >      haveError = 1;
405 >      simError();
406 >    }
407 >  
408 >    for (i=0 ; i < mpiSim->getTotNmol(); i++) {
409 >      which_node = MolToProcMap[i];
410        
411 <      if(!myStatus) anonymousNodeDie();
411 >      if(which_node == worldRank){
412 >      //molecule with global index i belongs to this processor
413        
414 <      if(myStatus < 0) break;
414 >        localIndex = mpiSim->getGlobalToLocalMol(i);
415  
416 <      MPI_Recv(read_buffer, BUFFERSIZE, MPI_CHAR, 0,
417 <               TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus);
418 <      MPI_Recv(&which_atom, 1, MPI_INT, 0,
419 <               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
420 <      
421 <      myStatus = 1;
422 <      parseErr = parseDumpLine( read_buffer, which_atom );
423 <      if( parseErr != NULL ){
424 <        strcpy( painCave.errMsg, parseErr );
425 <        myStatus = 0;;
426 <        simError();
416 >        if(localIndex == -1) {
417 >          sprintf(painCave.errMsg, "Molecule not found on node %d\n", worldRank);
418 >          haveError = 1;
419 >          simError();
420 >        }
421 >
422 >        integrableObjects = (simnfo->molecules[localIndex]).getIntegrableObjects();        
423 >
424 >        nCurObj = integrableObjects.size();
425 >        
426 >        MPI_Send(&nCurObj, 1, MPI_INT, 0,
427 >                        TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
428 >
429 >        for(j = 0; j < integrableObjects.size(); j++){
430 >
431 >          MPI_Recv(read_buffer, BUFFERSIZE, MPI_CHAR, 0,
432 >                              TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus);
433 >
434 >          parseErr = parseDumpLine(read_buffer, integrableObjects[j]);
435 >
436 >          if( parseErr != NULL ){
437 >                strcpy( painCave.errMsg, parseErr );
438 >                simError();
439 >          }
440 >
441 >        }
442 >          
443        }
444        
444      MPI_Send( &myStatus, 1, MPI_INT, 0,
445                TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
446      
445      }
446 +
447    }
449    
450 // last  thing last, enable  fatalities.
451  painCave.isEventLoop = 0;
448  
453  simnfo->setTime( time );
454
455  for(i=0;i<3;i++)
456    for(j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i];
457
458  simnfo->setBoxM( theBoxMat3 );
459
460  
449   #endif
450   }
451  
452 < char* DumpReader::parseDumpLine(char* readLine, int globalIndex){
452 > char* DumpReader::parseDumpLine(char* readLine, StuntDouble* sd){
453  
454 <  char *foo; // the pointer to the current string token
455 <  
454 >  char *foo; // the pointer to the current string token
455 >
456    double pos[3]; // position place holders
457    double vel[3]; // velocity placeholders
458    double q[4]; // the quaternions
459 <  double jx, jy, jz; // angular velocity placeholders;
459 >  double ji[3]; // angular velocity placeholders;
460    double qSqr, qLength; // needed to normalize the quaternion vector.
473  
474  Atom **atoms = simnfo->atoms;
475  DirectionalAtom* dAtom;
476  
477  int j, n_atoms, atomIndex;
461  
462 < #ifdef IS_MPI
463 <  n_atoms = mpiSim->getTotAtoms();
481 <  atomIndex=-1;        
482 <  for (j=0; j < mpiSim->getMyNlocal(); j++) {
483 <    if (atoms[j]->getGlobalIndex() == globalIndex) atomIndex = j;
484 <  }
485 <  if (atomIndex == -1) {
486 <    sprintf( painCave.errMsg,
487 <             "Initialize from file error. Atom at index %d "
488 <             "in file %s does not exist on processor %d .\n",
489 <             globalIndex, inName, mpiSim->getMyNode() );
490 <    return strdup( painCave.errMsg );
491 <  }  
492 < #else
493 <  n_atoms = simnfo->n_atoms;
494 <  atomIndex = globalIndex;
495 < #endif // is_mpi
462 >
463 >  // set the string tokenizer
464  
497  // set the string tokenizer
498  
465    foo = strtok(readLine, " ,;\t");
466 <  
466 >
467    // check the atom name to the current atom
468 <  
469 <  if( strcmp( foo, atoms[atomIndex]->getType() ) ){
468 >
469 >  if( strcmp( foo, sd->getType() ) ){
470      sprintf( painCave.errMsg,
471 <             "Initialize from file error. Atom %s at index %d "
506 <             "in file %s does not"
471 >             "DumpReader error.  Does not"
472               " match the BASS atom %s.\n",
473 <             foo, atomIndex, inName, atoms[atomIndex]->getType() );
473 >             sd->getType() );
474      return strdup( painCave.errMsg );
475    }
476 <    
476 >
477    // get the positions
478  
479    foo = strtok(NULL, " ,;\t");
480    if(foo == NULL){
481      sprintf( painCave.errMsg,
482 <             "error in reading postition x from %s\n"
483 <             "natoms  = %d, index = %d\n",
519 <             inName, n_atoms, atomIndex );
482 >             "error in reading postition x from %s\n",
483 >             inFileName.c_str());
484      return strdup( painCave.errMsg );
485    }
486    pos[0] = atof( foo );
487 <  
487 >
488    foo = strtok(NULL, " ,;\t");
489    if(foo == NULL){
490      sprintf( painCave.errMsg,
491 <             "error in reading postition y from %s\n"
492 <             "natoms  = %d, index = %d\n",
529 <             inName, n_atoms, atomIndex );
491 >             "error in reading postition y from %s\n",
492 >             inFileName.c_str());
493      return strdup( painCave.errMsg );
494    }
495    pos[1] = atof( foo );
496 <    
496 >
497    foo = strtok(NULL, " ,;\t");
498    if(foo == NULL){
499      sprintf( painCave.errMsg,
500 <             "error in reading postition z from %s\n"
501 <             "natoms  = %d, index = %d\n",
539 <             inName, n_atoms, atomIndex );
500 >             "error in reading postition z from %s\n",
501 >             inFileName.c_str());
502      return strdup( painCave.errMsg );
503    }
504 <  pos[2] = atof( foo );    
504 >  pos[2] = atof( foo );
505  
506  
507    // get the velocities
# Line 547 | Line 509 | char* DumpReader::parseDumpLine(char* readLine, int gl
509    foo = strtok(NULL, " ,;\t");
510    if(foo == NULL){
511      sprintf( painCave.errMsg,
512 <             "error in reading velocity x from %s\n"
513 <             "natoms  = %d, index = %d\n",
552 <             inName, n_atoms, atomIndex );
512 >             "error in reading velocity x from %s\n",
513 >             inFileName.c_str() );
514      return strdup( painCave.errMsg );
515    }
516    vel[0] = atof( foo );
517 <    
517 >
518    foo = strtok(NULL, " ,;\t");
519    if(foo == NULL){
520      sprintf( painCave.errMsg,
521 <             "error in reading velocity y from %s\n"
522 <             "natoms  = %d, index = %d\n",
562 <             inName, n_atoms, atomIndex );
521 >             "error in reading velocity x from %s\n",
522 >             inFileName.c_str() );
523      return strdup( painCave.errMsg );
524    }
525    vel[1] = atof( foo );
526 <    
526 >
527    foo = strtok(NULL, " ,;\t");
528    if(foo == NULL){
529      sprintf( painCave.errMsg,
530 <             "error in reading velocity z from %s\n"
531 <             "natoms  = %d, index = %d\n",
572 <             inName, n_atoms, atomIndex );
530 >             "error in reading velocity x from %s\n",
531 >             inFileName.c_str() );
532      return strdup( painCave.errMsg );
533    }
534    vel[2] = atof( foo );
535 <    
536 <    
535 >
536 >
537 >  // add the positions and velocities to the atom
538 >
539 >  sd->setPos( pos );
540 >  sd->setVel( vel );
541 >
542 >  if (!sd->isDirectional())
543 >    return NULL;
544 >
545    // get the quaternions
546 <    
547 <  if( atoms[atomIndex]->isDirectional() ){
548 <      
546 >
547 >  if( sd->isDirectional() ){
548 >
549      foo = strtok(NULL, " ,;\t");
550      if(foo == NULL){
551 <      sprintf(painCave.errMsg,
552 <              "error in reading quaternion 0 from %s\n"
553 <              "natoms  = %d, index = %d\n",
587 <              inName, n_atoms, atomIndex );
551 >      sprintf( painCave.errMsg,
552 >                     "error in reading velocity x from %s\n",
553 >                      inFileName.c_str() );
554        return strdup( painCave.errMsg );
555      }
556      q[0] = atof( foo );
557 <      
557 >
558      foo = strtok(NULL, " ,;\t");
559      if(foo == NULL){
560        sprintf( painCave.errMsg,
561 <               "error in reading quaternion 1 from %s\n"
562 <               "natoms  = %d, index = %d\n",
597 <               inName, n_atoms, atomIndex );
561 >                     "error in reading velocity x from %s\n",
562 >                      inFileName.c_str() );
563        return strdup( painCave.errMsg );
564      }
565      q[1] = atof( foo );
566 <      
566 >
567      foo = strtok(NULL, " ,;\t");
568      if(foo == NULL){
569        sprintf( painCave.errMsg,
570 <               "error in reading quaternion 2 from %s\n"
571 <               "natoms  = %d, index = %d\n",
607 <               inName, n_atoms, atomIndex );
570 >                     "error in reading velocity x from %s\n",
571 >                      inFileName.c_str() );
572        return strdup( painCave.errMsg );
573      }
574      q[2] = atof( foo );
575 <      
575 >
576      foo = strtok(NULL, " ,;\t");
577      if(foo == NULL){
578        sprintf( painCave.errMsg,
579 <               "error in reading quaternion 3 from %s\n"
580 <               "natoms  = %d, index = %d\n",
617 <               inName, n_atoms, atomIndex );
579 >                     "error in reading velocity x from %s\n",
580 >                      inFileName.c_str() );
581        return strdup( painCave.errMsg );
582      }
583      q[3] = atof( foo );
584 <      
584 >
585      // get the angular velocities
586 <      
586 >
587      foo = strtok(NULL, " ,;\t");
588      if(foo == NULL){
589        sprintf( painCave.errMsg,
590 <               "error in reading angular momentum jx from %s\n"
591 <               "natoms  = %d, index = %d\n",
629 <               inName, n_atoms, atomIndex );
590 >                     "error in reading velocity x from %s\n",
591 >                      inFileName.c_str() );
592        return strdup( painCave.errMsg );
593      }
594 <    jx = atof( foo );
595 <      
594 >    ji[0] = atof( foo );
595 >
596      foo = strtok(NULL, " ,;\t");
597      if(foo == NULL){
598        sprintf( painCave.errMsg,
599 <               "error in reading angular momentum jy from %s\n"
600 <               "natoms  = %d, index = %d\n",
639 <               inName, n_atoms, atomIndex );
599 >                     "error in reading velocity x from %s\n",
600 >                      inFileName.c_str() );
601        return strdup( painCave.errMsg );
602      }
603 <    jy = atof(foo );
604 <      
603 >    ji[1] = atof(foo );
604 >
605      foo = strtok(NULL, " ,;\t");
606      if(foo == NULL){
607        sprintf( painCave.errMsg,
608 <               "error in reading angular momentum jz from %s\n"
609 <               "natoms  = %d, index = %d\n",
649 <               inName, n_atoms, atomIndex );
608 >                     "error in reading velocity x from %s\n",
609 >                      inFileName.c_str() );
610        return strdup( painCave.errMsg );
611      }
612 <    jz = atof( foo );
653 <      
654 <    dAtom = ( DirectionalAtom* )atoms[atomIndex];
612 >    ji[2] = atof( foo );
613  
614 +
615      // check that the quaternion vector is normalized
616  
617      qSqr = (q[0] * q[0]) + (q[1] * q[1]) + (q[2] * q[2]) + (q[3] * q[3]);
618 <      
618 >
619      qLength = sqrt( qSqr );
620      q[0] = q[0] / qLength;
621      q[1] = q[1] / qLength;
622      q[2] = q[2] / qLength;
623      q[3] = q[3] / qLength;
665      
666    dAtom->setQ( q );
667      
668    // add the angular velocities
624  
625 <    dAtom->setJx( jx );
626 <    dAtom->setJy( jy );
627 <    dAtom->setJz( jz );
625 >    // add quaternion and angular velocities
626 >
627 >    sd->setQ( q );
628 >    sd->setJ( ji );
629    }
674    
675  // add the positions and velocities to the atom
630  
677  atoms[atomIndex]->setPos( pos );
678  atoms[atomIndex]->setVel( vel );
631  
632 +
633    return NULL;
634   }
635  
636  
637 < char* DumpReader::parseCommentLine(char* readLine, double &time,
685 <                                   double boxMat[9]){
637 > char* DumpReader::parseCommentLine(char* readLine, SimInfo* entry_plug){
638  
639 <  char *foo; // the pointer to the current string token
640 <  int j;
641 <  double chi, integralOfChidt;
639 >  double currTime;
640 >  double boxMat[9];
641 >  double theBoxMat3[3][3];
642 >  double chi;
643 >  double integralOfChidt;
644    double eta[9];
645  
646 +  char *foo; // the pointer to the current string token
647 +
648    // set the string tokenizer
649 <  
649 >
650    foo = strtok(readLine, " ,;\t");
651 +  // set the timeToken.
652 +
653    if(foo == NULL){
654      sprintf( painCave.errMsg,
655 <             "error in reading time from %s\n",
656 <             inName );
655 >             "error in reading Time from %s\n",
656 >             inFileName.c_str() );
657      return strdup( painCave.errMsg );
658    }
701  time = atof( foo );
659  
660 <  // get the Hx vector
660 >  currTime = atof( foo );
661 >  entry_plug->setTime( currTime );
662  
663 <  foo = strtok(NULL, " ,;\t");
706 <  if(foo == NULL){
707 <    sprintf( painCave.errMsg,
708 <             "error in reading Hx[0] from %s\n",
709 <             inName );
710 <    return strdup( painCave.errMsg );
711 <  }
712 <  boxMat[0] = atof( foo );
713 <  
714 <  foo = strtok(NULL, " ,;\t");
715 <  if(foo == NULL){
716 <    sprintf( painCave.errMsg,
717 <             "error in reading Hx[1] from %s\n",
718 <             inName );
719 <    return strdup( painCave.errMsg );
720 <  }
721 <  boxMat[1] = atof( foo );
722 <    
723 <  foo = strtok(NULL, " ,;\t");
724 <  if(foo == NULL){
725 <    sprintf( painCave.errMsg,
726 <             "error in reading Hx[2] from %s\n",
727 <             inName );
728 <    return strdup( painCave.errMsg );
729 <  }
730 <  boxMat[2] = atof( foo );    
663 >  //get H-Matrix
664  
665 <  // get the Hy vector
666 <
667 <  foo = strtok(NULL, " ,;\t");
668 <  if(foo == NULL){
669 <    sprintf( painCave.errMsg,
670 <             "error in reading Hy[0] from %s\n",
671 <             inName );
672 <    return strdup( painCave.errMsg );
665 >  for(int i = 0 ; i < 9; i++){
666 >    foo = strtok(NULL, " ,;\t");
667 >    if(foo == NULL){
668 >      sprintf( painCave.errMsg,
669 >               "error in reading H[%d] from %s\n", i, inFileName.c_str() );
670 >      return strdup( painCave.errMsg );
671 >    }
672 >    boxMat[i] = atof( foo );
673    }
741  boxMat[3] = atof( foo );
742  
743  foo = strtok(NULL, " ,;\t");
744  if(foo == NULL){
745    sprintf( painCave.errMsg,
746             "error in reading Hy[1] from %s\n",
747             inName );
748    return strdup( painCave.errMsg );
749  }
750  boxMat[4] = atof( foo );
751    
752  foo = strtok(NULL, " ,;\t");
753  if(foo == NULL){
754    sprintf( painCave.errMsg,
755             "error in reading Hy[2] from %s\n",
756             inName );
757    return strdup( painCave.errMsg );
758  }
759  boxMat[5] = atof( foo );    
674  
675 <  // get the Hz vector
675 >  for(int i=0;i<3;i++)
676 >    for(int j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i];
677  
678 <  foo = strtok(NULL, " ,;\t");
679 <  if(foo == NULL){
765 <    sprintf( painCave.errMsg,
766 <             "error in reading Hz[0] from %s\n",
767 <             inName );
768 <    return strdup( painCave.errMsg );
769 <  }
770 <  boxMat[6] = atof( foo );
771 <  
772 <  foo = strtok(NULL, " ,;\t");
773 <  if(foo == NULL){
774 <    sprintf( painCave.errMsg,
775 <             "error in reading Hz[1] from %s\n",
776 <             inName );
777 <    return strdup( painCave.errMsg );
778 <  }
779 <  boxMat[7] = atof( foo );
780 <    
781 <  foo = strtok(NULL, " ,;\t");
782 <  if(foo == NULL){
783 <    sprintf( painCave.errMsg,
784 <             "error in reading Hz[2] from %s\n",
785 <             inName );
786 <    return strdup( painCave.errMsg );
787 <  }
788 <  boxMat[8] = atof( foo );    
678 >  //set H-Matrix
679 >  entry_plug->setBoxM( theBoxMat3 );
680  
790  return NULL;
791
681    //get chi and integralOfChidt, they should appear by pair
682 <  foo = strtok(NULL, " ,;\t\n");
683 <  if(foo != NULL){
684 <    chi = atof(foo);
682 >
683 >  if( entry_plug->useInitXSstate ){
684 >    foo = strtok(NULL, " ,;\t\n");
685 >    if(foo != NULL){
686 >      chi = atof(foo);
687 >      
688 >      foo = strtok(NULL, " ,;\t\n");
689 >      if(foo == NULL){
690 >        sprintf( painCave.errMsg,
691 >                 "chi and integralOfChidt should appear by pair in %s\n", inFileName.c_str() );
692 >        return strdup( painCave.errMsg );
693 >      }
694 >      integralOfChidt = atof( foo );
695 >      
696 >      //push chi and integralOfChidt into SimInfo::properties which can be
697 >      //retrieved by integrator later
698 >      DoubleData* chiValue = new DoubleData();
699 >      chiValue->setID(CHIVALUE_ID);
700 >      chiValue->setData(chi);
701 >      entry_plug->addProperty(chiValue);
702 >      
703 >      DoubleData* integralOfChidtValue = new DoubleData();
704 >      integralOfChidtValue->setID(INTEGRALOFCHIDT_ID);
705 >      integralOfChidtValue->setData(integralOfChidt);
706 >      entry_plug->addProperty(integralOfChidtValue);
707 >      
708 >    }
709 >    else
710 >      return NULL;
711      
712 +    //get eta
713      foo = strtok(NULL, " ,;\t\n");
714 <    if(foo == NULL){
715 <      sprintf( painCave.errMsg,
716 <               "chi and integralOfChidt should appear by pair in %s\n", inName );
717 <      return strdup( painCave.errMsg );
714 >    if(foo != NULL ){
715 >  
716 >      for(int i = 0 ; i < 9; i++){
717 >        
718 >        if(foo == NULL){
719 >          sprintf( painCave.errMsg,
720 >                   "error in reading eta[%d] from %s\n", i, inFileName.c_str() );
721 >          return strdup( painCave.errMsg );
722 >        }
723 >        eta[i] = atof( foo );
724 >        foo = strtok(NULL, " ,;\t\n");
725 >      }
726      }
727 <    integralOfChidt = atof( foo );
727 >    else
728 >      return NULL;
729      
730 <    //push chi and integralOfChidt into SimInfo::properties which can be
730 >    //push eta into SimInfo::properties which can be
731      //retrieved by integrator later
732 <    DoubleData* chiValue = new DoubleData();
733 <    chiValue->setID(CHIVALUE_ID);
734 <    chiValue->setData(chi);
735 <    simnfo->addProperty(chiValue);
736 <    
812 <    DoubleData* integralOfChidtValue = new DoubleData();
813 <    integralOfChidtValue->setID(INTEGRALOFCHIDT_ID);
814 <    integralOfChidtValue->setData(integralOfChidt);
815 <    simnfo->addProperty(integralOfChidtValue);
816 <    
732 >    //entry_plug->setBoxM( theBoxMat3 );
733 >    DoubleArrayData* etaValue = new DoubleArrayData();
734 >    etaValue->setID(ETAVALUE_ID);
735 >    etaValue->setData(eta, 9);
736 >    entry_plug->addProperty(etaValue);
737    }
818  else
819    return NULL;
820  
821  //get eta
822  for(int i = 0 ; i < 9; i++){
823    foo = strtok(NULL, " ,;\t");
824    if(foo == NULL){
825      sprintf( painCave.errMsg,
826               "error in reading eta[%d] from %s\n", i, inName );
827      return strdup( painCave.errMsg );
828    }
829    eta[i] = atof( foo );
830  }
831  
832  //push eta into SimInfo::properties which can be
833  //retrieved by integrator later
834  //simnfo->setBoxM( theBoxMat3 );
835  DoubleArrayData* etaValue = new DoubleArrayData();
836  etaValue->setID(ETAVALUE_ID);
837  etaValue->setData(eta, 9);
838  simnfo->addProperty(etaValue);
839  
840  
841  return NULL;
842  
843  
738  
739 +  return NULL;
740   }
741  
847
742   #ifdef IS_MPI
743 <
850 < // a couple of functions to let us escape the read loop
851 <
852 < void dumpRead::nodeZeroError( void ){
743 > void DumpReader::nodeZeroError( void ){
744    int j, myStatus;
745 <  
745 >
746    myStatus = 0;
747 <  for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
748 <    MPI_Send( &myStatus, 1, MPI_INT, j,
747 >  for (j = 0; j < mpiSim->getNumberProcessors(); j++) {
748 >    MPI_Send( &myStatus, 1, MPI_INT, j,
749                TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
750 <  }  
860 <  
750 >  }
751  
752 +
753    MPI_Finalize();
754    exit (0);
755 <  
755 >
756   }
757  
758 < void dumpRead::anonymousNodeDie( void ){
758 > void DumpReader::anonymousNodeDie( void ){
759  
760    MPI_Finalize();
761    exit (0);
762   }
763 <
873 < #endif //is_mpi
763 > #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines