--- trunk/OOPSE/libmdtools/InitializeFromFile.cpp 2003/07/09 22:14:06 586 +++ trunk/OOPSE/libmdtools/InitializeFromFile.cpp 2003/08/12 21:44:06 690 @@ -26,7 +26,8 @@ using namespace initFile; #endif // is_mpi -InitializeFromFile :: InitializeFromFile( char *in_name ){ +InitializeFromFile::InitializeFromFile( char *in_name ){ + #ifdef IS_MPI if (worldRank == 0) { #endif @@ -48,7 +49,7 @@ InitializeFromFile :: InitializeFromFile( char *in_nam return; } -InitializeFromFile :: ~InitializeFromFile( ){ +InitializeFromFile::~InitializeFromFile( ){ #ifdef IS_MPI if (worldRank == 0) { #endif @@ -69,7 +70,7 @@ InitializeFromFile :: ~InitializeFromFile( ){ } -void InitializeFromFile :: read_xyz( SimInfo* the_simnfo ){ +void InitializeFromFile :: readInit( SimInfo* the_simnfo ){ int i, j, done, which_node, which_atom; // loop counter @@ -83,8 +84,9 @@ void InitializeFromFile :: read_xyz( SimInfo* the_simn char *eof_test; // ptr to see when we reach the end of the file char *parseErr; int procIndex; + double currTime; double boxMat[9]; - + double theBoxMat3[3][3]; simnfo = the_simnfo; @@ -123,14 +125,18 @@ void InitializeFromFile :: read_xyz( SimInfo* the_simn simError(); } - parseErr = parseBoxLine( read_buffer, boxMat ); + parseErr = parseBoxLine( read_buffer, boxMat, currTime ); if( parseErr != NULL ){ strcpy( painCave.errMsg, parseErr ); painCave.isFatal = 1; simError(); } - simnfo->setBoxM( boxMat ); + for(i=0;i<3;i++) + for(j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i]; + + simnfo->setBoxM( theBoxMat3 ); + simnfo->setTime( currTime ); for( i=0; i < n_atoms; i++){ @@ -207,7 +213,7 @@ void InitializeFromFile :: read_xyz( SimInfo* the_simn simError(); } - parseErr = parseBoxLine( read_buffer, boxMat ); + parseErr = parseBoxLine( read_buffer, boxMat, currTime ); if( parseErr != NULL ){ strcpy( painCave.errMsg, parseErr ); haveError = 1; @@ -215,6 +221,7 @@ void InitializeFromFile :: read_xyz( SimInfo* the_simn } MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD ); + MPI_Bcast(&currTime, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD ); if(haveError) nodeZeroError(); @@ -269,6 +276,7 @@ void InitializeFromFile :: read_xyz( SimInfo* the_simn } else { MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD); + MPI_Bcast(&currTime, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); done = 0; while (!done) { @@ -301,8 +309,13 @@ void InitializeFromFile :: read_xyz( SimInfo* the_simn // last thing last, enable fatalities. painCave.isEventLoop = 0; - simnfo->setBoxM( boxMat ); + for(i=0;i<3;i++) + for(j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i]; + + simnfo->setBoxM( theBoxMat3 ); + simnfo->setTime( currTime ); + #endif } @@ -311,8 +324,8 @@ char* InitializeFromFile::parseDumpLine(char* readLine 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. @@ -365,7 +378,7 @@ char* InitializeFromFile::parseDumpLine(char* readLine c_in_name, n_atoms, atomIndex ); return strdup( painCave.errMsg ); } - rx = atof( foo ); + pos[0] = atof( foo ); foo = strtok(NULL, " ,;\t"); if(foo == NULL){ @@ -375,7 +388,7 @@ char* InitializeFromFile::parseDumpLine(char* readLine c_in_name, n_atoms, atomIndex ); return strdup( painCave.errMsg ); } - ry = atof( foo ); + pos[1] = atof( foo ); foo = strtok(NULL, " ,;\t"); if(foo == NULL){ @@ -385,7 +398,7 @@ char* InitializeFromFile::parseDumpLine(char* readLine c_in_name, n_atoms, atomIndex ); return strdup( painCave.errMsg ); } - rz = atof( foo ); + pos[2] = atof( foo ); // get the velocities @@ -398,7 +411,7 @@ char* InitializeFromFile::parseDumpLine(char* readLine c_in_name, n_atoms, atomIndex ); return strdup( painCave.errMsg ); } - vx = atof( foo ); + vel[0] = atof( foo ); foo = strtok(NULL, " ,;\t"); if(foo == NULL){ @@ -408,7 +421,7 @@ char* InitializeFromFile::parseDumpLine(char* readLine c_in_name, n_atoms, atomIndex ); return strdup( painCave.errMsg ); } - vy = atof( foo ); + vel[1] = atof( foo ); foo = strtok(NULL, " ,;\t"); if(foo == NULL){ @@ -418,7 +431,7 @@ char* InitializeFromFile::parseDumpLine(char* readLine c_in_name, n_atoms, atomIndex ); return strdup( painCave.errMsg ); } - vz = atof( foo ); + vel[2] = atof( foo ); // get the quaternions @@ -520,19 +533,15 @@ char* InitializeFromFile::parseDumpLine(char* readLine // 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* InitializeFromFile::parseBoxLine(char* readLine, double boxMat[9]){ +char* InitializeFromFile::parseBoxLine(char* readLine, double boxMat[9], + double &time ){ char *foo; // the pointer to the current string token int j; @@ -540,8 +549,15 @@ char* InitializeFromFile::parseBoxLine(char* readLine, // set the string tokenizer foo = strtok(readLine, " ,;\t"); - // ignore the first token which is the time stamp. + // set the timeToken. + if(foo == NULL){ + sprintf( painCave.errMsg, + "error in reading Time from %s\n", + c_in_name ); + return strdup( painCave.errMsg ); + } + time = atof( foo ); // get the Hx vector