--- trunk/OOPSE/libmdtools/InitializeFromFile.cpp 2003/04/03 20:21:54 447 +++ trunk/OOPSE/libmdtools/InitializeFromFile.cpp 2003/07/09 22:14:06 586 @@ -69,7 +69,7 @@ void InitializeFromFile :: read_xyz( SimInfo* the_entr } -void InitializeFromFile :: read_xyz( SimInfo* the_entry_plug ){ +void InitializeFromFile :: read_xyz( SimInfo* the_simnfo ){ int i, j, done, which_node, which_atom; // loop counter @@ -83,8 +83,10 @@ void InitializeFromFile :: read_xyz( SimInfo* the_entr char *eof_test; // ptr to see when we reach the end of the file char *parseErr; int procIndex; + double boxMat[9]; + - entry_plug = the_entry_plug; + simnfo = the_simnfo; #ifndef IS_MPI @@ -99,19 +101,19 @@ void InitializeFromFile :: read_xyz( SimInfo* the_entr n_atoms = atoi( read_buffer ); - Atom **atoms = entry_plug->atoms; + Atom **atoms = simnfo->atoms; DirectionalAtom* dAtom; - if( n_atoms != entry_plug->n_atoms ){ + if( n_atoms != simnfo->n_atoms ){ sprintf( painCave.errMsg, "Initialize from File error. %s n_atoms, %d, " "does not match the BASS file's n_atoms, %d.\n", - c_in_name, n_atoms, entry_plug->n_atoms ); + c_in_name, n_atoms, simnfo->n_atoms ); painCave.isFatal = 1; simError(); } - //read and toss the comment line + //read the box mat from the comment line eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); if(eof_test == NULL){ @@ -121,6 +123,16 @@ void InitializeFromFile :: read_xyz( SimInfo* the_entr simError(); } + parseErr = parseBoxLine( read_buffer, boxMat ); + if( parseErr != NULL ){ + strcpy( painCave.errMsg, parseErr ); + painCave.isFatal = 1; + simError(); + } + + simnfo->setBoxM( boxMat ); + + for( i=0; i < n_atoms; i++){ eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); @@ -140,7 +152,7 @@ void InitializeFromFile :: read_xyz( SimInfo* the_entr strcpy( painCave.errMsg, parseErr ); painCave.isFatal = 1; simError(); - } + } } @@ -170,7 +182,7 @@ void InitializeFromFile :: read_xyz( SimInfo* the_entr n_atoms = atoi( read_buffer ); - Atom **atoms = entry_plug->atoms; + Atom **atoms = simnfo->atoms; DirectionalAtom* dAtom; // Check to see that the number of atoms in the intial configuration file is the @@ -180,20 +192,29 @@ void InitializeFromFile :: read_xyz( SimInfo* the_entr sprintf( painCave.errMsg, "Initialize from File error. %s n_atoms, %d, " "does not match the BASS file's n_atoms, %d.\n", - c_in_name, n_atoms, entry_plug->n_atoms ); + c_in_name, n_atoms, simnfo->n_atoms ); haveError= 1; simError(); } - //read and toss the comment line + //read the boxMat from the comment line eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); if(eof_test == NULL){ sprintf( painCave.errMsg, "error in reading commment in %s\n", c_in_name); - haveError= 1; + haveError = 1; + simError(); + } + + parseErr = parseBoxLine( read_buffer, boxMat ); + if( parseErr != NULL ){ + strcpy( painCave.errMsg, parseErr ); + haveError = 1; simError(); } + + MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD ); if(haveError) nodeZeroError(); @@ -247,6 +268,8 @@ void InitializeFromFile :: read_xyz( SimInfo* the_entr } else { + MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD); + done = 0; while (!done) { @@ -278,6 +301,8 @@ void InitializeFromFile :: read_xyz( SimInfo* the_entr // last thing last, enable fatalities. painCave.isEventLoop = 0; + simnfo->setBoxM( boxMat ); + #endif } @@ -292,7 +317,7 @@ char* InitializeFromFile::parseDumpLine(char* readLine double jx, jy, jz; // angular velocity placeholders; double qSqr, qLength; // needed to normalize the quaternion vector. - Atom **atoms = entry_plug->atoms; + Atom **atoms = simnfo->atoms; DirectionalAtom* dAtom; int j, n_atoms, atomIndex; @@ -311,7 +336,7 @@ char* InitializeFromFile::parseDumpLine(char* readLine return strdup( painCave.errMsg ); } #else - n_atoms = entry_plug->n_atoms; + n_atoms = simnfo->n_atoms; atomIndex = globalIndex; #endif // is_mpi @@ -507,6 +532,108 @@ char* InitializeFromFile::parseDumpLine(char* readLine } +char* InitializeFromFile::parseBoxLine(char* readLine, double boxMat[9]){ + + char *foo; // the pointer to the current string token + int j; + + // set the string tokenizer + + foo = strtok(readLine, " ,;\t"); + // ignore the first token which is the time stamp. + + + // get the Hx vector + + foo = strtok(NULL, " ,;\t"); + if(foo == NULL){ + sprintf( painCave.errMsg, + "error in reading Hx[0] from %s\n", + c_in_name ); + 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", + c_in_name ); + 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", + c_in_name ); + return strdup( painCave.errMsg ); + } + boxMat[2] = atof( foo ); + + // get the Hy vector + + foo = strtok(NULL, " ,;\t"); + if(foo == NULL){ + sprintf( painCave.errMsg, + "error in reading Hy[0] from %s\n", + c_in_name ); + return strdup( painCave.errMsg ); + } + boxMat[3] = atof( foo ); + + foo = strtok(NULL, " ,;\t"); + if(foo == NULL){ + sprintf( painCave.errMsg, + "error in reading Hy[1] from %s\n", + c_in_name ); + 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", + c_in_name ); + return strdup( painCave.errMsg ); + } + boxMat[5] = atof( foo ); + + // get the Hz vector + + foo = strtok(NULL, " ,;\t"); + if(foo == NULL){ + sprintf( painCave.errMsg, + "error in reading Hz[0] from %s\n", + c_in_name ); + 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", + c_in_name ); + 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", + c_in_name ); + return strdup( painCave.errMsg ); + } + boxMat[8] = atof( foo ); + + return NULL; +} + + #ifdef IS_MPI // a couple of functions to let us escape the read loop