Gnuplot.hh
//
// A C++ interface to gnuplot.
//
// This is a direct translation from the C interface
// written by N. Devillard (which is available from
// http://ndevilla.free.fr/gnuplot/).
//
// As in the C interface this uses pipes and so wont
// run on a system that doesn't have POSIX pipe
// support
//
// Rajarshi Guha
// <rajarshi@presidency.com>
//
// 07/03/03
//
//
// A little correction for Win32 compatibility
// and MS VC 6.0 done by V.Chyzhdzenka
//
// Notes:
// 1. Added private method Gnuplot::init().
// 2. Temporary file is created in th current
// folder but not in /tmp.
// 3. Added #indef WIN32 e.t.c. where is needed.
// 4. Added private member m_sGNUPlotFileName is
// a name of executed GNUPlot file.
//
// Viktor Chyzhdzenka
// e-mail: chyzhdzenka@mail.ru
//
// 20/05/03
//
#ifndef _GNUPLOT_HH
#define _GNUPLOT_HH
#include <OpenMesh/Core/System/config.hh>
// #ifndef WIN32
// # include <unistd.h>
// #else
// # pragma warning (disable : 4786) // Disable 4786 warning for MS VC 6.0
// #endif
#if defined(OM_CC_MIPS)
# include <stdio.h>
#else
# include <cstdio>
#endif
#include <string>
#include <vector>
#include <stdexcept>
// ----------------------------------------------------------------------------
#ifdef WIN32
# define GP_MAX_TMP_FILES 27 //27 temporary files it's Microsoft restriction
#else
# define GP_MAX_TMP_FILES 64
# define GP_TMP_NAME_SIZE 512
# define GP_TITLE_SIZE 80
#endif
#define GP_CMD_SIZE 1024
// ----------------------------------------------------------------------------
using namespace std;
// ----------------------------------------------------------------------------
class GnuplotException : public runtime_error
{
public:
explicit GnuplotException(const string &msg) : runtime_error(msg){}
};
// ----------------------------------------------------------------------------
class Gnuplot
{
private:
FILE *gnucmd;
string pstyle;
vector<string> to_delete;
int nplots;
bool get_program_path(const string& );
bool valid;
// Name of executed GNUPlot file
static string gnuplot_executable_;
void init();
public:
Gnuplot();
explicit Gnuplot(const string & _style);
Gnuplot(const string & _title,
const string & _style,
const string & _xlabel,
const string & _ylabel,
vector<double> _x, vector<double> _y);
Gnuplot(const string &_title,
const string &_style,
const string &_xlabel,
const string &_ylabel,
vector<double> _x);
~Gnuplot();
void cmd(const char *_cmd, ...);
void set_style(const string & _style);
void set_ylabel(const string & _ylabel);
void set_xlabel(const string & _xlabel);
void plot_x(vector<double> _x, const string &_title);
void plot_xy(vector<double> _x, vector<double> _y, const string &_title);
void plot_slope(
double _a,
double _b,
const string & _title
);
void plot_equation(
const string & _equation,
const string & _title
);
void reset_plot(void);
bool is_valid(void) const { return valid; }
bool is_active(void) const { return this->nplots > 0; }
};
// ----------------------------------------------------------------------------
#endif // _GNUPLOT_HH
// ============================================================================
Gnuplot
Utility class interfacing with Gnuplot.
Definition: Gnuplot.hh:92
Gnuplot::is_valid
bool is_valid(void) const
Is Self valid?
Definition: Gnuplot.hh:174
std
STL namespace.
GnuplotException
Exception thrown by class Gnuplot.
Definition: Gnuplot.hh:74
Gnuplot::is_active
bool is_active(void) const
Is Self active, i.e. does it have an active plot?
Definition: Gnuplot.hh:177