1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2025-04-10 19:20:44 +01:00

Plot: now handling gunplot through a forked process to allow interactivity (default terminal is now 'qt')

This commit is contained in:
Antonin Portelli 2015-05-13 17:38:47 +01:00
parent a9bb53bc1b
commit 7f2c8b6742
2 changed files with 35 additions and 44 deletions

View File

@ -62,7 +62,7 @@ string PlotObject::dumpToTmpFile(const DMat &m)
for (Index j = 0; j < m.cols(); ++j) for (Index j = 0; j < m.cols(); ++j)
{ {
} }
strcpy(tmpFileName, "./latan_plot_tmp.XXXXXX.dat"); strcpy(tmpFileName, "/tmp/latan_plot_tmp.XXXXXX.dat");
fd = mkstemps(tmpFileName, 4); fd = mkstemps(tmpFileName, 4);
if (fd == -1) if (fd == -1)
{ {
@ -276,30 +276,10 @@ Plot::Plot(void)
initOptions(); initOptions();
} }
// destructor //////////////////////////////////////////////////////////////////
Plot::~Plot(void)
{
cleanTmpFiles();
}
// clean temporary files ///////////////////////////////////////////////////////
void Plot::cleanTmpFiles(void)
{
for (string &fileName: tmpFileName_)
{
if (remove(fileName.c_str()))
{
LATAN_ERROR(System, "impossible to remove temporary file '" +
fileName + "'");
}
}
tmpFileName_.clear();
}
// default options ///////////////////////////////////////////////////////////// // default options /////////////////////////////////////////////////////////////
void Plot::initOptions(void) void Plot::initOptions(void)
{ {
options_.terminal = ""; options_.terminal = "qt";
options_.output = ""; options_.output = "";
options_.caption = ""; options_.caption = "";
options_.title = ""; options_.title = "";
@ -317,7 +297,6 @@ void Plot::reset(void)
{ {
headCommand_.clear(); headCommand_.clear();
plotCommand_.clear(); plotCommand_.clear();
cleanTmpFiles();
initOptions(); initOptions();
} }
@ -424,27 +403,41 @@ void Plot::getProgramPath(void)
// plot parsing and output ///////////////////////////////////////////////////// // plot parsing and output /////////////////////////////////////////////////////
void Plot::display(void) void Plot::display(void)
{ {
string command; int pid = fork();
FILE *gnuplotPipe;
if (pid == 0)
if (!getenv("DISPLAY"))
{ {
LATAN_ERROR(System, "cannot find DISPLAY variable: is it set ?"); FILE *gnuplotPipe;
string command;
ostringstream scriptBuf;
if (!getenv("DISPLAY"))
{
LATAN_ERROR(System, "cannot find DISPLAY variable: is it set ?");
}
getProgramPath();
command = gnuplotPath_ + "/" + gnuplotBin_;
gnuplotPipe = popen(command.c_str(), "w");
if (!gnuplotPipe)
{
LATAN_ERROR(System, "error starting gnuplot (command was '"
+ command + "')");
}
commandBuffer_.str("");
commandBuffer_ << *this << endl;
commandBuffer_ << "pause mouse close" << endl;
fprintf(gnuplotPipe, "%s", commandBuffer_.str().c_str());
if (pclose(gnuplotPipe) == -1)
{
LATAN_ERROR(System, "problem closing communication to gnuplot");
}
exit(EXIT_SUCCESS);
} }
getProgramPath(); else if (pid == -1)
command = gnuplotPath_ + "/" + gnuplotBin_ + " " + gnuplotArgs_;
gnuplotPipe = popen(command.c_str(), "w");
if (!gnuplotPipe)
{ {
LATAN_ERROR(System, "error starting gnuplot (command was '" + command perror("fork error");
+ "')"); LATAN_ERROR(System, "problem forking to the process handling gnuplot");
}
commandBuffer_.str("");
commandBuffer_ << *this;
fprintf(gnuplotPipe, "%s", commandBuffer_.str().c_str());
if (pclose(gnuplotPipe) == -1)
{
LATAN_ERROR(System, "problem closing communication to gnuplot");
} }
} }

View File

@ -256,7 +256,7 @@ public:
public: public:
// constructor/destructor // constructor/destructor
Plot(void); Plot(void);
virtual ~Plot(void); virtual ~Plot(void) = default;
// plot operations // plot operations
Plot & operator<<(PlotObject &&command); Plot & operator<<(PlotObject &&command);
Plot & operator<<(PlotModifier &&modifier); Plot & operator<<(PlotModifier &&modifier);
@ -267,8 +267,6 @@ public:
// plot reset // plot reset
void reset(void); void reset(void);
private: private:
// clean temporary files
void cleanTmpFiles(void);
// find gnuplot // find gnuplot
void getProgramPath(void); void getProgramPath(void);
// default options // default options