From 5702570108af8cff96b9f991887768a9eab88a40 Mon Sep 17 00:00:00 2001 From: Thomas Fetzer <thomas.fetzer@iws.uni-stuttgart.de> Date: Tue, 18 Apr 2017 14:44:02 +0200 Subject: [PATCH] [io][gnuplotinterface] Add functionality for output to specific folder (cherry picked from commit 4d0e694fc22b50a5a8e7664f8485e0dc3affad65) --- dumux/io/gnuplotinterface.hh | 19 +++++++++++++++---- test/io/gnuplotinterface/CMakeLists.txt | 1 + .../gnuplotinterface/test_gnuplotinterface.cc | 1 + 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/dumux/io/gnuplotinterface.hh b/dumux/io/gnuplotinterface.hh index b5589f79b8..024c0b4689 100644 --- a/dumux/io/gnuplotinterface.hh +++ b/dumux/io/gnuplotinterface.hh @@ -64,7 +64,7 @@ public: //! \brief The constructor GnuplotInterface(bool persist = true) : pipe_(0), openPlotWindow_(true), persist_(persist), - terminalType_("x11"), + terminalType_("x11"), outputDirectory_("./"), datafileSeparator_(' '), linetype_("solid"), xRangeIsSet_(false), yRangeIsSet_(false), xLabel_(""), yLabel_(""), @@ -144,9 +144,9 @@ public: plot += "set term pngcairo size 800,600 " + linetype_ + " \n"; plot += "set output \"" + filename + ".png\"\n"; plot += "replot\n"; - std::string fileName = filename + ".gp"; + std::string gnuplotFileName = outputDirectory_ + filename + ".gp"; std::ofstream file; - file.open(fileName); + file.open(gnuplotFileName); file << plot; file.close(); } @@ -253,7 +253,7 @@ public: // write data to file std::ofstream file; - file.open(fileName); + file.open(outputDirectory_ + fileName); for (unsigned int i = 0; i < x.size(); i++) { checkNumber(x[i], "x[i] i=" + std::to_string(i) + " in " + fileName); @@ -353,6 +353,16 @@ public: terminalType_ = terminal; } + /*! + * \brief Sets the output directory for data and gnuplot files + * + * \param outputDirectory The user-specified terminal + */ + void setOutputDirectory(std::string outputDirectory) + { + outputDirectory_ = outputDirectory + "/"; + } + /*! * \brief Use dashed (true) or solid (false) lines * @@ -386,6 +396,7 @@ private: bool openPlotWindow_; bool persist_; std::string terminalType_; + std::string outputDirectory_; char datafileSeparator_; std::string linetype_; StringVector curveFile_; diff --git a/test/io/gnuplotinterface/CMakeLists.txt b/test/io/gnuplotinterface/CMakeLists.txt index 35b9be2d7f..65e5411b57 100644 --- a/test/io/gnuplotinterface/CMakeLists.txt +++ b/test/io/gnuplotinterface/CMakeLists.txt @@ -1,3 +1,4 @@ +file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/output") add_dumux_test(test_gnuplotinterface test_gnuplotinterface test_gnuplotinterface.cc ${CMAKE_CURRENT_BINARY_DIR}/test_gnuplotinterface) diff --git a/test/io/gnuplotinterface/test_gnuplotinterface.cc b/test/io/gnuplotinterface/test_gnuplotinterface.cc index 1bdf5fc288..05c72643ec 100644 --- a/test/io/gnuplotinterface/test_gnuplotinterface.cc +++ b/test/io/gnuplotinterface/test_gnuplotinterface.cc @@ -52,6 +52,7 @@ int main() yMax = max(yMax, y[i]); } + gnuplot.setOutputDirectory("output"); gnuplot.setXRange(0, 5); gnuplot.setYRange(yMin, yMax); gnuplot.setXlabel("x [-]"); -- GitLab