Skip to content
Snippets Groups Projects
Commit d5f7fbd9 authored by Lars Bilke's avatar Lars Bilke
Browse files

Added cli option for output directory (-o)

Writes output files to the specified output directory.
parent 0b1918c4
No related branches found
No related tags found
No related merge requests found
......@@ -25,7 +25,7 @@
#include "ProcessLib/NumericsConfig.h"
void solveProcesses(ProjectData &project)
void solveProcesses(ProjectData &project, const std::string &outdir)
{
INFO("Solve processes.");
......@@ -58,8 +58,9 @@ void solveProcesses(ProjectData &project)
}
std::string const output_file_name =
out_pref + "_pcs_" + std::to_string(i) + "_ts_" +
std::to_string(timestep) + ".vtu";
BaseLib::joinPaths(outdir, out_pref) +
"_pcs_" + std::to_string(i) + "_ts_" +
std::to_string(timestep) + ".vtu";
(*p)->postTimestep(output_file_name, timestep);
++i;
......@@ -90,6 +91,14 @@ int main(int argc, char *argv[])
"PROJECT FILE");
cmd.add(project_arg);
TCLAP::ValueArg<std::string> outdir_arg(
"o", "output-directory",
"the output directory to write to",
false,
"",
"output directory");
cmd.add(outdir_arg);
TCLAP::SwitchArg nonfatal_arg("",
"config-warnings-nonfatal",
"warnings from parsing the configuration file will not trigger program abortion");
......@@ -117,9 +126,8 @@ int main(int argc, char *argv[])
(*p_it)->initialize();
}
std::string const output_file_name(project.getOutputFilePrefix() + ".vtu");
solveProcesses(project);
solveProcesses(project, outdir_arg.getValue());
return 0;
}
......@@ -133,4 +133,28 @@ std::string extractPath(std::string const& pathname)
const std::size_t pos = findLastPathSeparator(pathname);
return pathname.substr(0, pos + 1);
}
const char * pathSeparator =
#ifdef _WIN32
"\\";
#else
"/";
#endif
std::string appendPathSeparator(std::string const& path)
{
if(findLastPathSeparator(path) == path.length() - 1)
return path;
return path + pathSeparator;
}
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;
}
} // end namespace BaseLib
......@@ -152,6 +152,17 @@ std::string copyPathToFileName(const std::string &file_name,
* Returns a string up to the last path separator not including it.
*/
std::string extractPath(std::string const& pathname);
/**
* Appends a platform-dependent path separator (/ or \) if missing
*/
std::string appendPathSeparator(std::string const& path);
/**
* Concat two paths. Does not check for validity.
*/
std::string joinPaths(std::string const& pathA, std::string const& pathB);
} // end namespace BaseLib
#endif // FILETOOLS_H
......@@ -278,6 +278,7 @@ private:
#endif
// Write output file
DBUG("Writing output to \'%s\'.", file_name.c_str());
FileIO::VtuInterface vtu_interface(&_mesh, vtkXMLWriter::Binary, true);
vtu_interface.writeToFile(file_name);
}
......
......@@ -387,3 +387,16 @@ TEST(BaseLib, ExtractPathUnix)
ASSERT_EQ ( BaseLib::extractPath("/path/path/file.ext"), "/path/path/" );
ASSERT_EQ ( BaseLib::extractPath("/path/path/path.ext/"), "/path/path/path.ext/" );
}
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") );
#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") );
#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