32 #ifndef _GNUPLOT_PIPES_H_
33 #define _GNUPLOT_PIPES_H_
46 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__TOS_WIN__)
49 #define GP_MAX_TMP_FILES 27
50 #elif defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
53 #define GP_MAX_TMP_FILES 64
55 #error unsupported or unknown operating system
88 std::vector<std::string> tmpfile_list;
93 static int tmpfile_num;
95 static std::string m_sGNUPlotFileName;
97 static std::string m_sGNUPlotPath;
99 static std::string terminal_std;
118 std::string create_tmpfile(std::ofstream &tmp);
127 static bool get_program_path();
137 bool file_available(
const std::string &filename);
147 static bool file_exists(
const std::string &filename,
int mode=0);
178 Gnuplot(
const std::string &style =
"points");
181 Gnuplot(
const std::vector<double> &x,
182 const std::string &title =
"",
183 const std::string &style =
"points",
184 const std::string &labelx =
"x",
185 const std::string &labely =
"y");
188 Gnuplot(
const std::vector<double> &x,
189 const std::vector<double> &y,
190 const std::string &title =
"",
191 const std::string &style =
"points",
192 const std::string &labelx =
"x",
193 const std::string &labely =
"y");
196 Gnuplot(
const std::vector<double> &x,
197 const std::vector<double> &y,
198 const std::vector<double> &z,
199 const std::string &title =
"",
200 const std::string &style =
"points",
201 const std::string &labelx =
"x",
202 const std::string &labely =
"y",
203 const std::string &labelz =
"z");
370 cmdstr =
"set title \"";
476 const unsigned int column = 1,
477 const std::string &title =
"");
488 std::string name = create_tmpfile(tmp);
495 for (
unsigned int i = 0; i < x.size(); i++)
496 tmp << x[i] << std::endl;
511 const unsigned int column_x = 1,
512 const unsigned int column_y = 2,
513 const std::string &title =
"");
515 template<
typename X,
typename Y>
518 if (x.size() == 0 || y.size() == 0)
524 if (x.size() != y.size())
532 std::string name = create_tmpfile(tmp);
539 for (
unsigned int i = 0; i < x.size(); i++)
540 tmp << x[i] <<
" " << y[i] << std::endl;
556 const unsigned int column_x = 1,
557 const unsigned int column_y = 2,
558 const unsigned int column_dy = 3,
559 const std::string &title =
"");
561 template<
typename X,
typename Y,
typename E>
563 const std::string &title =
""){
564 if (x.size() == 0 || y.size() == 0 || dy.size() == 0)
570 if (x.size() != y.size() || y.size() != dy.size())
578 std::string name = create_tmpfile(tmp);
585 for (
unsigned int i = 0; i < x.size(); i++)
586 tmp << x[i] <<
" " << y[i] <<
" " << dy[i] << std::endl;
602 const unsigned int column_x = 1,
603 const unsigned int column_y = 2,
604 const unsigned int column_z = 3,
605 const std::string &title =
"");
607 template<
typename X,
typename Y,
typename Z>
611 const std::string &title =
""){
612 if (x.size() == 0 || y.size() == 0 || z.size() == 0)
618 if (x.size() != y.size() || x.size() != z.size())
626 std::string name = create_tmpfile(tmp);
633 for (
unsigned int i = 0; i < x.size(); i++)
634 tmp << x[i] <<
" " << y[i] <<
" " << z[i] <<std::endl;
649 const std::string &title =
"");
663 const std::string &title =
"");
668 const std::string &title =
"");
673 const unsigned int iWidth,
674 const unsigned int iHeight,
675 const std::string &title =
"");
709 template <
typename Container>
710 void stringtok (Container &container,
711 std::string
const &in,
712 const char *
const delimiters =
" \t\n")
714 const std::string::size_type len = in.length();
715 std::string::size_type i = 0;
720 i = in.find_first_not_of (delimiters, i);
722 if (i == std::string::npos)
726 std::string::size_type j = in.find_first_of (delimiters, i);
729 if (j == std::string::npos)
731 container.push_back (in.substr(i));
735 container.push_back (in.substr(i, j-i));
A C++ interface to gnuplot.
Definition: gnuplot_i.hpp:62
Definition: gnuplot_i.hpp:70
Gnuplot & savetops(const std::string &filename="gnuplot_output")
saves a gnuplot session to a postscript file, filename without extension
Definition: gnuplot_i.cpp:327
Gnuplot & cmd(const std::string &cmdstr)
send a command to gnuplot
Definition: gnuplot_i.cpp:891
Gnuplot & unset_contour()
Definition: gnuplot_i.hpp:324
Gnuplot & plot_xy(const X &x, const Y &y, const std::string &title="")
from data
Definition: gnuplot_i.hpp:516
Gnuplot & plotfile_xy(const std::string &filename, const unsigned int column_x=1, const unsigned int column_y=2, const std::string &title="")
Definition: gnuplot_i.cpp:707
Gnuplot & set_xautoscale()
Definition: gnuplot_i.hpp:410
Gnuplot(const std::string &style="points")
set a style during construction
Definition: gnuplot_i.cpp:60
Gnuplot & set_zlogscale(const double base=10)
turns on/off log scaling for the specified zaxis (logscale is not set by default)
Definition: gnuplot_i.cpp:384
Gnuplot & set_ylogscale(const double base=10)
turns on/off log scaling for the specified yaxis (logscale is not set by default)
Definition: gnuplot_i.cpp:370
static void set_terminal_std(const std::string &type)
Definition: gnuplot_i.cpp:168
Gnuplot & set_cbrange(const double iFrom, const double iTo)
set palette range (autoscale by default)
Definition: gnuplot_i.cpp:545
void remove_tmpfiles()
deletes temporary files
Definition: gnuplot_i.cpp:1199
bool is_valid()
Is the gnuplot session valid ??
Definition: gnuplot_i.hpp:706
Gnuplot & replot(void)
replot repeats the last plot or splot command. this can be useful for viewing a plot with different s...
Definition: gnuplot_i.hpp:687
Gnuplot & showonscreen()
sets terminal type to terminal_std
Definition: gnuplot_i.cpp:315
Gnuplot & plot_equation(const std::string &equation, const std::string &title="")
Definition: gnuplot_i.cpp:595
Gnuplot & set_yrange(const double iFrom, const double iTo)
set y-axis - ranges
Definition: gnuplot_i.cpp:516
Gnuplot & set_xrange(const double iFrom, const double iTo)
set axis - ranges
Definition: gnuplot_i.cpp:502
Gnuplot & unset_surface()
Definition: gnuplot_i.hpp:343
Gnuplot & set_title(const std::string &title="")
sets and clears the title of a gnuplot session
Definition: gnuplot_i.hpp:367
Gnuplot & plotfile_x(const std::string &filename, const unsigned int column=1, const std::string &title="")
Definition: gnuplot_i.cpp:662
Gnuplot & plot_slope(const double a, const double b, const std::string &title="")
plot an equation of the form: y = ax + b, you supply a and b
Definition: gnuplot_i.cpp:561
Gnuplot & unset_grid()
grid is not set by default
Definition: gnuplot_i.hpp:269
Gnuplot & set_grid()
turns grid on/off
Definition: gnuplot_i.hpp:267
Gnuplot & set_yautoscale()
Definition: gnuplot_i.hpp:419
Gnuplot & set_samples(const int samples=100)
set sampling rate of functions, or for interpolating data
Definition: gnuplot_i.cpp:411
Gnuplot & reset_plot()
resets a gnuplot session (next plot will erase previous ones)
Definition: gnuplot_i.cpp:212
static bool set_GNUPlotPath(const std::string &path)
optional function: set Gnuplot path manual attention: for windows: path with slash '/' not backslash ...
Definition: gnuplot_i.cpp:140
Gnuplot & set_multiplot()
Definition: gnuplot_i.hpp:278
Gnuplot & plot_x(const X &x, const std::string &title="")
from std::vector
Definition: gnuplot_i.hpp:480
Gnuplot & set_zrange(const double iFrom, const double iTo)
set z-axis - ranges
Definition: gnuplot_i.cpp:530
~Gnuplot()
destructor: needed to delete temporary files
Definition: gnuplot_i.cpp:194
Gnuplot & plot_equation3d(const std::string &equation, const std::string &title="")
Definition: gnuplot_i.cpp:628
Gnuplot & unset_xlogscale()
Definition: gnuplot_i.hpp:445
Gnuplot & set_hidden3d()
Definition: gnuplot_i.hpp:303
Gnuplot & unset_ylogscale()
Definition: gnuplot_i.hpp:454
Gnuplot & set_pointsize(const double pointsize=1.0)
scales the size of the points used in plots
Definition: gnuplot_i.cpp:398
Gnuplot & set_surface()
Definition: gnuplot_i.hpp:333
Gnuplot & reset_all()
resets a gnuplot session and sets all variables to default
Definition: gnuplot_i.cpp:226
Gnuplot & plot_xy_err(const X &x, const Y &y, const E &dy, const std::string &title="")
from data
Definition: gnuplot_i.hpp:562
Gnuplot & plotfile_xyz(const std::string &filename, const unsigned int column_x=1, const unsigned int column_y=2, const unsigned int column_z=3, const std::string &title="")
Definition: gnuplot_i.cpp:794
Gnuplot & set_smooth(const std::string &stylestr="csplines")
Definition: gnuplot_i.cpp:291
Gnuplot & set_xlabel(const std::string &label="y")
set y axis label
Definition: gnuplot_i.cpp:461
Gnuplot & unset_multiplot()
Definition: gnuplot_i.hpp:287
Gnuplot & plot_image(const unsigned char *ucPicBuf, const unsigned int iWidth, const unsigned int iHeight, const std::string &title="")
plot image
Definition: gnuplot_i.cpp:836
Gnuplot & set_zlabel(const std::string &label="z")
set z axis label
Definition: gnuplot_i.cpp:487
Gnuplot & set_isosamples(const int isolines=10)
set isoline density (grid) for plotting functions as surfaces (for 3d plots)
Definition: gnuplot_i.cpp:425
Gnuplot & unset_hidden3d()
Definition: gnuplot_i.hpp:312
Gnuplot & unset_title()
Clears the title of a gnuplot session The title is not set by default.
Definition: gnuplot_i.hpp:385
Gnuplot & unset_legend()
Switches legend off attention:legend is set by default.
Definition: gnuplot_i.hpp:358
Gnuplot & set_style(const std::string &stylestr="points")
Definition: gnuplot_i.cpp:245
Gnuplot & plot_xyz(const X &x, const Y &y, const Z &z, const std::string &title="")
from std::vector
Definition: gnuplot_i.hpp:608
Gnuplot & set_legend(const std::string &position="default")
Definition: gnuplot_i.cpp:342
Gnuplot & unset_smooth()
unset smooth attention: smooth is not set by default
Definition: gnuplot_i.hpp:260
Gnuplot & set_zautoscale()
Definition: gnuplot_i.hpp:428
Gnuplot & set_contour(const std::string &position="base")
Definition: gnuplot_i.cpp:440
Gnuplot & unset_zlogscale()
Definition: gnuplot_i.hpp:463
Gnuplot & operator<<(const std::string &cmdstr)
Sends a command to an active gnuplot session, identical to cmd() send a command to gnuplot using the ...
Definition: gnuplot_i.hpp:221
Gnuplot & set_ylabel(const std::string &label="x")
set x axis label
Definition: gnuplot_i.cpp:474
Gnuplot & plotfile_xy_err(const std::string &filename, const unsigned int column_x=1, const unsigned int column_y=2, const unsigned int column_dy=3, const std::string &title="")
Definition: gnuplot_i.cpp:752
Gnuplot & set_xlogscale(const double base=10)
turns on/off log scaling for the specified xaxis (logscale is not set by default)
Definition: gnuplot_i.cpp:356