--- trunk/src/io/DumpWriter.cpp 2005/02/13 19:10:25 324 +++ trunk/src/io/DumpWriter.cpp 2005/03/03 14:40:20 395 @@ -42,13 +42,41 @@ #include "io/DumpWriter.hpp" #include "primitives/Molecule.hpp" #include "utils/simError.h" - +#include "io/basic_teebuf.hpp" #ifdef IS_MPI #include #endif //is_mpi namespace oopse { + +DumpWriter::DumpWriter(SimInfo* info) + : info_(info), filename_(info->getDumpFileName()), eorFilename_(info->getFinalConfigFileName()){ +#ifdef IS_MPI + + if (worldRank == 0) { +#endif // is_mpi + + dumpFile_.open(filename_.c_str(), std::ios::out | std::ios::trunc); + + if (!dumpFile_) { + sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", + filename_.c_str()); + painCave.isFatal = 1; + simError(); + } + +#ifdef IS_MPI + + } + + sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n"); + MPIcheckPoint(); + +#endif // is_mpi + +} + DumpWriter::DumpWriter(SimInfo* info, const std::string& filename) : info_(info), filename_(filename){ #ifdef IS_MPI @@ -56,6 +84,7 @@ DumpWriter::DumpWriter(SimInfo* info, const std::strin if (worldRank == 0) { #endif // is_mpi + eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor"; dumpFile_.open(filename_.c_str(), std::ios::out | std::ios::trunc); if (!dumpFile_) { @@ -120,7 +149,7 @@ void DumpWriter::writeCommentLine(std::ostream& os, Sn << eta(0, 1) << "\t" << eta(1, 1) << "\t" << eta(2, 1) << ";\t" << eta(0, 2) << "\t" << eta(1, 2) << "\t" << eta(2, 2) << ";"; - os << std::endl; + os << "\n"; } void DumpWriter::writeFrame(std::ostream& os) { @@ -229,7 +258,6 @@ void DumpWriter::writeFrame(std::ostream& os) { int which_node; double atomData[13]; int isDirectional; - const char * atomTypeString; char MPIatomTypeString[MINIBUFFERSIZE]; int msgLen; // the length of message actually recieved at master nodes int haveError; @@ -301,8 +329,6 @@ void DumpWriter::writeFrame(std::ostream& os) { which_node, myPotato, MPI_COMM_WORLD, &istatus); - atomTypeString = MPIatomTypeString; - myPotato++; MPI_Recv(atomData, 13, MPI_DOUBLE, which_node, myPotato, @@ -320,7 +346,7 @@ void DumpWriter::writeFrame(std::ostream& os) { if (!isDirectional) { sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", - atomTypeString, atomData[0], + MPIatomTypeString, atomData[0], atomData[1], atomData[2], atomData[3], atomData[4], atomData[5]); @@ -330,7 +356,7 @@ void DumpWriter::writeFrame(std::ostream& os) { } else { sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", - atomTypeString, + MPIatomTypeString, atomData[0], atomData[1], atomData[2], @@ -362,9 +388,7 @@ void DumpWriter::writeFrame(std::ostream& os) { } for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; - integrableObject = mol->nextIntegrableObject(ii)) { - - atomTypeString = integrableObject->getType().c_str(); + integrableObject = mol->nextIntegrableObject(ii)) { pos = integrableObject->getPos(); vel = integrableObject->getVel(); @@ -403,7 +427,7 @@ void DumpWriter::writeFrame(std::ostream& os) { if (!isDirectional) { sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", - atomTypeString, atomData[0], + integrableObject->getType().c_str(), atomData[0], atomData[1], atomData[2], atomData[3], atomData[4], atomData[5]); @@ -413,7 +437,7 @@ void DumpWriter::writeFrame(std::ostream& os) { } else { sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", - atomTypeString, + integrableObject->getType().c_str(), atomData[0], atomData[1], atomData[2], @@ -486,8 +510,6 @@ void DumpWriter::writeFrame(std::ostream& os) { &istatus); } - atomTypeString = integrableObject->getType().c_str(); - pos = integrableObject->getPos(); vel = integrableObject->getVel(); @@ -517,7 +539,7 @@ void DumpWriter::writeFrame(std::ostream& os) { atomData[12] = ji[2]; } - strncpy(MPIatomTypeString, atomTypeString, MINIBUFFERSIZE); + strncpy(MPIatomTypeString, integrableObject->getType().c_str(), MINIBUFFERSIZE); // null terminate the std::string before sending (just in case): MPIatomTypeString[MINIBUFFERSIZE - 1] = '\0'; @@ -543,10 +565,70 @@ void DumpWriter::writeFrame(std::ostream& os) { } sprintf(checkPointMsg, "Sucessfully took a dump.\n"); MPIcheckPoint(); + } + +#endif // is_mpi + +} + +void DumpWriter::writeDump() { + writeFrame(dumpFile_); + +} + +void DumpWriter::writeEor() { + std::ofstream eorStream; + +#ifdef IS_MPI + if (worldRank == 0) { +#endif // is_mpi + + eorStream.open(eorFilename_.c_str()); + if (!eorStream.is_open()) { + sprintf(painCave.errMsg, "DumpWriter : Could not open \"%s\" for writing.\n", + eorFilename_.c_str()); + painCave.isFatal = 1; + simError(); + } + +#ifdef IS_MPI } +#endif // is_mpi + writeFrame(eorStream); +} + + +void DumpWriter::writeDumpAndEor() { + std::ofstream eorStream; + std::vector buffers; +#ifdef IS_MPI + if (worldRank == 0) { #endif // is_mpi + buffers.push_back(dumpFile_.rdbuf()); + + eorStream.open(eorFilename_.c_str()); + if (!eorStream.is_open()) { + sprintf(painCave.errMsg, "DumpWriter : Could not open \"%s\" for writing.\n", + eorFilename_.c_str()); + painCave.isFatal = 1; + simError(); + } + + buffers.push_back(eorStream.rdbuf()); + +#ifdef IS_MPI + } +#endif // is_mpi + + TeeBuf tbuf(buffers.begin(), buffers.end()); + std::ostream os(&tbuf); + + writeFrame(os); + } + + }//end namespace oopse