--- trunk/mdtools/md_code/StatWriter.cpp 2002/07/09 18:40:59 11 +++ trunk/mdtools/md_code/StatWriter.cpp 2003/02/03 21:15:59 261 @@ -3,41 +3,85 @@ #include #include "ReadWrite.hpp" +#include "simError.h" StatWriter::StatWriter( SimInfo* the_entry_plug ){ entry_plug = the_entry_plug; - - strcpy( outName, entry_plug->statusName ); - outFile.open(outName, ios::out | ios::trunc ); - - if( !outFile ){ + +#ifdef IS_MPI + if(worldRank == 0 ){ +#endif // is_mpi + + strcpy( outName, entry_plug->statusName ); - cerr << "Could not open \"" << outName << "\" for stat output.\n"; - exit(8); + std::cerr << "Opening " << outName << " for stat\n"; + + outFile.open(outName, ios::out | ios::trunc ); + + if( !outFile ){ + + sprintf( painCave.errMsg, + "Could not open \"%s\" for stat output.\n", + outName); + painCave.isFatal = 1; + simError(); + } + + //outFile.setf( ios::scientific ); + outFile << "#time(fs)\ttot_E\tpotential\tkinetic\ttemperature\n"; + + + +#ifdef IS_MPI } - - //outFile.setf( ios::scientific ); - outFile << "#time(fs)\ttot_E\tpotential\tkinetic\ttemperature\n"; - + + sprintf( checkPointMsg, + "Sucessfully opened output file for stating.\n"); + MPIcheckPoint(); +#endif // is_mpi + tStats = new Thermo( entry_plug ); } StatWriter::~StatWriter( ){ - outFile.close(); - delete tStats; +#ifdef IS_MPI + if(worldRank == 0 ){ +#endif // is_mpi + + outFile.close(); + delete tStats; + +#ifdef IS_MPI + } +#endif // is_mpi } void StatWriter::writeStat( double currentTime ){ - outFile.precision(8); - outFile - << currentTime << "\t" - << tStats->getTotalE() << "\t" - << tStats->getPotential() << "\t" - << tStats->getKinetic() << "\t" - << tStats->getTemperature() << "\n"; - outFile.flush(); + double totE, potE, kinE, temp; + + totE = tStats->getTotalE(); + potE = tStats->getPotential(); + kinE = tStats->getKinetic(); + temp = tStats->getTemperature(); + +#ifdef IS_MPI + if(worldRank == 0 ){ +#endif // is_mpi + + outFile.precision(8); + outFile + << currentTime << "\t" + << totE << "\t" + << potE << "\t" + << kinE << "\t" + << temp << "\n"; + outFile.flush(); + +#ifdef IS_MPI + } +#endif // is_mpi }