Skip to content
Snippets Groups Projects
Commit 6a610bdd authored by Christoph Lehmann's avatar Christoph Lehmann Committed by GitHub
Browse files

Merge pull request #1331 from chleh/fix-dot-path

Fix dots in VTU file names
parents 1478df67 558e8bbc
No related branches found
No related tags found
No related merge requests found
......@@ -141,11 +141,11 @@ std::string extractPath(std::string const& pathname)
return "";
return pathname.substr(0, pos + 1);
}
static const char * pathSeparator =
static const char pathSeparator =
#ifdef _WIN32
"\\";
'\\';
#else
"/";
'/';
#endif
std::string appendPathSeparator(std::string const& path)
......@@ -157,12 +157,18 @@ std::string appendPathSeparator(std::string const& path)
std::string joinPaths(std::string const& pathA, std::string const& pathB)
{
std::string tmpB(pathB);
if(tmpB.substr(0, 1) == ".")
tmpB = tmpB.substr(1);
if(tmpB.substr(0, 1) == pathSeparator)
tmpB = tmpB.substr(1);
return appendPathSeparator(pathA) + tmpB;
if (pathA.empty())
return pathB;
if (pathB.empty())
return pathA;
if (pathB.front() == pathSeparator) {
auto const tmpB = pathB.substr(1);
return appendPathSeparator(pathA) + tmpB;
} else {
return appendPathSeparator(pathA) + pathB;
}
}
} // end namespace BaseLib
......@@ -77,12 +77,17 @@ bool VtuInterface::writeToFile(std::string const &file_name)
// and PETSC_COMM_WORLD should be replaced with the argument.
int mpi_rank;
MPI_Comm_rank(PETSC_COMM_WORLD, &mpi_rank);
std::string file_name_base = boost::erase_last_copy(file_name, ".vtu");
auto const file_name_base = boost::erase_last_copy(file_name, ".vtu");
auto const dirname = BaseLib::extractPath(file_name_base);
auto basename = BaseLib::extractBaseName(file_name_base);
// Since the pvtu writing function drops all letters from the letter of '.'.
std::replace(file_name_base.begin(), file_name_base.end(), '.', '_');
std::replace(basename.begin(), basename.end(), '.', '_');
auto const vtu_file_name = BaseLib::joinPaths(dirname, basename);
const std::string file_name_rank = file_name_base + "_"
const std::string file_name_rank = vtu_file_name + "_"
+ std::to_string(mpi_rank) + ".vtu";
bool vtu_status_i = writeVTU<vtkXMLUnstructuredGridWriter>(file_name_rank);
bool vtu_status = false;
......@@ -93,7 +98,7 @@ bool VtuInterface::writeToFile(std::string const &file_name)
bool pvtu_status = false;
if (mpi_rank == 0)
{
pvtu_status = writeVTU<vtkXMLPUnstructuredGridWriter>(file_name_base + ".pvtu", mpi_size);
pvtu_status = writeVTU<vtkXMLPUnstructuredGridWriter>(vtu_file_name + ".pvtu", mpi_size);
}
MPI_Bcast(&pvtu_status, 1, MPI_C_BOOL, 0, PETSC_COMM_WORLD);
......
......@@ -391,12 +391,13 @@ TEST(BaseLib, ExtractPathUnix)
TEST(BaseLib, JoinPaths)
{
#if _WIN32
ASSERT_EQ ( "\\path\\path", BaseLib::joinPaths("\\path", "path") );
ASSERT_EQ ( "\\path\\path", BaseLib::joinPaths("\\path", "\\path") );
ASSERT_EQ ( "\\path\\path", BaseLib::joinPaths("\\path", ".\\path") );
ASSERT_EQ ( "\\path\\path", BaseLib::joinPaths("\\path\\", "\\path") );
ASSERT_EQ ( "\\path\\.\\path", BaseLib::joinPaths("\\path", ".\\path") );
#else
ASSERT_EQ ( "/path/path", BaseLib::joinPaths("/path", "path") );
ASSERT_EQ ( "/path/path", BaseLib::joinPaths("/path", "/path") );
ASSERT_EQ ( "/path/path", BaseLib::joinPaths("/path", "./path") );
ASSERT_EQ ( "/path/path", BaseLib::joinPaths("/path/", "/path") );
ASSERT_EQ ( "/path/./path", BaseLib::joinPaths("/path", "./path") );
ASSERT_EQ ( "/path", BaseLib::joinPaths("/", "path") );
#endif
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment