--- branches/mmeineke/OOPSE/libmdtools/InitializeFromFile.cpp 2003/03/21 17:42:12 377 +++ trunk/OOPSE/libmdtools/InitializeFromFile.cpp 2004/06/11 17:16:21 1268 @@ -1,5 +1,6 @@ +#define _FILE_OFFSET_BITS 64 #include -#include +#include #include #include @@ -10,14 +11,25 @@ #include "ReadWrite.hpp" #include "simError.h" +#include "GenericData.hpp" #ifdef IS_MPI +#include #include "mpiSimulation.hpp" +#define TAKE_THIS_TAG_CHAR 3134 +#define TAKE_THIS_TAG_INT 3135 -#define TAKE_THIS_TAG 0 +namespace initFile{ + void nodeZeroError( void ); + void anonymousNodeDie( void ); +} + +using namespace initFile; + #endif // is_mpi -InitializeFromFile :: InitializeFromFile( char *in_name ){ +InitializeFromFile::InitializeFromFile( char *in_name ){ + #ifdef IS_MPI if (worldRank == 0) { #endif @@ -29,17 +41,21 @@ InitializeFromFile :: InitializeFromFile( char *in_nam painCave.isFatal = 1; simError(); } - + strcpy( c_in_name, in_name); #ifdef IS_MPI } - strcpy( checkPointMsg, "Infile opened for reading successfully." ); + else{ + sprintf( c_in_name, "mpiNodeParser_%d", worldRank ); + } + + strcpy( checkPointMsg, "Infile opened for reading successfully." ); MPIcheckPoint(); #endif - return; + return; } -InitializeFromFile :: ~InitializeFromFile( ){ +InitializeFromFile::~InitializeFromFile( ){ #ifdef IS_MPI if (worldRank == 0) { #endif @@ -60,24 +76,26 @@ InitializeFromFile :: ~InitializeFromFile( ){ } -void InitializeFromFile :: read_xyz( SimInfo* the_entry_plug ){ +void InitializeFromFile :: readInit( SimInfo* the_simnfo ){ - int i; // 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; - entry_plug = the_entry_plug; + vector integrableObjects; + simnfo = the_simnfo; + #ifndef IS_MPI eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); if( eof_test == NULL ){ @@ -88,22 +106,19 @@ void InitializeFromFile :: read_xyz( SimInfo* the_entr simError(); } - n_atoms = atoi( read_buffer ); + nTotObjs = atoi( read_buffer ); - Atom **atoms = entry_plug->atoms; - DirectionalAtom* dAtom; - - if( n_atoms != entry_plug->n_atoms ){ + if( nTotObjs != simnfo->getTotIntegrableObjects() ){ 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, nTotObjs, simnfo->getTotIntegrableObjects()); 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){ sprintf( painCave.errMsg, @@ -112,262 +127,283 @@ void InitializeFromFile :: read_xyz( SimInfo* the_entr simError(); } - for( i=0; i < n_atoms; i++){ - - eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); - 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", - c_in_name, n_atoms, i ); - painCave.isFatal = 1; - simError(); - } - - - parseErr = parseDumpLine( read_buffer, i ); - if( parseErr != NULL ){ - strcpy( painCave.errMsg, parseErr ); - painCave.isFatal = 1; - simError(); - } + parseErr = parseCommentLine( read_buffer, simnfo); + if( parseErr != NULL ){ + strcpy( painCave.errMsg, parseErr ); + painCave.isFatal = 1; + simError(); } + //parse dump lines + for( i=0; i < simnfo->n_mol; i++){ + + integrableObjects = (simnfo->molecules[i]).getIntegrableObjects(); + + for(j = 0; j < integrableObjects.size(); j++){ + + eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); + 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", + c_in_name, 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 - int masterIndex; - int nodeAtomsStart; - int nodeAtomsEnd; - int mpiErr; - int sendError; + // first thing first, suspend fatalities. + painCave.isEventLoop = 1; - MPI_Status istatus[MPI_STATUS_SIZE]; + int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone + int haveError; + MPI_Status istatus; + int *MolToProcMap = mpiSim->getMolToProcMap(); + int localIndex; + int nCurObj; + int nItems; + + nTotObjs = simnfo->getTotIntegrableObjects(); + haveError = 0; if (worldRank == 0) { + eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); if( eof_test == NULL ){ sprintf( painCave.errMsg, - "Error reading 1st line of %d \n ",c_in_name); - painCave.isFatal = 1; + "Error reading 1st line of %s \n ",c_in_name); + haveError = 1; simError(); } - - n_atoms = atoi( read_buffer ); - - Atom **atoms = entry_plug->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, " "does not match the BASS file's n_atoms, %d.\n", - c_in_name, n_atoms, entry_plug->n_atoms ); - painCave.isFatal = 1; + c_in_name, nTotObjs, simnfo->getTotIntegrableObjects()); + 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); - painCave.isFatal = 1; + haveError = 1; simError(); } - - // Read Proc 0 share of the xyz file... - masterIndex = 0; - for( i=0; i <= mpiSim->getMyAtomEnd(); i++){ - - eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); - 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", - c_in_name, n_atoms, i ); - painCave.isFatal = 1; - simError(); - } - - parseErr = parseDumpLine( read_buffer, i ); - if( parseErr != NULL ){ - strcpy( painCave.errMsg, parseErr ); - painCave.isFatal = 1; - simError(); - } - masterIndex++; + + //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(); } - } - sprintf(checkPointMsg, - "Node 0 has successfully read positions from input file."); - MPIcheckPoint(); + for (i=0 ; i < mpiSim->getNMolGlobal(); i++) { + which_node = MolToProcMap[i]; + if(which_node == 0){ + //molecules belong to master node - for (procIndex = 1; procIndex < mpiSim->getNumberProcessors(); - procIndex++){ - if (worldRank == 0) { + localIndex = mpiSim->getGlobalToLocalMol(i); - mpiErr = MPI_Recv(&nodeAtomsStart,1,MPI_INT,procIndex,TAKE_THIS_TAG,MPI_COMM_WORLD, - istatus); + if(localIndex == -1) { + strcpy(painCave.errMsg, "Molecule not found on node 0!"); + haveError = 1; + simError(); + } - mpiErr = MPI_Recv(&nodeAtomsEnd,1,MPI_INT,procIndex,TAKE_THIS_TAG,MPI_COMM_WORLD, - istatus); - // Make sure where node 0 is reading from, matches where the receiving node - // expects it to be. + integrableObjects = (simnfo->molecules[localIndex]).getIntegrableObjects(); + for(j=0; j < integrableObjects.size(); j++){ + + eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); + 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", + c_in_name, nTotObjs, i ); + haveError= 1; + simError(); + } + + if(haveError) nodeZeroError(); - if (masterIndex != nodeAtomsStart){ - sendError = 1; - mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,TAKE_THIS_TAG,MPI_COMM_WORLD); - sprintf(painCave.errMsg, - "Initialize from file error: atoms start index (%d) for " - "node %d not equal to master index (%d)",nodeAtomsStart,procIndex,masterIndex ); - painCave.isFatal = 1; - simError(); + parseDumpLine(read_buffer, integrableObjects[j]); + + } + + } - sendError = 0; - mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,TAKE_THIS_TAG,MPI_COMM_WORLD); - - for ( i = nodeAtomsStart; i <= nodeAtomsEnd; i++){ - eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); - if(eof_test == NULL){ - - sprintf(read_buffer,"ERROR"); - mpiErr = MPI_Send(read_buffer,BUFFERSIZE,MPI_CHAR,procIndex,TAKE_THIS_TAG,MPI_COMM_WORLD); - - sprintf(painCave.errMsg, - "error in reading file %s\n" - "natoms = %d; index = %d\n" - "error reading the line from the file.\n", - c_in_name, n_atoms, i ); - painCave.isFatal = 1; - simError(); - } - - mpiErr = MPI_Send(read_buffer,BUFFERSIZE,MPI_CHAR,procIndex,TAKE_THIS_TAG,MPI_COMM_WORLD); - mpiErr = MPI_Recv(&sendError,1,MPI_INT,procIndex,TAKE_THIS_TAG,MPI_COMM_WORLD, - istatus); - if (sendError) MPIcheckPoint(); + else{ + //molecule belongs to slave nodes - masterIndex++; + MPI_Recv(&nCurObj, 1, MPI_INT, which_node, + TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); + + for(j=0; j < nCurObj; j++){ + + eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); + 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", + c_in_name, nTotObjs, i ); + haveError= 1; + simError(); + } + + if(haveError) nodeZeroError(); + + MPI_Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node, + TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); + + } + } + } + + } + else{ + //actions taken at slave nodes + MPI_Bcast(read_buffer, BUFFERSIZE, MPI_CHAR, 0, MPI_COMM_WORLD); - else if(worldRank == procIndex){ - nodeAtomsStart = mpiSim->getMyAtomStart(); - nodeAtomsEnd = mpiSim->getMyAtomEnd(); - mpiErr = MPI_Send(&nodeAtomsStart,1,MPI_INT,0,TAKE_THIS_TAG,MPI_COMM_WORLD); - mpiErr = MPI_Send(&nodeAtomsEnd,1,MPI_INT,0,TAKE_THIS_TAG,MPI_COMM_WORLD); + parseErr = parseCommentLine( read_buffer, simnfo); + + if( parseErr != NULL ){ + strcpy( painCave.errMsg, parseErr ); + haveError = 1; + simError(); + } + + for (i=0 ; i < mpiSim->getNMolGlobal(); i++) { + which_node = MolToProcMap[i]; - mpiErr = MPI_Recv(&sendError,1,MPI_INT,0,TAKE_THIS_TAG,MPI_COMM_WORLD, - istatus); - if (sendError) MPIcheckPoint(); + if(which_node == worldRank){ + //molecule with global index i belongs to this processor + + localIndex = mpiSim->getGlobalToLocalMol(i); - for ( i = 0; i < entry_plug->n_atoms; i++){ + if(localIndex == -1) { + sprintf(painCave.errMsg, "Molecule not found on node %d\n", worldRank); + haveError = 1; + simError(); + } - mpiErr = MPI_Recv(&read_buffer,BUFFERSIZE,MPI_CHAR,0,TAKE_THIS_TAG,MPI_COMM_WORLD, - istatus); - - if(!strcmp(read_buffer, "ERROR")) MPIcheckPoint(); - - parseErr = parseDumpLine( read_buffer, i ); - if( parseErr != NULL ){ - sendError = 1; - mpiErr = MPI_Send(&sendError,1,MPI_INT,0,TAKE_THIS_TAG,MPI_COMM_WORLD); + integrableObjects = (simnfo->molecules[localIndex]).getIntegrableObjects(); + nCurObj = integrableObjects.size(); + + MPI_Send(&nCurObj, 1, MPI_INT, 0, + TAKE_THIS_TAG_INT, MPI_COMM_WORLD); - strcpy( painCave.errMsg, parseErr ); - painCave.isFatal = 1; - simError(); - } - sendError = 0; - mpiErr = MPI_Send(&sendError,1,MPI_INT,0,TAKE_THIS_TAG,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(); + } + + } + } + } - sprintf(checkPointMsg,"Node %d received initial configuration.",procIndex); - MPIcheckPoint(); - } + } #endif } +char* InitializeFromFile::parseDumpLine(char* readLine, StuntDouble* sd){ -char* InitializeFromFile::parseDumpLine(char* readLine, int atomIndex){ + char *foo; // the pointer to the current string token - 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 ji[3]; // angular velocity placeholders; double qSqr, qLength; // needed to normalize the quaternion vector. - - Atom **atoms = entry_plug->atoms; - DirectionalAtom* dAtom; - - int n_atoms; -#ifdef IS_MPI - n_atoms = mpiSim->getTotAtoms(); -#else - n_atoms = entry_plug->n_atoms; -#endif // is_mpi - // 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" + "Initialize from file error. Does not" " match the BASS atom %s.\n", - foo, atomIndex, c_in_name, 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", - c_in_name, n_atoms, atomIndex ); + "error in reading postition x from %s\n", + c_in_name); return strdup( painCave.errMsg ); } - rx = atof( foo ); - + 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", - c_in_name, n_atoms, atomIndex ); + "error in reading postition y from %s\n", + c_in_name); return strdup( painCave.errMsg ); } - ry = atof( foo ); - + 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", - c_in_name, n_atoms, atomIndex ); + "error in reading postition z from %s\n", + c_in_name); return strdup( painCave.errMsg ); } - rz = atof( foo ); + pos[2] = atof( foo ); // get the velocities @@ -375,140 +411,265 @@ char* InitializeFromFile::parseDumpLine(char* readLine foo = strtok(NULL, " ,;\t"); if(foo == NULL){ sprintf( painCave.errMsg, - "error in reading velocity x from %s\n" - "natoms = %d, index = %d\n", - c_in_name, n_atoms, atomIndex ); + "error in reading velocity x from %s\n", + c_in_name ); return strdup( painCave.errMsg ); } - vx = atof( foo ); - + 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", - c_in_name, n_atoms, atomIndex ); + "error in reading velocity x from %s\n", + c_in_name ); return strdup( painCave.errMsg ); } - vy = atof( foo ); - + 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", - c_in_name, n_atoms, atomIndex ); + "error in reading velocity x from %s\n", + c_in_name ); return strdup( painCave.errMsg ); } - vz = atof( foo ); - - + 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", - c_in_name, n_atoms, atomIndex ); + sprintf( painCave.errMsg, + "error in reading velocity x from %s\n", + c_in_name ); 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", - c_in_name, n_atoms, atomIndex ); + "error in reading velocity x from %s\n", + c_in_name ); 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", - c_in_name, n_atoms, atomIndex ); + "error in reading velocity x from %s\n", + c_in_name ); 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", - c_in_name, n_atoms, atomIndex ); + "error in reading velocity x from %s\n", + c_in_name ); 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", - c_in_name, n_atoms, atomIndex ); + "error in reading velocity x from %s\n", + c_in_name ); 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", - c_in_name, n_atoms, atomIndex ); + "error in reading velocity x from %s\n", + c_in_name ); 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", - c_in_name, n_atoms, atomIndex ); + "error in reading velocity x from %s\n", + c_in_name ); 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]); - + + if (fabs(qSqr) < 1e-6) { + sprintf(painCave.errMsg, + "initial quaternion error (q0^2 + q1^2 + q2^2 + q3^2 ~ 0).\n"); + return strdup(painCave.errMsg); + } + 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 ); } + + + + return NULL; +} + + +char* InitializeFromFile::parseCommentLine(char* readLine, SimInfo* entry_plug){ + + 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", + c_in_name ); + return strdup( painCave.errMsg ); + } + + currTime = atof( foo ); + entry_plug->setTime( currTime ); + + //get H-Matrix + + 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, c_in_name ); + return strdup( painCave.errMsg ); + } + boxMat[i] = atof( foo ); + } + + for(int i=0;i<3;i++) + for(int j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i]; + + //set H-Matrix + entry_plug->setBoxM( theBoxMat3 ); + + //get chi and integralOfChidt, they should appear by pair + + 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", c_in_name ); + 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; - // add the positions and velocities to the atom + //get eta + foo = strtok(NULL, " ,;\t\n"); + 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, c_in_name ); + return strdup( painCave.errMsg ); + } + eta[i] = atof( foo ); + foo = strtok(NULL, " ,;\t\n"); + } + } + else + return NULL; - atoms[atomIndex]->setX( rx ); - atoms[atomIndex]->setY( ry ); - atoms[atomIndex]->setZ( rz ); + //push eta into SimInfo::properties which can be + //retrieved by integrator later - atoms[atomIndex]->set_vx( vx ); - atoms[atomIndex]->set_vy( vy ); - atoms[atomIndex]->set_vz( vz ); + DoubleArrayData* etaValue = new DoubleArrayData(); + etaValue->setID(ETAVALUE_ID); + etaValue->setData(eta, 9); + entry_plug->addProperty(etaValue); + } return NULL; } + +#ifdef IS_MPI + +// a couple of functions to let us escape the read loop + +void initFile::nodeZeroError( void ){ + int j, myStatus; + + myStatus = 0; + for (j = 0; j < mpiSim->getNProcessors(); j++) { + MPI_Send( &myStatus, 1, MPI_INT, j, + TAKE_THIS_TAG_INT, MPI_COMM_WORLD); + } + + + MPI_Finalize(); + exit (0); + +} + +void initFile::anonymousNodeDie( void ){ + + MPI_Finalize(); + exit (0); +} + +#endif //is_mpi