--- trunk/mdtools/md_code/DumpWriter.cpp 2002/11/21 20:33:02 183 +++ trunk/mdtools/md_code/DumpWriter.cpp 2002/11/21 20:33:06 184 @@ -8,150 +8,187 @@ DumpWriter::DumpWriter( SimInfo* the_entry_plug ){ DumpWriter::DumpWriter( SimInfo* the_entry_plug ){ - entry_plug = the_entry_plug; - - strcpy( outName, entry_plug->sampleName ); - outFile.open(outName, ios::out | ios::trunc ); - - if( !outFile ){ +#ifdef IS_MPI + if(worldRank == TESTWRITE ){ +#endif // is_mpi - sprintf( painCave.errMsg, - "Could not open \"%s\" for dump output.\n", - outName); - painCave.isFatal = 1; - simError(); - } + entry_plug = the_entry_plug; + + strcpy( outName, entry_plug->sampleName ); + + std::cerr << "Opening " << outName << " for dumping.\n"; + + outFile.open(outName, ios::out | ios::trunc ); + + if( !outFile ){ + + sprintf( painCave.errMsg, + "Could not open \"%s\" for dump output.\n", + outName); + painCave.isFatal = 1; + simError(); + } - //outFile.setf( ios::scientific ); + //outFile.setf( ios::scientific ); + +#ifdef IS_MPI + } +#endif // is_mpi } DumpWriter::~DumpWriter( ){ - outFile.close(); +#ifdef IS_MPI + if(worldRank == TESTWRITE ){ +#endif // is_mpi + + outFile.close(); + +#ifdef IS_MPI + } +#endif // is_mpi } void DumpWriter::writeDump( double currentTime ){ - int i; - double q[4]; - DirectionalAtom* dAtom; - int nAtoms = entry_plug->n_atoms; - Atom** atoms = entry_plug->atoms; +#ifdef IS_MPI + if(worldRank == TESTWRITE ){ +#endif // is_mpi - outFile << nAtoms << "\n"; - - outFile << currentTime << "\t" - << entry_plug->box_x << "\t" - << entry_plug->box_y << "\t" - << entry_plug->box_z << "\n"; - - for( i=0; igetType() << "\t" - << atoms[i]->getX() << "\t" - << atoms[i]->getY() << "\t" - << atoms[i]->getZ() << "\t" - << atoms[i]->get_vx() << "\t" - << atoms[i]->get_vy() << "\t" - << atoms[i]->get_vz() << "\t"; - - if( atoms[i]->isDirectional() ){ + int i; + double q[4]; + DirectionalAtom* dAtom; + int nAtoms = entry_plug->n_atoms; + Atom** atoms = entry_plug->atoms; + + + outFile << nAtoms << "\n"; + + outFile << currentTime << "\t" + << entry_plug->box_x << "\t" + << entry_plug->box_y << "\t" + << entry_plug->box_z << "\n"; + + for( i=0; igetQ( q ); - outFile - << q[0] << "\t" - << q[1] << "\t" - << q[2] << "\t" - << q[3] << "\t" - << dAtom->getJx() << "\t" - << dAtom->getJy() << "\t" - << dAtom->getJz() << "\n"; + << atoms[i]->getType() << "\t" + << atoms[i]->getX() << "\t" + << atoms[i]->getY() << "\t" + << atoms[i]->getZ() << "\t" + << atoms[i]->get_vx() << "\t" + << atoms[i]->get_vy() << "\t" + << atoms[i]->get_vz() << "\t"; + + if( atoms[i]->isDirectional() ){ + + dAtom = (DirectionalAtom *)atoms[i]; + dAtom->getQ( q ); + + outFile + << q[0] << "\t" + << q[1] << "\t" + << q[2] << "\t" + << q[3] << "\t" + << dAtom->getJx() << "\t" + << dAtom->getJy() << "\t" + << dAtom->getJz() << "\n"; + } + else{ + outFile + << 0.0 << "\t" + << 0.0 << "\t" + << 0.0 << "\t" + << 0.0 << "\t" + << 0.0 << "\t" + << 0.0 << "\t" + << 0.0 << "\n"; + } } - else{ - outFile - << 0.0 << "\t" - << 0.0 << "\t" - << 0.0 << "\t" - << 0.0 << "\t" - << 0.0 << "\t" - << 0.0 << "\t" - << 0.0 << "\n"; - } + outFile.flush(); + +#ifdef IS_MPI } - outFile.flush(); +#endif // is_mpi } + void DumpWriter::writeFinal(){ - char finalName[500]; - strcpy( finalName, entry_plug->finalName ); +#ifdef IS_MPI + if(worldRank == TESTWRITE ){ +#endif // is_mpi - ofstream finalOut( finalName ); - if( !finalOut ){ - sprintf( painCave.errMsg, - "Could not open \"%s\" for final dump output.\n", - finalName ); - painCave.isFatal = 1; - simError(); - } - - // finalOut.setf( ios::scientific ); - + char finalName[500]; + strcpy( finalName, entry_plug->finalName ); - int i; - double q[4]; - DirectionalAtom* dAtom; - int nAtoms = entry_plug->n_atoms; - Atom** atoms = entry_plug->atoms; - - - finalOut << nAtoms << "\n"; - - finalOut << 0.0 << "\t" - << entry_plug->box_x << "\t" - << entry_plug->box_y << "\t" - << entry_plug->box_z << "\n"; - - for( i=0; igetType() << "\t" - << atoms[i]->getX() << "\t" - << atoms[i]->getY() << "\t" - << atoms[i]->getZ() << "\t" - << atoms[i]->get_vx() << "\t" - << atoms[i]->get_vy() << "\t" - << atoms[i]->get_vz() << "\t"; - - if( atoms[i]->isDirectional() ){ + ofstream finalOut( finalName ); + if( !finalOut ){ + sprintf( painCave.errMsg, + "Could not open \"%s\" for final dump output.\n", + finalName ); + painCave.isFatal = 1; + simError(); + } + + // finalOut.setf( ios::scientific ); + + + int i; + double q[4]; + DirectionalAtom* dAtom; + int nAtoms = entry_plug->n_atoms; + Atom** atoms = entry_plug->atoms; + + + finalOut << nAtoms << "\n"; + + finalOut << 0.0 << "\t" + << entry_plug->box_x << "\t" + << entry_plug->box_y << "\t" + << entry_plug->box_z << "\n"; + + for( i=0; igetQ( q ); - finalOut - << q[0] << "\t" - << q[1] << "\t" - << q[2] << "\t" - << q[3] << "\t" - << dAtom->getJx() << "\t" - << dAtom->getJy() << "\t" - << dAtom->getJz() << "\n"; + << atoms[i]->getType() << "\t" + << atoms[i]->getX() << "\t" + << atoms[i]->getY() << "\t" + << atoms[i]->getZ() << "\t" + << atoms[i]->get_vx() << "\t" + << atoms[i]->get_vy() << "\t" + << atoms[i]->get_vz() << "\t"; + + if( atoms[i]->isDirectional() ){ + + dAtom = (DirectionalAtom *)atoms[i]; + dAtom->getQ( q ); + + finalOut + << q[0] << "\t" + << q[1] << "\t" + << q[2] << "\t" + << q[3] << "\t" + << dAtom->getJx() << "\t" + << dAtom->getJy() << "\t" + << dAtom->getJz() << "\n"; + } + else{ + finalOut + << 0.0 << "\t" + << 0.0 << "\t" + << 0.0 << "\t" + << 0.0 << "\t" + << 0.0 << "\t" + << 0.0 << "\t" + << 0.0 << "\n"; + } } - else{ - finalOut - << 0.0 << "\t" - << 0.0 << "\t" - << 0.0 << "\t" - << 0.0 << "\t" - << 0.0 << "\t" - << 0.0 << "\t" - << 0.0 << "\n"; - } + finalOut.close(); + +#ifdef IS_MPI } - finalOut.close(); +#endif // is_mpi }