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 647 by mmeineke, Tue Jul 22 21:49:38 2003 UTC vs.
Revision 1119 by tim, Mon Apr 19 17:44:48 2004 UTC

# Line 1 | Line 1
1 + #define _LARGEFILE_SOURCE64
2   #define _FILE_OFFSET_BITS 64
3  
4 + #include <sys/types.h>
5 + #include <sys/stat.h>
6 +
7   #include <iostream>
8 < #include <cmath>
5 < #include <vector>
8 > #include <math.h>
9  
10   #include <stdio.h>
11   #include <stdlib.h>
12   #include <string.h>
10 #include <unistd.h>
11 #include <sys/types.h>
12 #include <sys/stat.h>
13  
14 +
15   #include "ReadWrite.hpp"
16   #include "simError.h"
17  
# 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 <  class FilePos{
32 <    
33 <  public:
34 <    FilePos(){ myPos = NULL; }
35 <    FilePos( fpos_t* thePos ) { myPos = thePos; }
36 <    ~FilePos(){ if( myPos != NULL ) delete myPos; }
26 > DumpReader :: DumpReader(const char *in_name ){
27  
38    FilePos &operator=(fpos_t *thePos){ myPos = thePos; return *this; }
39
40    void setPos( fpos_t *thePos ){ myPos = thePos; }
41    fpos_t *getPos( void ){ return myPos; }
42  
43  private:
44    
45    fpos_t *myPos
46
47  };
48
49  bool operator<(FilePos a, FilePos b){
50    return (a.getPos())->__pos < (b.getPos())->__pos; }
51
52  bool operator==(FilePos a, FilePos b){
53    return (a.getPos())->__pos == (b.getPos())->__pos; }
54
55  vector<FilePos> frameStart;
56 }
57
58 using namespace dumpRead;
59
60
61 DumpReader :: DumpReader( char *in_name ){
62
28    isScanned = false;
29  
30   #ifdef IS_MPI
# Line 74 | 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 87 | 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 105 | 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 117 | Line 90 | void DumpReader::scanFile( void ){
90    char readBuffer[2000];
91    char* foo;
92    fpos_t *currPos;
93 +  double time;
94  
95 +
96 +
97   #ifdef IS_MPI
98    if( worldRank == 0 ){
99   #endif // is_mpi
# Line 126 | Line 102 | void DumpReader::scanFile( void ){
102      
103      currPos = new fpos_t;
104      fgetpos( inFile, currPos );
105 <    fgets( readBuffer, sizeof( readBuffer ), in_file );
105 >    fgets( readBuffer, sizeof( readBuffer ), inFile );
106      lineNum++;
107 <    if( feof( in_file ) ){
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 <    while( !feof( in_file ) ){
115 >
116 >    while( !feof( inFile ) ){
117        
118 <      frameStart.push_back( FilePos( currPos ) );
118 >      framePos.push_back(currPos);
119 >
120        i = atoi(readBuffer);
121        
122 <      fgets( readBuffer, sizeof( readBuffer ), in_file );
122 >      fgets( readBuffer, sizeof( readBuffer ), inFile );
123        lineNum++;    
124 <      if( feof( in_file ) ){
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 <      
156 <      if(outTime){
157 <        foo = strtok( readBuffer, " ,;\t" );
158 <        time = atof( foo );
159 <      }
160 <      
132 >            
133        for(j=0; j<i; j++){
134          
135 <        fgets( readBuffer, sizeof( readBuffer ), in_file );
135 >        fgets( readBuffer, sizeof( readBuffer ), inFile );
136          lineNum++;    
137 <        if( feof( in_file ) ){
137 >        if( feof( inFile ) ){
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 177 | Line 149 | void DumpReader::scanFile( void ){
149        
150        currPos = new fpos_t;
151        fgetpos( inFile, currPos );
152 <      fgets( readBuffer, sizeof( readBuffer ), in_file );
152 >      fgets( readBuffer, sizeof( readBuffer ), inFile );
153        lineNum++;
154      }
155      
156      delete currPos;
185    vectorSize = frameStart.size();
157      rewind( inFile );
158 <    
158 >    
159 >    isScanned = true;
160 >
161   #ifdef IS_MPI
162    }
163    strcpy( checkPointMsg, "Successfully scanned DumpFile\n" );
164    MPIcheckPoint();
165   #endif // is_mpi
166 + }
167  
168 <  nFrames = vectorSize;
169 <  isScanned = true;
168 > void DumpReader :: readFrame( SimInfo* the_simnfo, int whichFrame){
169 >
170 >  simnfo = the_simnfo;
171 >
172 >  this->readSet( whichFrame );
173   }
174  
175  
176  
177 < void DumpReader :: getFrame( SimInfo* the_simnfo, int whichFrame){
177 > void DumpReader :: readSet( int whichFrame ){
178  
179 <  int i, j, done, which_node, which_atom; // loop counter
179 >   int i, j;
180  
204  const int BUFFERSIZE = 2000; // size of the read buffer
205  int n_atoms; // the number of atoms
206  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;
213  int procIndex;
214  double boxMat[9];
215  double theBoxMat3[3][3];
191  
192 <  simnfo = the_simnfo;
192 >  vector<StuntDouble*> integrableObjects;
193  
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    }
228  
229  n_atoms = atoi( read_buffer );
206  
207 <  Atom **atoms = simnfo->atoms;
232 <  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 );
261 <  
262 <  for(i=0;i<3;i++)
263 <    for(j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i];
264 <  
235 >  //parse dump lines
236  
237 <  simnfo->setBoxM( theBoxMat3 );
267 <  
237 >  for( i=0; i < simnfo->n_mol; i++){
238  
239 <  for( i=0; i < n_atoms; i++){
270 <    
271 <    eof_test = fgets(read_buffer, sizeof(read_buffer), inFile);
272 <    if(eof_test == NULL){
273 <      sprintf(painCave.errMsg,
274 <              "error in reading file %s\n"
275 <              "natoms  = %d; index = %d\n"
276 <              "error reading the line from the file.\n",
277 <              inName, n_atoms, i );
278 <      painCave.isFatal = 1;
279 <      simError();
280 <    }
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  
291
263    // MPI Section of code..........
264   #else //IS_MPI
265  
# Line 297 | Line 268 | void DumpReader :: getFrame( SimInfo* the_simnfo, int
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  
304  
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;
292 <    DirectionalAtom* dAtom;
293 <
294 <    // Check to see that the number of atoms in the intial configuration file is the
295 <    // same as declared in simBass.
296 <    
324 <    if( n_atoms != mpiSim->getTotAtoms() ){
325 <      sprintf( painCave.errMsg,
326 <               "Initialize from File error. %s n_atoms, %d, "
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( nTotObjs != simnfo->getTotIntegrableObjects()){
295 >      sprintf( painCave.errMsg,
296 >               "DumpReadererror. %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 <    
354 <    if(haveError) nodeZeroError();
355 <    
356 <    for (i=0 ; i < mpiSim->getTotAtoms(); i++) {
357 <      
358 <      eof_test = fgets(read_buffer, sizeof(read_buffer), inFile);
359 <      if(eof_test == NULL){
360 <        sprintf(painCave.errMsg,
361 <                "error in reading file %s\n"
362 <                "natoms  = %d; index = %d\n"
363 <                "error reading the line from the file.\n",
364 <                inName, n_atoms, i );
365 <        haveError= 1;
366 <        simError();
367 <      }
368 <    
369 <      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 );
377 <          haveError = 1;
378 <          simError();
379 <        }    
380 <        if(haveError) nodeZeroError();
381 <      }
382 <      
383 <      else {
384 <      
385 <        myStatus = 1;
386 <        MPI_Send(&myStatus, 1, MPI_INT, which_node,
387 <                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
388 <        MPI_Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node,
389 <                 TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD);
390 <        MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT,
391 <                 MPI_COMM_WORLD);
392 <        MPI_Recv(&myStatus, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT,
393 <                 MPI_COMM_WORLD, &istatus);
394 <        
395 <        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        }
397    }
398    myStatus = -1;
399    for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
400      MPI_Send( &myStatus, 1, MPI_INT, j,
401                TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
402    }
403    
404  } else {
405    
406    MPI_Bcast(time, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
407    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 <      
415 <      if(!myStatus) anonymousNodeDie();
416 <      
417 <      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        
432      MPI_Send( &myStatus, 1, MPI_INT, 0,
433                TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
434      
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++)
444 <    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 <  
444 <  double rx, ry, rz; // position place holders
445 <  double vx, vy, vz; // velocity placeholders
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.
461  
462  Atom **atoms = simnfo->atoms;
463  DirectionalAtom* dAtom;
464  
465  int j, n_atoms, atomIndex;
449  
467 #ifdef IS_MPI
468  n_atoms = mpiSim->getTotAtoms();
469  atomIndex=-1;        
470  for (j=0; j < mpiSim->getMyNlocal(); j++) {
471    if (atoms[j]->getGlobalIndex() == globalIndex) atomIndex = j;
472  }
473  if (atomIndex == -1) {
474    sprintf( painCave.errMsg,
475             "Initialize from file error. Atom at index %d "
476             "in file %s does not exist on processor %d .\n",
477             globalIndex, inName, mpiSim->getMyNode() );
478    return strdup( painCave.errMsg );
479  }  
480 #else
481  n_atoms = simnfo->n_atoms;
482  atomIndex = globalIndex;
483 #endif // is_mpi
450  
451    // set the string tokenizer
452 <  
452 >
453    foo = strtok(readLine, " ,;\t");
454 <  
454 >
455    // check the atom name to the current atom
456 <  
457 <  if( strcmp( foo, atoms[atomIndex]->getType() ) ){
456 >
457 >  if( strcmp( foo, sd->getType() ) ){
458      sprintf( painCave.errMsg,
459 <             "Initialize from file error. Atom %s at index %d "
494 <             "in file %s does not"
459 >             "DumpReader 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",
507 <             inName, n_atoms, atomIndex );
470 >             "error in reading postition x from %s\n",
471 >             inFileName.c_str());
472      return strdup( painCave.errMsg );
473    }
474 <  rx = atof( foo );
475 <  
474 >  pos[0] = atof( foo );
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",
517 <             inName, n_atoms, atomIndex );
479 >             "error in reading postition y from %s\n",
480 >             inFileName.c_str());
481      return strdup( painCave.errMsg );
482    }
483 <  ry = atof( foo );
484 <    
483 >  pos[1] = atof( foo );
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",
527 <             inName, n_atoms, atomIndex );
488 >             "error in reading postition z from %s\n",
489 >             inFileName.c_str());
490      return strdup( painCave.errMsg );
491    }
492 <  rz = atof( foo );    
492 >  pos[2] = atof( foo );
493  
494  
495    // get the velocities
# Line 535 | 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",
540 <             inName, n_atoms, atomIndex );
500 >             "error in reading velocity x from %s\n",
501 >             inFileName.c_str() );
502      return strdup( painCave.errMsg );
503    }
504 <  vx = atof( foo );
505 <    
504 >  vel[0] = atof( foo );
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",
550 <             inName, n_atoms, atomIndex );
509 >             "error in reading velocity x from %s\n",
510 >             inFileName.c_str() );
511      return strdup( painCave.errMsg );
512    }
513 <  vy = atof( foo );
514 <    
513 >  vel[1] = atof( foo );
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",
560 <             inName, n_atoms, atomIndex );
518 >             "error in reading velocity x from %s\n",
519 >             inFileName.c_str() );
520      return strdup( painCave.errMsg );
521    }
522 <  vz = atof( foo );
523 <    
524 <    
522 >  vel[2] = atof( foo );
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",
575 <              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",
585 <               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",
595 <               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",
605 <               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",
617 <               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",
627 <               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",
637 <               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 );
641 <      
642 <    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;
653      
654    dAtom->setQ( q );
655      
656    // 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    }
662    
663  // add the positions and velocities to the atom
664    
665  atoms[atomIndex]->setX( rx );
666  atoms[atomIndex]->setY( ry );
667  atoms[atomIndex]->setZ( rz );
668    
669  atoms[atomIndex]->set_vx( vx );
670  atoms[atomIndex]->set_vy( vy );
671  atoms[atomIndex]->set_vz( vz );
618  
619 +
620 +
621    return NULL;
622   }
623  
624  
625 < char* DumpReader::parseCommentLine(char* readLine, double time,
678 <                                   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;
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    }
692  time = atof( foo );
647  
648 <  // get the Hx vector
648 >  currTime = atof( foo );
649 >  entry_plug->setTime( currTime );
650  
651 <  foo = strtok(NULL, " ,;\t");
652 <  if(foo == NULL){
653 <    sprintf( painCave.errMsg,
654 <             "error in reading Hx[0] from %s\n",
655 <             inName );
656 <    return strdup( painCave.errMsg );
651 >  //get H-Matrix
652 >
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    }
703  boxMat[0] = atof( foo );
704  
705  foo = strtok(NULL, " ,;\t");
706  if(foo == NULL){
707    sprintf( painCave.errMsg,
708             "error in reading Hx[1] from %s\n",
709             inName );
710    return strdup( painCave.errMsg );
711  }
712  boxMat[1] = atof( foo );
713    
714  foo = strtok(NULL, " ,;\t");
715  if(foo == NULL){
716    sprintf( painCave.errMsg,
717             "error in reading Hx[2] from %s\n",
718             inName );
719    return strdup( painCave.errMsg );
720  }
721  boxMat[2] = atof( foo );    
662  
663 <  // get the Hy 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){
727 <    sprintf( painCave.errMsg,
728 <             "error in reading Hy[0] from %s\n",
729 <             inName );
730 <    return strdup( painCave.errMsg );
731 <  }
732 <  boxMat[3] = atof( foo );
733 <  
734 <  foo = strtok(NULL, " ,;\t");
735 <  if(foo == NULL){
736 <    sprintf( painCave.errMsg,
737 <             "error in reading Hy[1] from %s\n",
738 <             inName );
739 <    return strdup( painCave.errMsg );
740 <  }
741 <  boxMat[4] = atof( foo );
742 <    
743 <  foo = strtok(NULL, " ,;\t");
744 <  if(foo == NULL){
745 <    sprintf( painCave.errMsg,
746 <             "error in reading Hy[2] from %s\n",
747 <             inName );
748 <    return strdup( painCave.errMsg );
749 <  }
750 <  boxMat[5] = atof( foo );    
666 >  //set H-Matrix
667 >  entry_plug->setBoxM( theBoxMat3 );
668  
669 <  // get the Hz vector
669 >  //get chi and integralOfChidt, they should appear by pair
670  
671 <  foo = strtok(NULL, " ,;\t");
672 <  if(foo == NULL){
673 <    sprintf( painCave.errMsg,
674 <             "error in reading Hz[0] from %s\n",
675 <             inName );
676 <    return strdup( painCave.errMsg );
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 >  
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 >    else
716 >      return NULL;
717 >    
718 >    //push eta into SimInfo::properties which can be
719 >    //retrieved by integrator later
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    }
761  boxMat[6] = atof( foo );
762  
763  foo = strtok(NULL, " ,;\t");
764  if(foo == NULL){
765    sprintf( painCave.errMsg,
766             "error in reading Hz[1] from %s\n",
767             inName );
768    return strdup( painCave.errMsg );
769  }
770  boxMat[7] = atof( foo );
771    
772  foo = strtok(NULL, " ,;\t");
773  if(foo == NULL){
774    sprintf( painCave.errMsg,
775             "error in reading Hz[2] from %s\n",
776             inName );
777    return strdup( painCave.errMsg );
778  }
779  boxMat[8] = atof( foo );    
726  
727    return NULL;
728   }
729  
784
730   #ifdef IS_MPI
731 <
787 < // a couple of functions to let us escape the read loop
788 <
789 < void initFile::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 <  }  
797 <  
738 >  }
739  
740 +
741    MPI_Finalize();
742    exit (0);
743 <  
743 >
744   }
745  
746 < void initFile::anonymousNodeDie( void ){
746 > void DumpReader::anonymousNodeDie( void ){
747  
748    MPI_Finalize();
749    exit (0);
750   }
751 <
810 < #endif //is_mpi
751 > #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines