Skip to content
Snippets Groups Projects
Commit ed7024a2 authored by Timo Koch's avatar Timo Koch
Browse files

Merge branch 'cherry-pick-035da38c' into 'next'

Merge branch 'fix/gnuplotinterface' into 'master'

See merge request !481
parents 57025701 aa5adb16
No related branches found
No related tags found
Loading
...@@ -56,10 +56,9 @@ class GnuplotInterface ...@@ -56,10 +56,9 @@ class GnuplotInterface
{ {
public: public:
typedef std::vector<std::string> StringVector; typedef std::vector<std::string> StringVector;
enum PlotStyle enum class CurveType
{ { function, file, data };
lines, points, linesPoints, impulses, dots typedef std::vector<CurveType> CurveTypeVector;
};
//! \brief The constructor //! \brief The constructor
GnuplotInterface(bool persist = true) : GnuplotInterface(bool persist = true) :
...@@ -122,13 +121,27 @@ public: ...@@ -122,13 +121,27 @@ public:
// plot curves // plot curves
plot += "plot"; plot += "plot";
for (unsigned int i = 0; i < curveFile_.size(); ++i) std::string plotCommandForFile(plot);
for (unsigned int i = 0; i < curve_.size(); ++i)
{ {
plot += + " " + curveFile_[i] if (curveType_[i] == CurveType::function)
+ " " + curveOptions_[i]; {
if (i < curveFile_.size()-1) plot += + " " + curve_[i] + " " + curveOptions_[i];
plotCommandForFile += + " " + curve_[i] + " " + curveOptions_[i];
}
else
{
plot += + " '" + outputDirectory_ + curve_[i] + "' " + curveOptions_[i];
plotCommandForFile += + " '" + curve_[i] + "' " + curveOptions_[i];
}
if (i < curve_.size()-1)
{
plot += ",\\"; plot += ",\\";
plotCommandForFile += ",\\";
}
plot += "\n"; plot += "\n";
plotCommandForFile += "\n";
} }
// live plot of the results if gnuplot is installed // live plot of the results if gnuplot is installed
...@@ -140,14 +153,14 @@ public: ...@@ -140,14 +153,14 @@ public:
// create a gnuplot file if a filename is specified // create a gnuplot file if a filename is specified
if (filename.compare("") != 0) if (filename.compare("") != 0)
{ {
plot += "\n"; plotCommandForFile += "\n";
plot += "set term pngcairo size 800,600 " + linetype_ + " \n"; plotCommandForFile += "set term pngcairo size 800,600 " + linetype_ + " \n";
plot += "set output \"" + filename + ".png\"\n"; plotCommandForFile += "set output \"" + filename + ".png\"\n";
plot += "replot\n"; plotCommandForFile += "replot\n";
std::string gnuplotFileName = outputDirectory_ + filename + ".gp"; std::string gnuplotFileName = outputDirectory_ + filename + ".gp";
std::ofstream file; std::ofstream file;
file.open(gnuplotFileName); file.open(gnuplotFileName);
file << plot; file << plotCommandForFile;
file.close(); file.close();
} }
} }
...@@ -167,13 +180,13 @@ public: ...@@ -167,13 +180,13 @@ public:
*/ */
void resetPlot() void resetPlot()
{ {
curveFile_.clear(); curve_.clear();
curveOptions_.clear(); curveOptions_.clear();
plotOptions_ = ""; plotOptions_ = "";
} }
/*! /*!
* \brief Closes gnuplot * \brief Opens gnuplot
*/ */
void open(const bool persist = true) void open(const bool persist = true)
{ {
...@@ -209,8 +222,9 @@ public: ...@@ -209,8 +222,9 @@ public:
void addFunctionToPlot(const std::string function, void addFunctionToPlot(const std::string function,
const std::string options = "with lines") const std::string options = "with lines")
{ {
curveFile_.push_back(function); curve_.push_back(function);
curveOptions_.push_back(options); curveOptions_.push_back(options);
curveType_.push_back(CurveType::function);
} }
DUNE_DEPRECATED_MSG("The signature of addFileToPlot(string, string, string) has been changed to addFileToPlot(string, string).") DUNE_DEPRECATED_MSG("The signature of addFileToPlot(string, string, string) has been changed to addFileToPlot(string, string).")
...@@ -230,8 +244,9 @@ public: ...@@ -230,8 +244,9 @@ public:
void addFileToPlot(const std::string fileName, void addFileToPlot(const std::string fileName,
const std::string options = "with lines") const std::string options = "with lines")
{ {
curveFile_.push_back("'" + fileName + "'"); curve_.push_back(fileName);
curveOptions_.push_back(options); curveOptions_.push_back(options);
curveType_.push_back(CurveType::file);
} }
/*! /*!
...@@ -263,8 +278,9 @@ public: ...@@ -263,8 +278,9 @@ public:
file.close(); file.close();
// adding file to list of plotted lines // adding file to list of plotted lines
curveFile_.push_back("'" + fileName + "'"); curve_.push_back(fileName);
curveOptions_.push_back(options); curveOptions_.push_back(options);
curveType_.push_back(CurveType::data);
} }
/*! /*!
...@@ -399,8 +415,9 @@ private: ...@@ -399,8 +415,9 @@ private:
std::string outputDirectory_; std::string outputDirectory_;
char datafileSeparator_; char datafileSeparator_;
std::string linetype_; std::string linetype_;
StringVector curveFile_; StringVector curve_;
StringVector curveOptions_; StringVector curveOptions_;
CurveTypeVector curveType_;
bool interaction_; bool interaction_;
Scalar xRangeMin_; Scalar xRangeMin_;
Scalar xRangeMax_; Scalar xRangeMax_;
......
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