--- trunk/OOPSE/libmdtools/DumpReader.cpp 2003/07/29 16:32:37 656 +++ trunk/OOPSE/libmdtools/DumpReader.cpp 2003/10/16 19:16:24 804 @@ -1,16 +1,16 @@ #define _FILE_OFFSET_BITS 64 +#include +#include + #include #include -#include #include #include #include -#include -#include -#include + #include "ReadWrite.hpp" #include "simError.h" @@ -28,31 +28,6 @@ namespace dumpRead{ void anonymousNodeDie( void ); #endif // is_mpi - class FilePos{ - - public: - FilePos(){ myPos = NULL; } - FilePos( fpos_t* thePos ) { myPos = thePos; } - ~FilePos(){ if( myPos != NULL ) delete myPos; } - - FilePos &operator=(fpos_t *thePos){ myPos = thePos; return *this; } - - void setPos( fpos_t *thePos ){ myPos = thePos; } - fpos_t *getPos( void ){ return myPos; } - - private: - - fpos_t *myPos - - }; - - bool operator<(FilePos a, FilePos b){ - return (a.getPos())->__pos < (b.getPos())->__pos; } - - bool operator==(FilePos a, FilePos b){ - return (a.getPos())->__pos == (b.getPos())->__pos; } - - vector frameStart; } using namespace dumpRead; @@ -61,6 +36,7 @@ DumpReader :: DumpReader( char *in_name ){ DumpReader :: DumpReader( char *in_name ){ isScanned = false; + headFP = new FilePos; #ifdef IS_MPI if (worldRank == 0) { @@ -117,7 +93,11 @@ void DumpReader::scanFile( void ){ char readBuffer[2000]; char* foo; fpos_t *currPos; + double time; + FilePos *currFP; + + #ifdef IS_MPI if( worldRank == 0 ){ #endif // is_mpi @@ -126,9 +106,9 @@ void DumpReader::scanFile( void ){ currPos = new fpos_t; fgetpos( inFile, currPos ); - fgets( readBuffer, sizeof( readBuffer ), in_file ); + fgets( readBuffer, sizeof( readBuffer ), inFile ); lineNum++; - if( feof( in_file ) ){ + if( feof( inFile ) ){ sprintf( painCave.errMsg, "File \"%s\" ended unexpectedly at line %d\n", inName, @@ -137,14 +117,17 @@ void DumpReader::scanFile( void ){ simError(); } - while( !feof( in_file ) ){ - - frameStart.push_back( FilePos( currPos ) ); + nFrames = 0; + while( !feof( inFile ) ){ + + headFP->add( currPos ); + nFrames++; + i = atoi(readBuffer); - fgets( readBuffer, sizeof( readBuffer ), in_file ); + fgets( readBuffer, sizeof( readBuffer ), inFile ); lineNum++; - if( feof( in_file ) ){ + if( feof( inFile ) ){ sprintf( painCave.errMsg, "File \"%s\" ended unexpectedly at line %d\n", inName, @@ -153,16 +136,16 @@ void DumpReader::scanFile( void ){ simError(); } - if(outTime){ - foo = strtok( readBuffer, " ,;\t" ); - time = atof( foo ); - } +// if(outTime){ +// foo = strtok( readBuffer, " ,;\t" ); +// time = atof( foo ); +// } for(j=0; jgetNext(); + if( currFP == NULL ){ + sprintf( painCave.errMsg, + "DumpReader error: scanFile FilePos mismatch at " + "nFrames = %d\n", + i ); + painCave.isFatal = 1; + simError(); + } + + frameStart[i] = currFP; + } + + isScanned = true; + #ifdef IS_MPI } strcpy( checkPointMsg, "Successfully scanned DumpFile\n" ); MPIcheckPoint(); #endif // is_mpi - - nFrames = vectorSize; - isScanned = true; } void DumpReader :: readFrame( SimInfo* the_simnfo, int whichFrame){ @@ -220,12 +218,13 @@ void DumpReader :: readSet( int whichFrame ){ int procIndex; double boxMat[9]; double theBoxMat3[3][3]; - + double time; + fpos_t *framePos; #ifndef IS_MPI - framePos = startFrame[whichFrame].getPos(); + framePos = frameStart[whichFrame]->getPos(); @@ -360,7 +359,7 @@ void DumpReader :: readSet( int whichFrame ){ simError(); } - MPI_Bcast(time, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD ); + MPI_Bcast(&time, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD ); MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD ); @@ -416,7 +415,7 @@ void DumpReader :: readSet( int whichFrame ){ } else { - MPI_Bcast(time, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); + MPI_Bcast(&time, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD); done = 0; @@ -466,8 +465,8 @@ char* DumpReader::parseDumpLine(char* readLine, int gl char *foo; // the pointer to the current string token - double rx, ry, rz; // position place holders - double vx, vy, vz; // velocity placeholders + double pos[3]; // position place holders + double vel[3]; // velocity placeholders double q[4]; // the quaternions double jx, jy, jz; // angular velocity placeholders; double qSqr, qLength; // needed to normalize the quaternion vector. @@ -520,7 +519,7 @@ char* DumpReader::parseDumpLine(char* readLine, int gl inName, n_atoms, atomIndex ); return strdup( painCave.errMsg ); } - rx = atof( foo ); + pos[0] = atof( foo ); foo = strtok(NULL, " ,;\t"); if(foo == NULL){ @@ -530,7 +529,7 @@ char* DumpReader::parseDumpLine(char* readLine, int gl inName, n_atoms, atomIndex ); return strdup( painCave.errMsg ); } - ry = atof( foo ); + pos[1] = atof( foo ); foo = strtok(NULL, " ,;\t"); if(foo == NULL){ @@ -540,7 +539,7 @@ char* DumpReader::parseDumpLine(char* readLine, int gl inName, n_atoms, atomIndex ); return strdup( painCave.errMsg ); } - rz = atof( foo ); + pos[2] = atof( foo ); // get the velocities @@ -553,7 +552,7 @@ char* DumpReader::parseDumpLine(char* readLine, int gl inName, n_atoms, atomIndex ); return strdup( painCave.errMsg ); } - vx = atof( foo ); + vel[0] = atof( foo ); foo = strtok(NULL, " ,;\t"); if(foo == NULL){ @@ -563,7 +562,7 @@ char* DumpReader::parseDumpLine(char* readLine, int gl inName, n_atoms, atomIndex ); return strdup( painCave.errMsg ); } - vy = atof( foo ); + vel[1] = atof( foo ); foo = strtok(NULL, " ,;\t"); if(foo == NULL){ @@ -573,7 +572,7 @@ char* DumpReader::parseDumpLine(char* readLine, int gl inName, n_atoms, atomIndex ); return strdup( painCave.errMsg ); } - vz = atof( foo ); + vel[2] = atof( foo ); // get the quaternions @@ -674,20 +673,15 @@ char* DumpReader::parseDumpLine(char* readLine, int gl } // add the positions and velocities to the atom - - atoms[atomIndex]->setX( rx ); - atoms[atomIndex]->setY( ry ); - atoms[atomIndex]->setZ( rz ); - - atoms[atomIndex]->set_vx( vx ); - atoms[atomIndex]->set_vy( vy ); - atoms[atomIndex]->set_vz( vz ); + atoms[atomIndex]->setPos( pos ); + atoms[atomIndex]->setVel( vel ); + return NULL; } -char* DumpReader::parseCommentLine(char* readLine, double time, +char* DumpReader::parseCommentLine(char* readLine, double &time, double boxMat[9]){ char *foo; // the pointer to the current string token @@ -799,7 +793,7 @@ void initFile::nodeZeroError( void ){ // a couple of functions to let us escape the read loop -void initFile::nodeZeroError( void ){ +void dumpRead::nodeZeroError( void ){ int j, myStatus; myStatus = 0; @@ -814,7 +808,7 @@ void initFile::anonymousNodeDie( void ){ } -void initFile::anonymousNodeDie( void ){ +void dumpRead::anonymousNodeDie( void ){ MPI_Finalize(); exit (0);