diff --git a/src/picongpu/include/plugins/common/txtFileHandling.hpp b/src/picongpu/include/plugins/common/txtFileHandling.hpp index a307562fc3..e5f61d7724 100644 --- a/src/picongpu/include/plugins/common/txtFileHandling.hpp +++ b/src/picongpu/include/plugins/common/txtFileHandling.hpp @@ -1,5 +1,5 @@ /** - * Copyright 2015 Axel Huebl + * Copyright 2015 Axel Huebl, Richard Pausch * * This file is part of PIConGPU. * @@ -34,7 +34,8 @@ using namespace boost::filesystem; /** Restore a txt file from the checkpoint dir * * Restores a txt file from the checkpoint dir and starts appending to it. - * Opened files in \see outFile are closed and a valid handle is opened again. + * Opened files in \see outFile are closed and a valid handle is opened again + * if a restart file is found. Otherwise new output file stays untouched. * * \param outFile std::ofstream file handle to regular file that shall be restored * \param filename the file's name @@ -46,28 +47,42 @@ using namespace boost::filesystem; bool restoreTxtFile( std::ofstream& outFile, std::string filename, uint32_t restartStep, const std::string restartDirectory ) { - if( outFile.is_open() ) - outFile.close(); - + /* get restart time step as string */ std::stringstream sStep; sStep << restartStep; + /* set location of restart file and output file */ path src( restartDirectory + std::string("/") + filename + std::string(".") + sStep.str() ); path dst( filename ); - copy_file( src, - dst, - copy_option::overwrite_if_exists ); - - outFile.open( filename.c_str(), std::ofstream::out | std::ostream::app ); - if( !outFile ) + /* check whether restart file exists */ + if( !boost::filesystem::exists( src ) ) { - std::cerr << "[Plugin] Can't open file '" << filename - << "', output disabled" << std::endl; - return false; + /* restart file does not exists */ + log ("Plugin restart file: %1% was not found. \ + --> Starting plugin from current time step.") % src; + return true; + } + else + { + /* restart file found - fix output file created at restart */ + if( outFile.is_open() ) + outFile.close(); + + copy_file( src, + dst, + copy_option::overwrite_if_exists ); + + outFile.open( filename.c_str(), std::ofstream::out | std::ostream::app ); + if( !outFile ) + { + std::cerr << "[Plugin] Can't open file '" << filename + << "', output disabled" << std::endl; + return false; + } + return true; } - return true; } /** Checkpoints a txt file