--- trunk/OOPSE/libmdtools/DumpReader.cpp 2003/10/31 18:28:52 847 +++ trunk/OOPSE/libmdtools/DumpReader.cpp 2004/04/22 14:55:17 1130 @@ -1,3 +1,4 @@ +#define _LARGEFILE_SOURCE64 #define _FILE_OFFSET_BITS 64 #include \ No newline at end of file @@ -21,22 +22,10 @@ namespace dumpRead{ #define TAKE_THIS_TAG_INT 1 #endif // is_mpi -namespace dumpRead{ -#ifdef IS_MPI - void nodeZeroError( void ); - void anonymousNodeDie( void ); -#endif // is_mpi - -} +DumpReader :: DumpReader(const char *in_name ){ -using namespace dumpRead; - - -DumpReader :: DumpReader( char *in_name ){ - isScanned = false; - headFP = new FilePos; #ifdef IS_MPI if (worldRank == 0) { \ No newline at end of file @@ -50,7 +39,7 @@ DumpReader :: DumpReader( char *in_name ){ simError(); } - strcpy( inName, in_name); + inFileName = in_name; #ifdef IS_MPI } strcpy( checkPointMsg, "Dump file opened for reading successfully." ); \ No newline at end of file @@ -63,13 +52,20 @@ DumpReader :: ~DumpReader( ){ #ifdef IS_MPI if (worldRank == 0) { #endif + vector::iterator i; + int error; error = fclose( inFile ); if( error ){ sprintf( painCave.errMsg, - "Error closing %s\n", inName ); + "Error closing %s\n", inFileName.c_str()); simError(); } + + for(i = framePos.begin(); i != framePos.end(); ++i) + delete *i; + framePos.clear(); + #ifdef IS_MPI } strcpy( checkPointMsg, "Dump file closed successfully." ); \ No newline at end of file @@ -81,8 +77,9 @@ int DumpReader::getNframes( void ){ int DumpReader::getNframes( void ){ - if( !isScanned ) scanFile(); - return nFrames; + if( !isScanned ) + scanFile(); + return framePos.size(); } void DumpReader::scanFile( void ){ \ No newline at end of file @@ -95,7 +92,6 @@ void DumpReader::scanFile( void ){ fpos_t *currPos; double time; - FilePos *currFP; #ifdef IS_MPI \ No newline at end of file @@ -111,18 +107,16 @@ void DumpReader::scanFile( void ){ if( feof( inFile ) ){ sprintf( painCave.errMsg, "File \"%s\" ended unexpectedly at line %d\n", - inName, + inFileName.c_str(), lineNum ); painCave.isFatal = 1; simError(); } - - nFrames = 0; + while( !feof( inFile ) ){ + + framePos.push_back(currPos); - headFP->add( currPos ); - nFrames++; - i = atoi(readBuffer); fgets( readBuffer, sizeof( readBuffer ), inFile ); \ No newline at end of file @@ -130,17 +124,12 @@ void DumpReader::scanFile( void ){ if( feof( inFile ) ){ sprintf( painCave.errMsg, "File \"%s\" ended unexpectedly at line %d\n", - inName, + inFileName.c_str(), lineNum ); painCave.isFatal = 1; simError(); } - -// 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 \ No newline at end of file @@ -204,103 +176,90 @@ void DumpReader :: readSet( int whichFrame ){ void DumpReader :: readSet( int whichFrame ){ - int i, j, done, which_node, which_atom; // loop counter + int i, j; - const int BUFFERSIZE = 2000; // size of the read buffer - int n_atoms; // the number of atoms - char read_buffer[BUFFERSIZE]; //the line buffer for reading #ifdef IS_MPI - char send_buffer[BUFFERSIZE]; -#endif + int done, which_node, which_atom; // loop counter +#endif //is_mpi - char *eof_test; // ptr to see when we reach the end of the file + const int BUFFERSIZE = 2000; // size of the read buffer + int nTotObjs; // the number of atoms + char read_buffer[BUFFERSIZE]; //the line buffer for reading + + char *eof_test; // ptr to see when we reach the end of the file char *parseErr; - int procIndex; - double boxMat[9]; - double theBoxMat3[3][3]; - double time; - fpos_t *framePos; - -#ifndef IS_MPI - - framePos = frameStart[whichFrame]->getPos(); + vector integrableObjects; - +#ifndef IS_MPI + fsetpos(inFile, framePos[whichFrame]); eof_test = fgets(read_buffer, sizeof(read_buffer), inFile); if( eof_test == NULL ){ sprintf( painCave.errMsg, "DumpReader error: error reading 1st line of \"%s\"\n", - inName ); + inFileName.c_str() ); painCave.isFatal = 1; simError(); } - - n_atoms = atoi( read_buffer ); - Atom **atoms = simnfo->atoms; - DirectionalAtom* dAtom; + nTotObjs = atoi( read_buffer ); - if( n_atoms != simnfo->n_atoms ){ + if( nTotObjs != simnfo->getTotIntegrableObjects() ){ sprintf( painCave.errMsg, "DumpReader error. %s n_atoms, %d, " "does not match the BASS file's n_atoms, %d.\n", - inName, n_atoms, simnfo->n_atoms ); + inFileName.c_str(), nTotObjs, simnfo->getTotIntegrableObjects()); painCave.isFatal = 1; simError(); } - - //read the box mat from the comment line - + + //read the box mat from the comment line + eof_test = fgets(read_buffer, sizeof(read_buffer), inFile); if(eof_test == NULL){ sprintf( painCave.errMsg, - "error in reading commment in %s\n", inName); + "error in reading commment in %s\n", inFileName.c_str()); painCave.isFatal = 1; simError(); } - parseErr = parseCommentLine( read_buffer, time, boxMat ); + parseErr = parseCommentLine( read_buffer, simnfo); if( parseErr != NULL ){ strcpy( painCave.errMsg, parseErr ); painCave.isFatal = 1; simError(); } - simnfo->setTime( time ); - - for(i=0;i<3;i++) - for(j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i]; - + //parse dump lines - simnfo->setBoxM( theBoxMat3 ); - + for( i=0; i < simnfo->n_mol; i++){ - for( i=0; i < n_atoms; i++){ - - eof_test = fgets(read_buffer, sizeof(read_buffer), inFile); - if(eof_test == NULL){ - sprintf(painCave.errMsg, - "error in reading file %s\n" - "natoms = %d; index = %d\n" - "error reading the line from the file.\n", - inName, n_atoms, i ); - painCave.isFatal = 1; - simError(); - } + integrableObjects = (simnfo->molecules[i]).getIntegrableObjects(); - - parseErr = parseDumpLine( read_buffer, i ); - if( parseErr != NULL ){ - strcpy( painCave.errMsg, parseErr ); - painCave.isFatal = 1; - simError(); + for(j = 0; j < integrableObjects.size(); j++){ + + eof_test = fgets(read_buffer, sizeof(read_buffer), inFile); + if(eof_test == NULL){ + sprintf(painCave.errMsg, + "error in reading file %s\n" + "natoms = %d; index = %d\n" + "error reading the line from the file.\n", + inFileName.c_str(), nTotObjs, i ); + painCave.isFatal = 1; + simError(); + } + + parseErr = parseDumpLine( read_buffer, integrableObjects[j]); + if( parseErr != NULL ){ + strcpy( painCave.errMsg, parseErr ); + painCave.isFatal = 1; + simError(); + } } } - // MPI Section of code.......... #else //IS_MPI \ No newline at end of file @@ -309,237 +268,240 @@ void DumpReader :: readSet( int whichFrame ){ int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone int haveError; - + MPI_Status istatus; - int *AtomToProcMap = mpiSim->getAtomToProcMap(); + int *MolToProcMap = mpiSim->getMolToProcMap(); + int localIndex; + int nCurObj; + int nitems; - + nTotObjs = simnfo->getTotIntegrableObjects(); haveError = 0; if (worldRank == 0) { + fsetpos(inFile, framePos[whichFrame]); eof_test = fgets(read_buffer, sizeof(read_buffer), inFile); if( eof_test == NULL ){ sprintf( painCave.errMsg, - "Error reading 1st line of %d \n ",inName); + "Error reading 1st line of %s \n ",inFileName.c_str()); haveError = 1; simError(); } - - n_atoms = atoi( read_buffer ); - - Atom **atoms = simnfo->atoms; - DirectionalAtom* dAtom; - - // Check to see that the number of atoms in the intial configuration file is the + + nitems = atoi( read_buffer ); + + // Check to see that the number of integrable objects in the intial configuration file is the // same as declared in simBass. - - if( n_atoms != mpiSim->getTotAtoms() ){ + + if( nTotObjs != nitems){ sprintf( painCave.errMsg, - "Initialize from File error. %s n_atoms, %d, " + "DumpReadererror. %s n_atoms, %d, " "does not match the BASS file's n_atoms, %d.\n", - inName, n_atoms, simnfo->n_atoms ); + inFileName.c_str(), nTotObjs, simnfo->getTotIntegrableObjects()); haveError= 1; simError(); } - - //read the time and boxMat from the comment line - + + //read the boxMat from the comment line + eof_test = fgets(read_buffer, sizeof(read_buffer), inFile); if(eof_test == NULL){ sprintf( painCave.errMsg, - "error in reading commment in %s\n", inName); + "error in reading commment in %s\n", inFileName.c_str()); haveError = 1; simError(); } - - parseErr = parseCommentLine( read_buffer, time, boxMat ); + + //Every single processor will parse the comment line by itself + //By using this way, we might lose some efficiency, but if we want to add + //more parameters into comment line, we only need to modify function + //parseCommentLine + + MPI_Bcast(read_buffer, BUFFERSIZE, MPI_CHAR, 0, MPI_COMM_WORLD); + + parseErr = parseCommentLine( read_buffer, simnfo); + if( parseErr != NULL ){ strcpy( painCave.errMsg, parseErr ); haveError = 1; simError(); } - MPI_Bcast(&time, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD ); - - MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD ); - - if(haveError) nodeZeroError(); - - for (i=0 ; i < mpiSim->getTotAtoms(); i++) { - - eof_test = fgets(read_buffer, sizeof(read_buffer), inFile); - if(eof_test == NULL){ - sprintf(painCave.errMsg, - "error in reading file %s\n" - "natoms = %d; index = %d\n" - "error reading the line from the file.\n", - inName, n_atoms, i ); - haveError= 1; - simError(); + for (i=0 ; i < mpiSim->getTotNmol(); i++) { + which_node = MolToProcMap[i]; + if(which_node == 0){ + //molecules belong to master node + + localIndex = mpiSim->getGlobalToLocalMol(i); + + if(localIndex == -1) { + strcpy(painCave.errMsg, "Molecule not found on node 0!"); + haveError = 1; + simError(); } - - if(haveError) nodeZeroError(); - // Get the Node number which wants this atom: - which_node = AtomToProcMap[i]; - if (which_node == 0) { - parseErr = parseDumpLine( read_buffer, i ); - if( parseErr != NULL ){ - strcpy( painCave.errMsg, parseErr ); - haveError = 1; - simError(); - } - if(haveError) nodeZeroError(); - } + integrableObjects = (simnfo->molecules[localIndex]).getIntegrableObjects(); + for(j=0; j < integrableObjects.size(); j++){ + + eof_test = fgets(read_buffer, sizeof(read_buffer), inFile); + if(eof_test == NULL){ + sprintf(painCave.errMsg, + "error in reading file %s\n" + "natoms = %d; index = %d\n" + "error reading the line from the file.\n", + inFileName.c_str(), nTotObjs, i ); + haveError= 1; + simError(); + } + + if(haveError) nodeZeroError(); + + parseDumpLine(read_buffer, integrableObjects[j]); + + } + + + } + else{ + //molecule belongs to slave nodes + + MPI_Recv(&nCurObj, 1, MPI_INT, which_node, + TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); - else { - - myStatus = 1; - MPI_Send(&myStatus, 1, MPI_INT, which_node, - TAKE_THIS_TAG_INT, MPI_COMM_WORLD); - MPI_Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node, - TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); - MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, - MPI_COMM_WORLD); - MPI_Recv(&myStatus, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, - MPI_COMM_WORLD, &istatus); - - if(!myStatus) nodeZeroError(); + for(j=0; j < nCurObj; j++){ + + eof_test = fgets(read_buffer, sizeof(read_buffer), inFile); + if(eof_test == NULL){ + sprintf(painCave.errMsg, + "error in reading file %s\n" + "natoms = %d; index = %d\n" + "error reading the line from the file.\n", + inFileName.c_str(), nTotObjs, i ); + haveError= 1; + simError(); + } + + if(haveError) nodeZeroError(); + + MPI_Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node, + TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); + + } + } + } - myStatus = -1; - for (j = 0; j < mpiSim->getNumberProcessors(); j++) { - MPI_Send( &myStatus, 1, MPI_INT, j, - TAKE_THIS_TAG_INT, MPI_COMM_WORLD); - } - } else { - - MPI_Bcast(&time, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); - MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD); + } + else{ + //actions taken at slave nodes + MPI_Bcast(read_buffer, BUFFERSIZE, MPI_CHAR, 0, MPI_COMM_WORLD); - done = 0; - while (!done) { + parseErr = parseCommentLine( read_buffer, simnfo); - MPI_Recv(&myStatus, 1, MPI_INT, 0, - TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); + if( parseErr != NULL ){ + strcpy( painCave.errMsg, parseErr ); + haveError = 1; + simError(); + } + + for (i=0 ; i < mpiSim->getTotNmol(); i++) { + which_node = MolToProcMap[i]; - if(!myStatus) anonymousNodeDie(); + if(which_node == worldRank){ + //molecule with global index i belongs to this processor - if(myStatus < 0) break; + localIndex = mpiSim->getGlobalToLocalMol(i); - MPI_Recv(read_buffer, BUFFERSIZE, MPI_CHAR, 0, - TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus); - MPI_Recv(&which_atom, 1, MPI_INT, 0, - TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); - - myStatus = 1; - parseErr = parseDumpLine( read_buffer, which_atom ); - if( parseErr != NULL ){ - strcpy( painCave.errMsg, parseErr ); - myStatus = 0;; - simError(); + if(localIndex == -1) { + sprintf(painCave.errMsg, "Molecule not found on node %d\n", worldRank); + haveError = 1; + simError(); + } + + integrableObjects = (simnfo->molecules[localIndex]).getIntegrableObjects(); + + nCurObj = integrableObjects.size(); + + MPI_Send(&nCurObj, 1, MPI_INT, 0, + TAKE_THIS_TAG_INT, MPI_COMM_WORLD); + + for(j = 0; j < integrableObjects.size(); j++){ + + MPI_Recv(read_buffer, BUFFERSIZE, MPI_CHAR, 0, + TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus); + + parseErr = parseDumpLine(read_buffer, integrableObjects[j]); + + if( parseErr != NULL ){ + strcpy( painCave.errMsg, parseErr ); + simError(); + } + + } + } - MPI_Send( &myStatus, 1, MPI_INT, 0, - TAKE_THIS_TAG_INT, MPI_COMM_WORLD); - } + } - - // last thing last, enable fatalities. - painCave.isEventLoop = 0; - simnfo->setTime( time ); - - for(i=0;i<3;i++) - for(j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i]; - - simnfo->setBoxM( theBoxMat3 ); - - #endif } -char* DumpReader::parseDumpLine(char* readLine, int globalIndex){ +char* DumpReader::parseDumpLine(char* readLine, StuntDouble* sd){ - char *foo; // the pointer to the current string token - + char *foo; // the pointer to the current string token + double pos[3]; // position place holders double vel[3]; // velocity placeholders double q[4]; // the quaternions - double jx, jy, jz; // angular velocity placeholders; + double ji[3]; // angular velocity placeholders; double qSqr, qLength; // needed to normalize the quaternion vector. - - Atom **atoms = simnfo->atoms; - DirectionalAtom* dAtom; - - int j, n_atoms, atomIndex; -#ifdef IS_MPI - n_atoms = mpiSim->getTotAtoms(); - atomIndex=-1; - for (j=0; j < mpiSim->getMyNlocal(); j++) { - if (atoms[j]->getGlobalIndex() == globalIndex) atomIndex = j; - } - if (atomIndex == -1) { - sprintf( painCave.errMsg, - "Initialize from file error. Atom at index %d " - "in file %s does not exist on processor %d .\n", - globalIndex, inName, mpiSim->getMyNode() ); - return strdup( painCave.errMsg ); - } -#else - n_atoms = simnfo->n_atoms; - atomIndex = globalIndex; -#endif // is_mpi + + // set the string tokenizer - // set the string tokenizer - foo = strtok(readLine, " ,;\t"); - + // check the atom name to the current atom - - if( strcmp( foo, atoms[atomIndex]->getType() ) ){ + + if( strcmp( foo, sd->getType() ) ){ sprintf( painCave.errMsg, - "Initialize from file error. Atom %s at index %d " - "in file %s does not" + "DumpReader error. Does not" " match the BASS atom %s.\n", - foo, atomIndex, inName, atoms[atomIndex]->getType() ); + sd->getType() ); return strdup( painCave.errMsg ); } - + // get the positions foo = strtok(NULL, " ,;\t"); if(foo == NULL){ sprintf( painCave.errMsg, - "error in reading postition x from %s\n" - "natoms = %d, index = %d\n", - inName, n_atoms, atomIndex ); + "error in reading postition x from %s\n", + inFileName.c_str()); return strdup( painCave.errMsg ); } pos[0] = atof( foo ); - + foo = strtok(NULL, " ,;\t"); if(foo == NULL){ sprintf( painCave.errMsg, - "error in reading postition y from %s\n" - "natoms = %d, index = %d\n", - inName, n_atoms, atomIndex ); + "error in reading postition y from %s\n", + inFileName.c_str()); return strdup( painCave.errMsg ); } pos[1] = atof( foo ); - + foo = strtok(NULL, " ,;\t"); if(foo == NULL){ sprintf( painCave.errMsg, - "error in reading postition z from %s\n" - "natoms = %d, index = %d\n", - inName, n_atoms, atomIndex ); + "error in reading postition z from %s\n", + inFileName.c_str()); return strdup( painCave.errMsg ); } - pos[2] = atof( foo ); + pos[2] = atof( foo ); // get the velocities \ No newline at end of file @@ -547,327 +509,255 @@ char* DumpReader::parseDumpLine(char* readLine, int gl foo = strtok(NULL, " ,;\t"); if(foo == NULL){ sprintf( painCave.errMsg, - "error in reading velocity x from %s\n" - "natoms = %d, index = %d\n", - inName, n_atoms, atomIndex ); + "error in reading velocity x from %s\n", + inFileName.c_str() ); return strdup( painCave.errMsg ); } vel[0] = atof( foo ); - + foo = strtok(NULL, " ,;\t"); if(foo == NULL){ sprintf( painCave.errMsg, - "error in reading velocity y from %s\n" - "natoms = %d, index = %d\n", - inName, n_atoms, atomIndex ); + "error in reading velocity x from %s\n", + inFileName.c_str() ); return strdup( painCave.errMsg ); } vel[1] = atof( foo ); - + foo = strtok(NULL, " ,;\t"); if(foo == NULL){ sprintf( painCave.errMsg, - "error in reading velocity z from %s\n" - "natoms = %d, index = %d\n", - inName, n_atoms, atomIndex ); + "error in reading velocity x from %s\n", + inFileName.c_str() ); return strdup( painCave.errMsg ); } vel[2] = atof( foo ); - - + + + // add the positions and velocities to the atom + + sd->setPos( pos ); + sd->setVel( vel ); + + if (!sd->isDirectional()) + return NULL; + // get the quaternions - - if( atoms[atomIndex]->isDirectional() ){ - + + if( sd->isDirectional() ){ + foo = strtok(NULL, " ,;\t"); if(foo == NULL){ - sprintf(painCave.errMsg, - "error in reading quaternion 0 from %s\n" - "natoms = %d, index = %d\n", - inName, n_atoms, atomIndex ); + sprintf( painCave.errMsg, + "error in reading velocity x from %s\n", + inFileName.c_str() ); return strdup( painCave.errMsg ); } q[0] = atof( foo ); - + foo = strtok(NULL, " ,;\t"); if(foo == NULL){ sprintf( painCave.errMsg, - "error in reading quaternion 1 from %s\n" - "natoms = %d, index = %d\n", - inName, n_atoms, atomIndex ); + "error in reading velocity x from %s\n", + inFileName.c_str() ); return strdup( painCave.errMsg ); } q[1] = atof( foo ); - + foo = strtok(NULL, " ,;\t"); if(foo == NULL){ sprintf( painCave.errMsg, - "error in reading quaternion 2 from %s\n" - "natoms = %d, index = %d\n", - inName, n_atoms, atomIndex ); + "error in reading velocity x from %s\n", + inFileName.c_str() ); return strdup( painCave.errMsg ); } q[2] = atof( foo ); - + foo = strtok(NULL, " ,;\t"); if(foo == NULL){ sprintf( painCave.errMsg, - "error in reading quaternion 3 from %s\n" - "natoms = %d, index = %d\n", - inName, n_atoms, atomIndex ); + "error in reading velocity x from %s\n", + inFileName.c_str() ); return strdup( painCave.errMsg ); } q[3] = atof( foo ); - + // get the angular velocities - + foo = strtok(NULL, " ,;\t"); if(foo == NULL){ sprintf( painCave.errMsg, - "error in reading angular momentum jx from %s\n" - "natoms = %d, index = %d\n", - inName, n_atoms, atomIndex ); + "error in reading velocity x from %s\n", + inFileName.c_str() ); return strdup( painCave.errMsg ); } - jx = atof( foo ); - + ji[0] = atof( foo ); + foo = strtok(NULL, " ,;\t"); if(foo == NULL){ sprintf( painCave.errMsg, - "error in reading angular momentum jy from %s\n" - "natoms = %d, index = %d\n", - inName, n_atoms, atomIndex ); + "error in reading velocity x from %s\n", + inFileName.c_str() ); return strdup( painCave.errMsg ); } - jy = atof(foo ); - + ji[1] = atof(foo ); + foo = strtok(NULL, " ,;\t"); if(foo == NULL){ sprintf( painCave.errMsg, - "error in reading angular momentum jz from %s\n" - "natoms = %d, index = %d\n", - inName, n_atoms, atomIndex ); + "error in reading velocity x from %s\n", + inFileName.c_str() ); return strdup( painCave.errMsg ); } - jz = atof( foo ); - - dAtom = ( DirectionalAtom* )atoms[atomIndex]; + ji[2] = atof( foo ); + // check that the quaternion vector is normalized qSqr = (q[0] * q[0]) + (q[1] * q[1]) + (q[2] * q[2]) + (q[3] * q[3]); - + qLength = sqrt( qSqr ); q[0] = q[0] / qLength; q[1] = q[1] / qLength; q[2] = q[2] / qLength; q[3] = q[3] / qLength; - - dAtom->setQ( q ); - - // add the angular velocities - dAtom->setJx( jx ); - dAtom->setJy( jy ); - dAtom->setJz( jz ); + // add quaternion and angular velocities + + sd->setQ( q ); + sd->setJ( ji ); } - - // add the positions and velocities to the atom - atoms[atomIndex]->setPos( pos ); - atoms[atomIndex]->setVel( vel ); + return NULL; } -char* DumpReader::parseCommentLine(char* readLine, double &time, - double boxMat[9]){ +char* DumpReader::parseCommentLine(char* readLine, SimInfo* entry_plug){ - char *foo; // the pointer to the current string token - int j; - double chi, integralOfChidt; + double currTime; + double boxMat[9]; + double theBoxMat3[3][3]; + double chi; + double integralOfChidt; double eta[9]; + char *foo; // the pointer to the current string token + // set the string tokenizer - + foo = strtok(readLine, " ,;\t"); + // set the timeToken. + if(foo == NULL){ sprintf( painCave.errMsg, - "error in reading time from %s\n", - inName ); + "error in reading Time from %s\n", + inFileName.c_str() ); return strdup( painCave.errMsg ); } - time = atof( foo ); - // get the Hx vector + currTime = atof( foo ); + entry_plug->setTime( currTime ); - foo = strtok(NULL, " ,;\t"); - if(foo == NULL){ - sprintf( painCave.errMsg, - "error in reading Hx[0] from %s\n", - inName ); - return strdup( painCave.errMsg ); - } - boxMat[0] = atof( foo ); - - foo = strtok(NULL, " ,;\t"); - if(foo == NULL){ - sprintf( painCave.errMsg, - "error in reading Hx[1] from %s\n", - inName ); - return strdup( painCave.errMsg ); - } - boxMat[1] = atof( foo ); - - foo = strtok(NULL, " ,;\t"); - if(foo == NULL){ - sprintf( painCave.errMsg, - "error in reading Hx[2] from %s\n", - inName ); - return strdup( painCave.errMsg ); - } - boxMat[2] = atof( foo ); + //get H-Matrix - // get the Hy vector - - foo = strtok(NULL, " ,;\t"); - if(foo == NULL){ - sprintf( painCave.errMsg, - "error in reading Hy[0] from %s\n", - inName ); - return strdup( painCave.errMsg ); + for(int i = 0 ; i < 9; i++){ + foo = strtok(NULL, " ,;\t"); + if(foo == NULL){ + sprintf( painCave.errMsg, + "error in reading H[%d] from %s\n", i, inFileName.c_str() ); + return strdup( painCave.errMsg ); + } + boxMat[i] = atof( foo ); } - boxMat[3] = atof( foo ); - - foo = strtok(NULL, " ,;\t"); - if(foo == NULL){ - sprintf( painCave.errMsg, - "error in reading Hy[1] from %s\n", - inName ); - return strdup( painCave.errMsg ); - } - boxMat[4] = atof( foo ); - - foo = strtok(NULL, " ,;\t"); - if(foo == NULL){ - sprintf( painCave.errMsg, - "error in reading Hy[2] from %s\n", - inName ); - return strdup( painCave.errMsg ); - } - boxMat[5] = atof( foo ); - // get the Hz vector + for(int i=0;i<3;i++) + for(int j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i]; - foo = strtok(NULL, " ,;\t"); - if(foo == NULL){ - sprintf( painCave.errMsg, - "error in reading Hz[0] from %s\n", - inName ); - return strdup( painCave.errMsg ); - } - boxMat[6] = atof( foo ); - - foo = strtok(NULL, " ,;\t"); - if(foo == NULL){ - sprintf( painCave.errMsg, - "error in reading Hz[1] from %s\n", - inName ); - return strdup( painCave.errMsg ); - } - boxMat[7] = atof( foo ); - - foo = strtok(NULL, " ,;\t"); - if(foo == NULL){ - sprintf( painCave.errMsg, - "error in reading Hz[2] from %s\n", - inName ); - return strdup( painCave.errMsg ); - } - boxMat[8] = atof( foo ); + //set H-Matrix + entry_plug->setBoxM( theBoxMat3 ); - return NULL; - //get chi and integralOfChidt, they should appear by pair - foo = strtok(NULL, " ,;\t\n"); - if(foo != NULL){ - chi = atof(foo); + + if( entry_plug->useInitXSstate ){ + 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", inFileName.c_str() ); + 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); + entry_plug->addProperty(chiValue); + + DoubleData* integralOfChidtValue = new DoubleData(); + integralOfChidtValue->setID(INTEGRALOFCHIDT_ID); + integralOfChidtValue->setData(integralOfChidt); + entry_plug->addProperty(integralOfChidtValue); + + } + else + return NULL; + //get eta 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 ); + if(foo != NULL ){ + + for(int i = 0 ; i < 9; i++){ + + if(foo == NULL){ + sprintf( painCave.errMsg, + "error in reading eta[%d] from %s\n", i, inFileName.c_str() ); + return strdup( painCave.errMsg ); + } + eta[i] = atof( foo ); + foo = strtok(NULL, " ,;\t\n"); + } } - integralOfChidt = atof( foo ); + else + return NULL; - //push chi and integralOfChidt into SimInfo::properties which can be + //push eta 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); - + //entry_plug->setBoxM( theBoxMat3 ); + DoubleArrayData* etaValue = new DoubleArrayData(); + etaValue->setID(ETAVALUE_ID); + etaValue->setData(eta, 9); + entry_plug->addProperty(etaValue); } - 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; - - + return NULL; } - #ifdef IS_MPI - -// a couple of functions to let us escape the read loop - -void dumpRead::nodeZeroError( void ){ +void DumpReader::nodeZeroError( void ){ int j, myStatus; - + myStatus = 0; - for (j = 0; j < mpiSim->getNumberProcessors(); j++) { - MPI_Send( &myStatus, 1, MPI_INT, j, + for (j = 0; j < mpiSim->getNumberProcessors(); j++) { + MPI_Send( &myStatus, 1, MPI_INT, j, TAKE_THIS_TAG_INT, MPI_COMM_WORLD); - } - + } + MPI_Finalize(); exit (0); - + } -void dumpRead::anonymousNodeDie( void ){ +void DumpReader::anonymousNodeDie( void ){ MPI_Finalize(); exit (0); } - -#endif //is_mpi +#endif \ No newline at end of file