--- trunk/OOPSE/libmdtools/DumpReader.cpp 2003/07/29 16:32:37 656 +++ trunk/OOPSE/libmdtools/DumpReader.cpp 2004/04/12 20:32:20 1097 @@ -1,16 +1,17 @@ +#define _LARGEFILE_SOURCE64 #define _FILE_OFFSET_BITS 64 +#include +#include + #include -#include -#include +#include #include #include #include -#include -#include -#include + #include "ReadWrite.hpp" #include "simError.h" @@ -28,39 +29,15 @@ 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; -DumpReader :: DumpReader( char *in_name ){ +DumpReader :: DumpReader(const char *in_name ){ isScanned = false; + headFP = new FilePos; #ifdef IS_MPI if (worldRank == 0) { @@ -117,7 +94,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 +107,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 +118,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 +137,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,16 +219,16 @@ void DumpReader :: readSet( int whichFrame ){ int procIndex; double boxMat[9]; double theBoxMat3[3][3]; - + double time; + fpos_t *framePos; + framePos = frameStart[whichFrame]->getPos(); #ifndef IS_MPI - framePos = startFrame[whichFrame].getPos(); - + fsetpos(inFile, framePos); - eof_test = fgets(read_buffer, sizeof(read_buffer), inFile); if( eof_test == NULL ){ sprintf( painCave.errMsg, @@ -317,7 +316,7 @@ void DumpReader :: readSet( int whichFrame ){ haveError = 0; if (worldRank == 0) { - + fsetpos(inFile, framePos); eof_test = fgets(read_buffer, sizeof(read_buffer), inFile); if( eof_test == NULL ){ sprintf( painCave.errMsg, @@ -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,10 +465,10 @@ 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 q[4]; // the quaternions - double jx, jy, jz; // angular velocity placeholders; + double pos[3]; // position place holders + double vel[3]; // velocity placeholders + double q[4]; // the quaternions + double ji[3]; // angular velocity placeholders; double qSqr, qLength; // needed to normalize the quaternion vector. Atom **atoms = simnfo->atoms; @@ -498,17 +497,17 @@ char* DumpReader::parseDumpLine(char* readLine, int gl // set the string tokenizer foo = strtok(readLine, " ,;\t"); - + atoms[atomIndex]->setType(foo); // check the atom name to the current atom - if( strcmp( foo, atoms[atomIndex]->getType() ) ){ - sprintf( painCave.errMsg, - "Initialize from file error. Atom %s at index %d " - "in file %s does not" - " match the BASS atom %s.\n", - foo, atomIndex, inName, atoms[atomIndex]->getType() ); - return strdup( painCave.errMsg ); - } + //if( strcmp( foo, atoms[atomIndex]->getType() ) ){ + // sprintf( painCave.errMsg, + // "Initialize from file error. Atom %s at index %d " + // "in file %s does not" + // " match the BASS atom %s.\n", + // foo, atomIndex, inName, atoms[atomIndex]->getType() ); + // return strdup( painCave.errMsg ); + //} // get the positions @@ -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 @@ -630,7 +629,7 @@ char* DumpReader::parseDumpLine(char* readLine, int gl inName, n_atoms, atomIndex ); return strdup( painCave.errMsg ); } - jx = atof( foo ); + ji[0] = atof( foo ); foo = strtok(NULL, " ,;\t"); if(foo == NULL){ @@ -640,7 +639,7 @@ char* DumpReader::parseDumpLine(char* readLine, int gl inName, n_atoms, atomIndex ); return strdup( painCave.errMsg ); } - jy = atof(foo ); + ji[1] = atof(foo ); foo = strtok(NULL, " ,;\t"); if(foo == NULL){ @@ -650,7 +649,7 @@ char* DumpReader::parseDumpLine(char* readLine, int gl inName, n_atoms, atomIndex ); return strdup( painCave.errMsg ); } - jz = atof( foo ); + ji[2] = atof( foo ); dAtom = ( DirectionalAtom* )atoms[atomIndex]; @@ -668,30 +667,25 @@ char* DumpReader::parseDumpLine(char* readLine, int gl // add the angular velocities - dAtom->setJx( jx ); - dAtom->setJy( jy ); - dAtom->setJz( jz ); + dAtom->setJ( ji ); } // 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 int j; + double chi, integralOfChidt; + double eta[9]; // set the string tokenizer @@ -792,6 +786,60 @@ char* DumpReader::parseCommentLine(char* readLine, dou boxMat[8] = atof( foo ); return NULL; + + //get chi and integralOfChidt, they should appear by pair + foo = strtok(NULL, " ,;\t\n"); + if(foo != NULL){ + chi = atof(foo); + + foo = strtok(NULL, " ,;\t\n"); + if(foo == NULL){ + sprintf( painCave.errMsg, + "chi and integralOfChidt should appear by pair in %s\n", inName ); + return strdup( painCave.errMsg ); + } + integralOfChidt = atof( foo ); + + //push chi and integralOfChidt into SimInfo::properties which can be + //retrieved by integrator later + DoubleData* chiValue = new DoubleData(); + chiValue->setID(CHIVALUE_ID); + chiValue->setData(chi); + simnfo->addProperty(chiValue); + + DoubleData* integralOfChidtValue = new DoubleData(); + integralOfChidtValue->setID(INTEGRALOFCHIDT_ID); + integralOfChidtValue->setData(integralOfChidt); + simnfo->addProperty(integralOfChidtValue); + + } + else + return NULL; + + //get eta + for(int i = 0 ; i < 9; i++){ + foo = strtok(NULL, " ,;\t"); + if(foo == NULL){ + sprintf( painCave.errMsg, + "error in reading eta[%d] from %s\n", i, inName ); + return strdup( painCave.errMsg ); + } + eta[i] = atof( foo ); + } + + //push eta into SimInfo::properties which can be + //retrieved by integrator later + //simnfo->setBoxM( theBoxMat3 ); + DoubleArrayData* etaValue = new DoubleArrayData(); + etaValue->setID(ETAVALUE_ID); + etaValue->setData(eta, 9); + simnfo->addProperty(etaValue); + + + return NULL; + + + } @@ -799,7 +847,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 +862,7 @@ void initFile::anonymousNodeDie( void ){ } -void initFile::anonymousNodeDie( void ){ +void dumpRead::anonymousNodeDie( void ){ MPI_Finalize(); exit (0);