--- trunk/OOPSE/libmdtools/InitializeFromFile.cpp 2003/07/10 22:15:53 590 +++ trunk/OOPSE/libmdtools/InitializeFromFile.cpp 2003/08/12 19:56:49 689 @@ -26,7 +26,10 @@ using namespace initFile; #endif // is_mpi -InitializeFromFile :: InitializeFromFile( char *in_name ){ +InitializeFromFile::InitializeFromFile( char *in_name ){ + + std::cerr << "Hello from Initialize from file.\n"; + #ifdef IS_MPI if (worldRank == 0) { #endif @@ -48,7 +51,7 @@ InitializeFromFile :: InitializeFromFile( char *in_nam return; } -InitializeFromFile :: ~InitializeFromFile( ){ +InitializeFromFile::~InitializeFromFile( ){ #ifdef IS_MPI if (worldRank == 0) { #endif @@ -69,7 +72,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,6 +86,7 @@ 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]; @@ -123,7 +127,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 ); painCave.isFatal = 1; @@ -134,6 +138,7 @@ void InitializeFromFile :: read_xyz( SimInfo* the_simn 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++){ @@ -210,7 +215,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; @@ -218,6 +223,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(); @@ -272,6 +278,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) { @@ -309,6 +316,7 @@ void InitializeFromFile :: read_xyz( SimInfo* the_simn for(j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i]; simnfo->setBoxM( theBoxMat3 ); + simnfo->setTime( currTime ); #endif @@ -318,8 +326,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. @@ -372,7 +380,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){ @@ -382,7 +390,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){ @@ -392,7 +400,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 @@ -405,7 +413,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){ @@ -415,7 +423,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){ @@ -425,7 +433,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 @@ -527,19 +535,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; @@ -547,8 +551,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