Commit 505054bc authored by Kilian Lackhove's avatar Kilian Lackhove
Browse files

moved chk backup logic into FieldIO::SetupOutput

parent 19b85a78
......@@ -85,6 +85,7 @@ enum FieldIOType {
eHDF5
};
/**
* @brief Determine file type of given input file.
*
......@@ -309,7 +310,7 @@ LIB_UTILITIES_EXPORT void Import(
* @brief Constructor for FieldIO base class.
*/
FieldIO::FieldIO(LibUtilities::CommSharedPtr pComm, bool sharedFilesystem)
: m_comm(pComm), m_sharedFilesystem(sharedFilesystem)
: m_comm(pComm), m_sharedFilesystem(sharedFilesystem), m_backup(false)
{
}
......@@ -406,6 +407,20 @@ std::string FieldIO::SetUpOutput(const std::string outname, bool perRank)
// serial.
fs::path specPath(outname), fulloutname;
if (m_backup && (rank == 0 || !m_sharedFilesystem))
{
fs::path newPath = specPath;
int cnt = 0;
while (fs::exists(newPath))
{
newPath = specPath.parent_path();
newPath += specPath.stem();
newPath += fs::path("_" + boost::lexical_cast<std::string>(cnt++));
newPath += specPath.extension();
}
specPath = newPath;
}
if (nprocs == 1)
{
fulloutname = specPath;
......
......@@ -248,6 +248,9 @@ public:
const std::string &filename,
FieldMetaDataMap &fieldmetadatamap);
LIB_UTILITIES_EXPORT bool GetDoBackup();
LIB_UTILITIES_EXPORT void SetDoBackup(bool backup);
LIB_UTILITIES_EXPORT static const std::string GetFileType(
const std::string &filename, CommSharedPtr comm);
LIB_UTILITIES_EXPORT virtual const std::string &GetClassName() const = 0;
......@@ -263,6 +266,8 @@ protected:
LibUtilities::CommSharedPtr m_comm;
/// Boolean dictating whether we are on a shared filesystem.
bool m_sharedFilesystem;
/// Boolean dictating whether we should backup existing files
bool m_backup;
LIB_UTILITIES_EXPORT void AddInfoTag(
TagWriterSharedPtr root,
......
......@@ -124,6 +124,7 @@ namespace Nektar
// Instantiate a field reader/writer
m_fld = LibUtilities::FieldIO::CreateDefault(m_session);
m_fld->SetDoBackup(true);
// Read the geometry and the expansion information
m_graph = SpatialDomains::MeshGraph::Read(m_session);
......@@ -1987,14 +1988,6 @@ namespace Nektar
{
std::string outname = m_sessionName + "_" +
boost::lexical_cast<std::string>(n);
int cnt = 0;
while (boost::filesystem::exists(outname + ".chk"))
{
outname = m_sessionName + "_" +
boost::lexical_cast<std::string>(n) + "_" +
boost::lexical_cast<std::string>(cnt++);
}
WriteFld(outname + ".chk");
}
......@@ -2010,13 +2003,6 @@ namespace Nektar
{
std::string outname = m_sessionName + "_" +
boost::lexical_cast<std::string>(n);
int cnt = 0;
while (boost::filesystem::exists(outname + ".chk"))
{
outname = m_sessionName + "_" +
boost::lexical_cast<std::string>(n) + "_" +
boost::lexical_cast<std::string>(cnt++);
}
WriteFld(outname, field, fieldcoeffs, variables);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment