Skip to content

Commit

Permalink
Fix gnuplot detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Bieder committed Aug 15, 2023
1 parent 5e80fff commit f095d01
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion configure1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Initial information about the package
AC_INIT([Agate],[1.4.0],[[email protected]])
AC_INIT([Agate],[1.4.1],[[email protected]])

# Check source directory
AC_CONFIG_SRCDIR([bin/agate.cpp])
Expand Down
26 changes: 12 additions & 14 deletions src/plot/gnuplot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ Gnuplot::Gnuplot() : Graph(),
_buffer(),
_custom()
{
_gp.reset(popen("gnuplot","w"));
if (errno != 0) {
pclose(_gp.release());
_gp=nullptr;
}
if ( _gp.get() == nullptr )
errno = 0;
auto* fd = popen("gnuplot","w");
auto ret = pclose(fd);
if ( ret != 0 )
throw EXCEPTION("Unable to open pipe for gnuplot",ERRABT);
_gp.reset(popen("gnuplot","w"));
_header << "reset" << std::endl;
_header << "set style data line" << std::endl;
_header << "set autoscale xy" << std::endl;
Expand All @@ -57,10 +56,9 @@ Gnuplot::~Gnuplot() {
if ( _gp != nullptr ) {
fprintf(_gp.get(),"%s\n","quit");
fflush(_gp.get());
r_val = pclose(_gp.get());
_gp.release();
if (r_val == -1) {
Exception e(EXCEPTION("Can not close gnuplot", ERRABT));
r_val = pclose(_gp.release());
if (r_val != 0) {
Exception e(EXCEPTION("Gnuplot returned non-zero code", ERRABT));
std::cerr << e.fullWhat() << std::endl;
}
}
Expand Down Expand Up @@ -111,7 +109,7 @@ void Gnuplot::plot(const std::vector<double> &x, const std::list<std::vector<dou
total << "set title '" << _title << "'" << std::endl;
total << _buffer.str();

if ( _gp.get() != nullptr ) {
if ( _gp != nullptr ) {
fprintf(_gp.get(),"%s\n",total.str().c_str());
fflush(_gp.get());
}
Expand Down Expand Up @@ -162,7 +160,7 @@ void Gnuplot::plot(const std::vector<double> &x, const std::list<std::vector<dou
total << "set title '" << _title << "'" << std::endl;
total << _buffer.str();

if ( _gp.get() != nullptr ) {
if ( _gp != nullptr ) {
fprintf(_gp.get(),"%s\n",total.str().c_str());
fflush(_gp.get());
}
Expand Down Expand Up @@ -212,7 +210,7 @@ void Gnuplot::plot(const std::list<std::pair<std::vector<double>,std::vector<dou
total << "set title '" << _title << "'" << std::endl;
total << _buffer.str();

if ( _gp.get() != nullptr ) {
if ( _gp != nullptr ) {
fprintf(_gp.get(),"%s\n",total.str().c_str());
fflush(_gp.get());
}
Expand All @@ -223,7 +221,7 @@ void Gnuplot::save(const std::string &filename) {
std::stringstream com;
this->dump(com,filename);

if ( _gp.get() != nullptr ) {
if ( _gp != nullptr ) {
fprintf(_gp.get(),"%s\n",com.str().c_str());
fflush(_gp.get());
}
Expand Down

0 comments on commit f095d01

Please sign in to comment.