|
From: Robbie M. <ro...@ac...> - 2011-08-26 14:28:46
|
------------------------------------------------------------
To: Benjamin von Ardenne <ben...@gm...>
Subject: Re: [Gnuplot-info] call gnuplot from c++ (windows)
Message-ID: <201...@ju...>
From: Mathias Anselmann <mat...@li...>
Date: Fri, 26 Aug 2011 12:36:26 +0200
------------------------------------------------------------
Hello Mathias
> So has anybody got a clue for me here?
Here is an extract of the code I use, based on code by
Daniel Stahlke. My platform is GCC + Linux and not Windows.
I remember having to experiment quite a lot to get
the run-time behaviors I want. I also use the "dumb"
during unit testing so that I don't create plot windows.
Note that I set PERSIST as a gnuplot statement and NOT
as a command-line option. Maybe that will work for you?
I'm happy to forward all my code for this unit, if that
would help. GPLv3 + the MIT license from Daniel.
good luck, Robbie
//// HEADER
#include <boost/iostreams/stream.hpp> // stream template
for io
#include <boost/iostreams/device/file_descriptor.hpp> // filesystem access
class Gnuplot :
public boost::iostreams::stream<boost::iostreams::file_descriptor_sink>
{
public:
explicit
Gnuplot
(const std::string cmd);
~Gnuplot();
// BEHAVIOR SET FUNCTIONS
void setTerminal(const std::string& term); // "dumb" "x11" "wxt"
void setPersist(); // plot window remains
// DATA
private:
FILE* pout; // C-style stdlib io
std::string gnuplotTerm; // Gnuplot terminal device
}; // class 'Gnuplot'
//// IMPLEMENTATION
void
Gnuplot::setTerminal(const std::string& term) // "dumb" "x11" "wxt"
{
const bool supported = ( term == "dumb" ||
term == "x11" ||
term == "wxt" );
if ( supported ) logme("term = '" + term + "'");
else logme("WARNING: gnuplot terminal type not tested: " +
term);
gnuplotTerm = term; // store value
*this << "set terminal " << gnuplotTerm << std::endl;
}
void
Gnuplot::setPersist() // plot window remains open
{
*this << "set terminal " << gnuplotTerm << " persist" << std::endl;
}
//// USAGE
Gnuplot gp("gnuplot"); // gnuplot invocation string
gp.setTerminal("wxt");
gp.setPersist(); // sets persist
gp << "set xrange [-2:2]" << "\n";
...
---
Robbie Morrison
PhD student -- policy-oriented energy system simulation
Technical University of Berlin (TU-Berlin), Germany
University email (redirected) : mor...@ie...
Webmail (preferred) : ro...@ac...
[from Webmail client]
|