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 1118 by tim, Mon Apr 19 03:52:27 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 <    
116 <    nFrames = 0;
115 >    framePos.push_back(currPos);
116 >
117      while( !feof( inFile ) ){
118  
123      headFP->add( currPos );
124      nFrames++;
125
119        i = atoi(readBuffer);
120        
121        fgets( readBuffer, sizeof( readBuffer ), inFile );
# Line 130 | Line 123 | void DumpReader::scanFile( void ){
123        if( feof( inFile ) ){
124          sprintf( painCave.errMsg,
125                   "File \"%s\" ended unexpectedly at line %d\n",
126 <                 inName,
126 >                 inFileName.c_str(),
127                   lineNum );
128          painCave.isFatal = 1;
129          simError();
130        }
131 <      
139 < //       if(outTime){
140 < //      foo = strtok( readBuffer, " ,;\t" );
141 < //      time = atof( foo );
142 < //       }
143 <      
131 >            
132        for(j=0; j<i; j++){
133          
134          fgets( readBuffer, sizeof( readBuffer ), inFile );
# Line 149 | Line 137 | void DumpReader::scanFile( void ){
137            sprintf( painCave.errMsg,
138                     "File \"%s\" ended unexpectedly at line %d,"
139                     " with atom %d\n",
140 <                   inName,
140 >                   inFileName.c_str(),
141                     lineNum,
142                     j );
143            painCave.isFatal = 1;
# Line 161 | Line 149 | void DumpReader::scanFile( void ){
149        currPos = new fpos_t;
150        fgetpos( inFile, currPos );
151        fgets( readBuffer, sizeof( readBuffer ), inFile );
152 +      framePos.push_back(currPos);
153        lineNum++;
154      }
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 );
201 >             "InitializeFromFile error: error reading 1st line of \"%s\"\n",
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, "
211 >             "Initialize from File 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  
316  
277    haveError = 0;
278    if (worldRank == 0) {
279 +     fsetpos(inFile,  framePos[whichFrame]);
280  
281      eof_test = fgets(read_buffer, sizeof(read_buffer), inFile);
282      if( eof_test == NULL ){
283        sprintf( painCave.errMsg,
284 <               "Error reading 1st line of %d \n ",inName);
284 >               "Error reading 1st line of %s \n ",inFileName.c_str());
285        haveError = 1;
286        simError();
287      }
288 <    
289 <    n_atoms = atoi( read_buffer );
290 <    
291 <    Atom **atoms = simnfo->atoms;
331 <    DirectionalAtom* dAtom;
332 <
333 <    // Check to see that the number of atoms in the intial configuration file is the
288 >
289 >    nTotObjs = atoi( read_buffer );
290 >
291 >    // Check to see that the number of integrable objects  in the intial configuration file is the
292      // same as declared in simBass.
293 <    
294 <    if( n_atoms != mpiSim->getTotAtoms() ){
293 >
294 >    if( nTotObjs != simnfo->getTotIntegrableObjects()){
295        sprintf( painCave.errMsg,
296                 "Initialize from File error. %s n_atoms, %d, "
297                 "does not match the BASS file's n_atoms, %d.\n",
298 <               inName, n_atoms, simnfo->n_atoms );
298 >               inFileName.c_str(), nTotObjs, simnfo->getTotIntegrableObjects());
299        haveError= 1;
300        simError();
301      }
302 <    
303 <    //read the time and boxMat from the comment line
304 <    
302 >
303 >    //read the boxMat from the comment line
304 >
305      eof_test = fgets(read_buffer, sizeof(read_buffer), inFile);
306      if(eof_test == NULL){
307        sprintf( painCave.errMsg,
308 <               "error in reading commment in %s\n", inName);
308 >               "error in reading commment in %s\n", inFileName.c_str());
309        haveError = 1;
310        simError();
311      }
312 <    
313 <    parseErr = parseCommentLine( read_buffer, time, boxMat );
312 >
313 >    //Every single processor will parse the comment line by itself
314 >    //By using this way, we might lose some efficiency, but if we want to add
315 >    //more parameters into comment line, we only need to modify function
316 >    //parseCommentLine
317 >
318 >    MPI_Bcast(read_buffer, BUFFERSIZE, MPI_CHAR, 0, MPI_COMM_WORLD);
319 >
320 >    parseErr = parseCommentLine( read_buffer, simnfo);
321 >
322      if( parseErr != NULL ){
323        strcpy( painCave.errMsg, parseErr );
324        haveError = 1;
325        simError();
326      }
327  
328 <    MPI_Bcast(&time, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD );
329 <    
330 <    MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD );
331 <    
366 <    if(haveError) nodeZeroError();
367 <    
368 <    for (i=0 ; i < mpiSim->getTotAtoms(); i++) {
369 <      
370 <      eof_test = fgets(read_buffer, sizeof(read_buffer), inFile);
371 <      if(eof_test == NULL){
372 <        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();
379 <      }
380 <    
381 <      if(haveError) nodeZeroError();
328 >    for (i=0 ; i < mpiSim->getTotNmol(); i++) {
329 >      which_node = MolToProcMap[i];
330 >      if(which_node == 0){
331 >       //molecules belong to master node
332  
333 <      // Get the Node number which wants this atom:
334 <      which_node = AtomToProcMap[i];    
335 <      if (which_node == 0) {
336 <        parseErr = parseDumpLine( read_buffer, i );
337 <        if( parseErr != NULL ){
338 <          strcpy( painCave.errMsg, parseErr );
389 <          haveError = 1;
390 <          simError();
391 <        }    
392 <        if(haveError) nodeZeroError();
393 <      }
394 <      
395 <      else {
396 <      
397 <        myStatus = 1;
398 <        MPI_Send(&myStatus, 1, MPI_INT, which_node,
399 <                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
400 <        MPI_Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node,
401 <                 TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD);
402 <        MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT,
403 <                 MPI_COMM_WORLD);
404 <        MPI_Recv(&myStatus, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT,
405 <                 MPI_COMM_WORLD, &istatus);
406 <        
407 <        if(!myStatus) nodeZeroError();
333 >      localIndex = mpiSim->getGlobalToLocalMol(i);
334 >
335 >      if(localIndex == -1) {
336 >        strcpy(painCave.errMsg, "Molecule not found on node 0!");
337 >        haveError = 1;
338 >        simError();
339        }
409    }
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    }
415    
416  } else {
417    
418    MPI_Bcast(&time, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
419    MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD);
340  
341 <    done = 0;
342 <    while (!done) {
341 >       integrableObjects = (simnfo->molecules[localIndex]).getIntegrableObjects();
342 >       for(j=0; j < integrableObjects.size(); j++){
343 >        
344 >          eof_test = fgets(read_buffer, sizeof(read_buffer), inFile);
345 >          if(eof_test == NULL){
346 >                sprintf(painCave.errMsg,
347 >                    "error in reading file %s\n"
348 >                    "natoms  = %d; index = %d\n"
349 >                    "error reading the line from the file.\n",
350 >                    inFileName.c_str(), nTotObjs, i );
351 >                haveError= 1;
352 >                simError();
353 >          }
354 >          
355 >          if(haveError) nodeZeroError();
356  
357 <      MPI_Recv(&myStatus, 1, MPI_INT, 0,
358 <               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
359 <      
427 <      if(!myStatus) anonymousNodeDie();
428 <      
429 <      if(myStatus < 0) break;
357 >          parseDumpLine(read_buffer, integrableObjects[i]);
358 >          
359 >       }
360  
361 <      MPI_Recv(read_buffer, BUFFERSIZE, MPI_CHAR, 0,
362 <               TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus);
363 <      MPI_Recv(&which_atom, 1, MPI_INT, 0,
361 >
362 >      }
363 >      else{
364 >      //molecule belongs to slave nodes
365 >
366 >        MPI_Recv(&nCurObj, 1, MPI_INT, 0,
367                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
368        
369 <      myStatus = 1;
370 <      parseErr = parseDumpLine( read_buffer, which_atom );
371 <      if( parseErr != NULL ){
372 <        strcpy( painCave.errMsg, parseErr );
373 <        myStatus = 0;;
374 <        simError();
369 >       for(j=0; j < integrableObjects.size(); j++){
370 >        
371 >          eof_test = fgets(read_buffer, sizeof(read_buffer), inFile);
372 >          if(eof_test == NULL){
373 >                sprintf(painCave.errMsg,
374 >                    "error in reading file %s\n"
375 >                    "natoms  = %d; index = %d\n"
376 >                    "error reading the line from the file.\n",
377 >                    inFileName.c_str(), nTotObjs, i );
378 >                haveError= 1;
379 >                simError();
380 >          }
381 >          
382 >          if(haveError) nodeZeroError();
383 >
384 >            MPI_Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node,
385 >                      TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD);
386 >          
387 >       }
388 >
389        }
390        
444      MPI_Send( &myStatus, 1, MPI_INT, 0,
445                TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
446      
391      }
392 +    
393    }
394 <    
395 < // last  thing last, enable  fatalities.
396 <  painCave.isEventLoop = 0;
394 >  else{
395 >  //actions taken at slave nodes
396 >    for (i=0 ; i < mpiSim->getTotNmol(); i++) {
397 >      which_node = MolToProcMap[i];
398 >      
399 >      if(which_node == worldRank){
400 >      //molecule with global index i belongs to this processor
401 >      
402 >        localIndex = mpiSim->getGlobalToLocalMol(i);
403  
404 <  simnfo->setTime( time );
404 >        if(localIndex == -1) {
405 >          sprintf(painCave.errMsg, "Molecule not found on node %d\n", worldRank);
406 >          haveError = 1;
407 >          simError();
408 >        }
409  
410 <  for(i=0;i<3;i++)
456 <    for(j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i];
410 >        integrableObjects = (simnfo->molecules[localIndex]).getIntegrableObjects();        
411  
412 <  simnfo->setBoxM( theBoxMat3 );
412 >        nCurObj = integrableObjects.size();
413 >        
414 >        MPI_Recv(&nCurObj, 1, MPI_INT, 0,
415 >                        TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
416  
417 <  
417 >        for(j = 0; j < integrableObjects.size(); j++){
418 >
419 >          MPI_Recv(read_buffer, BUFFERSIZE, MPI_CHAR, 0,
420 >                              TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus);
421 >
422 >          parseErr = parseDumpLine(read_buffer, integrableObjects[j]);
423 >
424 >          if( parseErr != NULL ){
425 >                strcpy( painCave.errMsg, parseErr );
426 >                simError();
427 >          }
428 >
429 >        }
430 >          
431 >      }
432 >      
433 >    }
434 >
435 >  }
436 >
437   #endif
438   }
439  
440 < char* DumpReader::parseDumpLine(char* readLine, int globalIndex){
440 > char* DumpReader::parseDumpLine(char* readLine, StuntDouble* sd){
441  
442 <  char *foo; // the pointer to the current string token
443 <  
442 >  char *foo; // the pointer to the current string token
443 >
444    double pos[3]; // position place holders
445    double vel[3]; // velocity placeholders
446    double q[4]; // the quaternions
447 <  double jx, jy, jz; // angular velocity placeholders;
447 >  double ji[3]; // angular velocity placeholders;
448    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;
449  
450 < #ifdef IS_MPI
451 <  n_atoms = mpiSim->getTotAtoms();
452 <  atomIndex=-1;        
453 <  for (j=0; j < mpiSim->getMyNlocal(); j++) {
454 <    if (atoms[j]->getGlobalIndex() == globalIndex) atomIndex = j;
455 <  }
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
450 >
451 >  // set the string tokenizer
452 >
453 >  foo = strtok(readLine, " ,;\t");
454 >
455 >  // check the atom name to the current atom
456  
457 <  // set the string tokenizer
498 <  
499 <  foo = strtok(readLine, " ,;\t");
500 <  
501 <  // check the atom name to the current atom
502 <  
503 <  if( strcmp( foo, atoms[atomIndex]->getType() ) ){
457 >  if( strcmp( foo, sd->getType() ) ){
458      sprintf( painCave.errMsg,
459 <             "Initialize from file error. Atom %s at index %d "
506 <             "in file %s does not"
459 >             "Initialize from file error.  Does not"
460               " match the BASS atom %s.\n",
461 <             foo, atomIndex, inName, atoms[atomIndex]->getType() );
461 >             sd->getType() );
462      return strdup( painCave.errMsg );
463    }
464 <    
464 >
465    // get the positions
466  
467    foo = strtok(NULL, " ,;\t");
468    if(foo == NULL){
469      sprintf( painCave.errMsg,
470 <             "error in reading postition x from %s\n"
471 <             "natoms  = %d, index = %d\n",
519 <             inName, n_atoms, atomIndex );
470 >             "error in reading postition x from %s\n",
471 >             inFileName.c_str());
472      return strdup( painCave.errMsg );
473    }
474    pos[0] = atof( foo );
475 <  
475 >
476    foo = strtok(NULL, " ,;\t");
477    if(foo == NULL){
478      sprintf( painCave.errMsg,
479 <             "error in reading postition y from %s\n"
480 <             "natoms  = %d, index = %d\n",
529 <             inName, n_atoms, atomIndex );
479 >             "error in reading postition y from %s\n",
480 >             inFileName.c_str());
481      return strdup( painCave.errMsg );
482    }
483    pos[1] = atof( foo );
484 <    
484 >
485    foo = strtok(NULL, " ,;\t");
486    if(foo == NULL){
487      sprintf( painCave.errMsg,
488 <             "error in reading postition z from %s\n"
489 <             "natoms  = %d, index = %d\n",
539 <             inName, n_atoms, atomIndex );
488 >             "error in reading postition z from %s\n",
489 >             inFileName.c_str());
490      return strdup( painCave.errMsg );
491    }
492 <  pos[2] = atof( foo );    
492 >  pos[2] = atof( foo );
493  
494  
495    // get the velocities
# Line 547 | Line 497 | char* DumpReader::parseDumpLine(char* readLine, int gl
497    foo = strtok(NULL, " ,;\t");
498    if(foo == NULL){
499      sprintf( painCave.errMsg,
500 <             "error in reading velocity x from %s\n"
501 <             "natoms  = %d, index = %d\n",
552 <             inName, n_atoms, atomIndex );
500 >             "error in reading velocity x from %s\n",
501 >             inFileName.c_str() );
502      return strdup( painCave.errMsg );
503    }
504    vel[0] = atof( foo );
505 <    
505 >
506    foo = strtok(NULL, " ,;\t");
507    if(foo == NULL){
508      sprintf( painCave.errMsg,
509 <             "error in reading velocity y from %s\n"
510 <             "natoms  = %d, index = %d\n",
562 <             inName, n_atoms, atomIndex );
509 >             "error in reading velocity x from %s\n",
510 >             inFileName.c_str() );
511      return strdup( painCave.errMsg );
512    }
513    vel[1] = atof( foo );
514 <    
514 >
515    foo = strtok(NULL, " ,;\t");
516    if(foo == NULL){
517      sprintf( painCave.errMsg,
518 <             "error in reading velocity z from %s\n"
519 <             "natoms  = %d, index = %d\n",
572 <             inName, n_atoms, atomIndex );
518 >             "error in reading velocity x from %s\n",
519 >             inFileName.c_str() );
520      return strdup( painCave.errMsg );
521    }
522    vel[2] = atof( foo );
523 <    
524 <    
523 >
524 >
525 >  // add the positions and velocities to the atom
526 >
527 >  sd->setPos( pos );
528 >  sd->setVel( vel );
529 >
530 >  if (!sd->isDirectional())
531 >    return NULL;
532 >
533    // get the quaternions
534 <    
535 <  if( atoms[atomIndex]->isDirectional() ){
536 <      
534 >
535 >  if( sd->isDirectional() ){
536 >
537      foo = strtok(NULL, " ,;\t");
538      if(foo == NULL){
539 <      sprintf(painCave.errMsg,
540 <              "error in reading quaternion 0 from %s\n"
541 <              "natoms  = %d, index = %d\n",
587 <              inName, n_atoms, atomIndex );
539 >      sprintf( painCave.errMsg,
540 >                     "error in reading velocity x from %s\n",
541 >                      inFileName.c_str() );
542        return strdup( painCave.errMsg );
543      }
544      q[0] = atof( foo );
545 <      
545 >
546      foo = strtok(NULL, " ,;\t");
547      if(foo == NULL){
548        sprintf( painCave.errMsg,
549 <               "error in reading quaternion 1 from %s\n"
550 <               "natoms  = %d, index = %d\n",
597 <               inName, n_atoms, atomIndex );
549 >                     "error in reading velocity x from %s\n",
550 >                      inFileName.c_str() );
551        return strdup( painCave.errMsg );
552      }
553      q[1] = atof( foo );
554 <      
554 >
555      foo = strtok(NULL, " ,;\t");
556      if(foo == NULL){
557        sprintf( painCave.errMsg,
558 <               "error in reading quaternion 2 from %s\n"
559 <               "natoms  = %d, index = %d\n",
607 <               inName, n_atoms, atomIndex );
558 >                     "error in reading velocity x from %s\n",
559 >                      inFileName.c_str() );
560        return strdup( painCave.errMsg );
561      }
562      q[2] = atof( foo );
563 <      
563 >
564      foo = strtok(NULL, " ,;\t");
565      if(foo == NULL){
566        sprintf( painCave.errMsg,
567 <               "error in reading quaternion 3 from %s\n"
568 <               "natoms  = %d, index = %d\n",
617 <               inName, n_atoms, atomIndex );
567 >                     "error in reading velocity x from %s\n",
568 >                      inFileName.c_str() );
569        return strdup( painCave.errMsg );
570      }
571      q[3] = atof( foo );
572 <      
572 >
573      // get the angular velocities
574 <      
574 >
575      foo = strtok(NULL, " ,;\t");
576      if(foo == NULL){
577        sprintf( painCave.errMsg,
578 <               "error in reading angular momentum jx from %s\n"
579 <               "natoms  = %d, index = %d\n",
629 <               inName, n_atoms, atomIndex );
578 >                     "error in reading velocity x from %s\n",
579 >                      inFileName.c_str() );
580        return strdup( painCave.errMsg );
581      }
582 <    jx = atof( foo );
583 <      
582 >    ji[0] = atof( foo );
583 >
584      foo = strtok(NULL, " ,;\t");
585      if(foo == NULL){
586        sprintf( painCave.errMsg,
587 <               "error in reading angular momentum jy from %s\n"
588 <               "natoms  = %d, index = %d\n",
639 <               inName, n_atoms, atomIndex );
587 >                     "error in reading velocity x from %s\n",
588 >                      inFileName.c_str() );
589        return strdup( painCave.errMsg );
590      }
591 <    jy = atof(foo );
592 <      
591 >    ji[1] = atof(foo );
592 >
593      foo = strtok(NULL, " ,;\t");
594      if(foo == NULL){
595        sprintf( painCave.errMsg,
596 <               "error in reading angular momentum jz from %s\n"
597 <               "natoms  = %d, index = %d\n",
649 <               inName, n_atoms, atomIndex );
596 >                     "error in reading velocity x from %s\n",
597 >                      inFileName.c_str() );
598        return strdup( painCave.errMsg );
599      }
600 <    jz = atof( foo );
653 <      
654 <    dAtom = ( DirectionalAtom* )atoms[atomIndex];
600 >    ji[2] = atof( foo );
601  
602 +
603      // check that the quaternion vector is normalized
604  
605      qSqr = (q[0] * q[0]) + (q[1] * q[1]) + (q[2] * q[2]) + (q[3] * q[3]);
606 <      
606 >
607      qLength = sqrt( qSqr );
608      q[0] = q[0] / qLength;
609      q[1] = q[1] / qLength;
610      q[2] = q[2] / qLength;
611      q[3] = q[3] / qLength;
665      
666    dAtom->setQ( q );
667      
668    // add the angular velocities
612  
613 <    dAtom->setJx( jx );
614 <    dAtom->setJy( jy );
615 <    dAtom->setJz( jz );
613 >    // add quaternion and angular velocities
614 >
615 >    sd->setQ( q );
616 >    sd->setJ( ji );
617    }
674    
675  // add the positions and velocities to the atom
618  
677  atoms[atomIndex]->setPos( pos );
678  atoms[atomIndex]->setVel( vel );
619  
620 +
621    return NULL;
622   }
623  
624  
625 < char* DumpReader::parseCommentLine(char* readLine, double &time,
685 <                                   double boxMat[9]){
625 > char* DumpReader::parseCommentLine(char* readLine, SimInfo* entry_plug){
626  
627 <  char *foo; // the pointer to the current string token
628 <  int j;
629 <  double chi, integralOfChidt;
627 >  double currTime;
628 >  double boxMat[9];
629 >  double theBoxMat3[3][3];
630 >  double chi;
631 >  double integralOfChidt;
632    double eta[9];
633  
634 +  char *foo; // the pointer to the current string token
635 +
636    // set the string tokenizer
637 <  
637 >
638    foo = strtok(readLine, " ,;\t");
639 +  // set the timeToken.
640 +
641    if(foo == NULL){
642      sprintf( painCave.errMsg,
643 <             "error in reading time from %s\n",
644 <             inName );
643 >             "error in reading Time from %s\n",
644 >             inFileName.c_str() );
645      return strdup( painCave.errMsg );
646    }
701  time = atof( foo );
647  
648 <  // get the Hx vector
648 >  currTime = atof( foo );
649 >  entry_plug->setTime( currTime );
650  
651 <  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 );    
651 >  //get H-Matrix
652  
653 <  // get the Hy vector
654 <
655 <  foo = strtok(NULL, " ,;\t");
656 <  if(foo == NULL){
657 <    sprintf( painCave.errMsg,
658 <             "error in reading Hy[0] from %s\n",
659 <             inName );
660 <    return strdup( painCave.errMsg );
653 >  for(int i = 0 ; i < 9; i++){
654 >    foo = strtok(NULL, " ,;\t");
655 >    if(foo == NULL){
656 >      sprintf( painCave.errMsg,
657 >               "error in reading H[%d] from %s\n", i, inFileName.c_str() );
658 >      return strdup( painCave.errMsg );
659 >    }
660 >    boxMat[i] = atof( foo );
661    }
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 );    
662  
663 <  // get the Hz vector
663 >  for(int i=0;i<3;i++)
664 >    for(int j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i];
665  
666 <  foo = strtok(NULL, " ,;\t");
667 <  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 );    
666 >  //set H-Matrix
667 >  entry_plug->setBoxM( theBoxMat3 );
668  
790  return NULL;
791
669    //get chi and integralOfChidt, they should appear by pair
670 <  foo = strtok(NULL, " ,;\t\n");
671 <  if(foo != NULL){
672 <    chi = atof(foo);
670 >
671 >  if( entry_plug->useInitXSstate ){
672 >    foo = strtok(NULL, " ,;\t\n");
673 >    if(foo != NULL){
674 >      chi = atof(foo);
675 >      
676 >      foo = strtok(NULL, " ,;\t\n");
677 >      if(foo == NULL){
678 >        sprintf( painCave.errMsg,
679 >                 "chi and integralOfChidt should appear by pair in %s\n", inFileName.c_str() );
680 >        return strdup( painCave.errMsg );
681 >      }
682 >      integralOfChidt = atof( foo );
683 >      
684 >      //push chi and integralOfChidt into SimInfo::properties which can be
685 >      //retrieved by integrator later
686 >      DoubleData* chiValue = new DoubleData();
687 >      chiValue->setID(CHIVALUE_ID);
688 >      chiValue->setData(chi);
689 >      entry_plug->addProperty(chiValue);
690 >      
691 >      DoubleData* integralOfChidtValue = new DoubleData();
692 >      integralOfChidtValue->setID(INTEGRALOFCHIDT_ID);
693 >      integralOfChidtValue->setData(integralOfChidt);
694 >      entry_plug->addProperty(integralOfChidtValue);
695 >      
696 >    }
697 >    else
698 >      return NULL;
699      
700 +    //get eta
701      foo = strtok(NULL, " ,;\t\n");
702 <    if(foo == NULL){
703 <      sprintf( painCave.errMsg,
704 <               "chi and integralOfChidt should appear by pair in %s\n", inName );
705 <      return strdup( painCave.errMsg );
702 >    if(foo != NULL ){
703 >  
704 >      for(int i = 0 ; i < 9; i++){
705 >        
706 >        if(foo == NULL){
707 >          sprintf( painCave.errMsg,
708 >                   "error in reading eta[%d] from %s\n", i, inFileName.c_str() );
709 >          return strdup( painCave.errMsg );
710 >        }
711 >        eta[i] = atof( foo );
712 >        foo = strtok(NULL, " ,;\t\n");
713 >      }
714      }
715 <    integralOfChidt = atof( foo );
715 >    else
716 >      return NULL;
717      
718 <    //push chi and integralOfChidt into SimInfo::properties which can be
718 >    //push eta into SimInfo::properties which can be
719      //retrieved by integrator later
720 <    DoubleData* chiValue = new DoubleData();
721 <    chiValue->setID(CHIVALUE_ID);
722 <    chiValue->setData(chi);
723 <    simnfo->addProperty(chiValue);
724 <    
812 <    DoubleData* integralOfChidtValue = new DoubleData();
813 <    integralOfChidtValue->setID(INTEGRALOFCHIDT_ID);
814 <    integralOfChidtValue->setData(integralOfChidt);
815 <    simnfo->addProperty(integralOfChidtValue);
816 <    
720 >    //entry_plug->setBoxM( theBoxMat3 );
721 >    DoubleArrayData* etaValue = new DoubleArrayData();
722 >    etaValue->setID(ETAVALUE_ID);
723 >    etaValue->setData(eta, 9);
724 >    entry_plug->addProperty(etaValue);
725    }
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  
726  
727 +  return NULL;
728   }
729  
847
730   #ifdef IS_MPI
731 <
850 < // a couple of functions to let us escape the read loop
851 <
852 < void dumpRead::nodeZeroError( void ){
731 > void DumpReader::nodeZeroError( void ){
732    int j, myStatus;
733 <  
733 >
734    myStatus = 0;
735 <  for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
736 <    MPI_Send( &myStatus, 1, MPI_INT, j,
735 >  for (j = 0; j < mpiSim->getNumberProcessors(); j++) {
736 >    MPI_Send( &myStatus, 1, MPI_INT, j,
737                TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
738 <  }  
860 <  
738 >  }
739  
740 +
741    MPI_Finalize();
742    exit (0);
743 <  
743 >
744   }
745  
746 < void dumpRead::anonymousNodeDie( void ){
746 > void DumpReader::anonymousNodeDie( void ){
747  
748    MPI_Finalize();
749    exit (0);
750   }
751 <
873 < #endif //is_mpi
751 > #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines