27#ifndef math_plot_gnuPlot_hpp
28#define math_plot_gnuPlot_hpp
48#include "../constants.hpp"
56#define MX_GP_FNAME_SZ ( 128 )
63#define MX_GP_TEMP_SZ ( 128 )
72#define MX_GP_FC_TIME ( 10000 )
75#ifndef MX_GP_FC_RETRIES
80#define MX_GP_FC_RETRIES ( 10 )
90template <
typename dataT>
91std::string gpBinaryFormat()
93 static_assert( std::is_fundamental<dataT>::value || !std::is_fundamental<dataT>::value,
94 "No gnuplot format specifier available for this type." );
104 std::string m_modifiers;
106 std::string m_binary;
112 gpCurve(
const std::string &file,
const std::string &title,
const std::string &modifiers )
113 : m_file( file ), m_title( title ), m_modifiers( modifiers )
117 gpCurve(
const std::string &file,
118 const std::string &title,
119 const std::string &modifiers,
120 const std::string &binary )
121 : m_file( file ), m_title( title ), m_modifiers( modifiers ), m_binary( binary )
125 gpCurve(
const gpCurve &gpc )
128 m_title = gpc.m_title;
129 m_modifiers = gpc.m_modifiers;
130 m_binary = gpc.m_binary;
201 std::string _gpErrorMsg;
228 std::map<std::string, gpCurve> m_curveMap;
287 std::string &response,
432 int plot(
const std::string &fname,
434 const std::string &
title,
435 const std::string &name
450 int plot(
const std::string &fname,
452 const std::string &name
469 int plot(
const std::string &fname,
470 const std::string &name
487 int plot(
const std::string &fname );
501 template <
typename dataT>
502 int plot(
const dataT *y,
508 const std::string &name
523 template <
typename dataT>
524 int plot(
const dataT *y,
528 const std::string &name
541 template <
typename dataT>
542 int plot(
const dataT *y,
544 const std::string &name
556 template <
typename dataT>
557 int plot(
const dataT *y,
573 template <
typename dataT>
574 int plot(
const std::vector<dataT> &y,
579 const std::string &name
594 template <
typename dataT>
595 int plot(
const std::vector<dataT> &y,
598 const std::string &name
610 template <
typename dataT>
611 int plot(
const std::vector<dataT> &y,
612 const std::string &name
624 template <
typename dataT>
625 int plot(
const std::vector<dataT> &y );
639 template <
typename dataTx,
typename dataTy>
640 int plot(
const dataTx *x,
645 const std::string &
title,
646 const std::string &name
661 template <
typename dataTx,
typename dataTy>
662 int plot(
const dataTx *x,
667 const std::string &name
679 template <
typename dataTx,
typename dataTy>
680 int plot(
const dataTx *x,
683 const std::string &name
695 template <
typename dataTx,
typename dataTy>
696 int plot(
const dataTx *x,
713 template <
typename dataTx,
typename dataTy>
714 int plot(
const std::vector<dataTx> &x,
715 const std::vector<dataTy> &y,
718 const std::string &
title,
719 const std::string &name
734 template <
typename dataTx,
typename dataTy>
735 int plot(
const std::vector<dataTx> &x,
736 const std::vector<dataTy> &y,
739 const std::string &name
751 template <
typename dataTx,
typename dataTy>
752 int plot(
const std::vector<dataTx> &x,
753 const std::vector<dataTy> &y,
754 const std::string &name
766 template <
typename dataTx,
typename dataTy>
767 int plot(
const std::vector<dataTx> &x,
768 const std::vector<dataTy> &y
778 template <
typename dataTx,
typename dataTy>
783 const std::string &
title =
""
795 const std::string &
title =
"",
807 const std::string &
title =
"",
828 void title(
const std::string &name,
829 const std::string &
title
836 const std::string &binary,
838 const std::string &
title,
839 const std::string &name );
847 const std::string &binaryx,
848 const std::string &binaryy,
850 const std::string &
title,
851 const std::string &name );
864template <
typename dataT>
866 const dataT *y,
size_t N,
const std::string &
modifiers,
const std::string &
title,
const std::string &name )
871template <
typename dataT>
874 return plotImpl( y, N *
sizeof( dataT ), gpBinaryFormat<dataT>(),
modifiers,
"", name );
877template <
typename dataT>
880 return plotImpl( y, N *
sizeof( dataT ), gpBinaryFormat<dataT>(),
"",
"", name );
883template <
typename dataT>
886 return plotImpl( y, N *
sizeof( dataT ), gpBinaryFormat<dataT>(),
"",
"",
"" );
889template <
typename dataT>
892 const std::string &
title,
893 const std::string &name )
898template <
typename dataT>
904template <
typename dataT>
907 return plot<dataT>( y.data(), y.size(),
"",
"", name );
910template <
typename dataT>
913 return plot<dataT>( y.data(), y.size(),
"",
"",
"" );
916template <
typename dataTx,
typename dataTy>
921 const std::string &
title,
922 const std::string &name )
929 gpBinaryFormat<dataTx>(),
930 gpBinaryFormat<dataTy>(),
936template <
typename dataTx,
typename dataTy>
944 gpBinaryFormat<dataTx>(),
945 gpBinaryFormat<dataTy>(),
951template <
typename dataTx,
typename dataTy>
952int gnuPlot::plot(
const dataTx *x,
const dataTy *y,
size_t N,
const std::string &name )
955 x, y, N,
sizeof( dataTx ),
sizeof( dataTy ), gpBinaryFormat<dataTx>(), gpBinaryFormat<dataTy>(),
"",
"", name );
958template <
typename dataTx,
typename dataTy>
962 x, y, N,
sizeof( dataTx ),
sizeof( dataTy ), gpBinaryFormat<dataTx>(), gpBinaryFormat<dataTy>(),
"",
"",
"" );
965template <
typename dataTx,
typename dataTy>
967 const std::vector<dataTy> &y,
969 const std::string &
title,
970 const std::string &name )
975template <
typename dataTx,
typename dataTy>
977 const std::vector<dataTy> &y,
979 const std::string &name )
981 return plot( x.data(), y.data(), x.size(),
modifiers,
"", name );
984template <
typename dataTx,
typename dataTy>
985int gnuPlot::plot(
const std::vector<dataTx> &x,
const std::vector<dataTy> &y,
const std::string &name )
987 return plot( x.data(), y.data(), x.size(),
"",
"", name );
990template <
typename dataTx,
typename dataTy>
991int gnuPlot::plot(
const std::vector<dataTx> &x,
const std::vector<dataTy> &y )
993 return plot( x.data(), y.data(), x.size(),
"",
"",
"" );
996template <
typename dataTx,
typename dataTy>
1004std::string gpBinaryFormat<char>();
1007std::string gpBinaryFormat<unsigned char>();
1010std::string gpBinaryFormat<short>();
1013std::string gpBinaryFormat<unsigned short>();
1016std::string gpBinaryFormat<int>();
1019std::string gpBinaryFormat<unsigned int>();
1022std::string gpBinaryFormat<long>();
1025std::string gpBinaryFormat<unsigned long>();
1028std::string gpBinaryFormat<float>();
1031std::string gpBinaryFormat<double>();
An interactive c++ interface to gnuplot.
int circle(double radius, const std::string &modifiers="", const std::string &title="", int npoints=10)
Draw a circle on the plot around the origin.
int doPlotCommand()
Issue the plot command for all the curves.
int plot(const std::string &fname)
Plot from a file without specifying the name or any modifiers.
std::string getResponse(const std::string &com, double timeout=0.5)
Get a response from gnuplot for a given command.
FILE * _pipeH
File stream for the gnuplot interface.
int plot(const std::string &fname, const std::string &modifiers, const std::string &title, const std::string &name)
Plot from a file specifying all curve components.
bool _gpError
Set to true if the response indicates a gnuplot error.
int xrange(double x0, double x1)
Set the x-axis range.
void title(const std::string &name, const std::string &title)
Modify the title for a curve.
int plot(const std::string &fname, const std::string &modifiers, const std::string &name)
Plot from a file without specifying the title.
int plotImpl(const void *x, const void *y, size_t Npts, size_t sizex, size_t sizey, const std::string &binaryx, const std::string &binaryy, const std::string &modifiers, const std::string &title, const std::string &name)
Implementation of 2-d binary plotting.
int plot(const std::string &fname, const std::string &name)
Plot from a file without modifiers.
void reset()
Clear all the curves and reset plot configuration.
int connect()
Connect to gnuplot.
int point(dataTx x, dataTy y, const std::string &modifiers="", const std::string &title="")
Plot a single point.
FILE * openTempFile(char *fname)
Open a temporary binary file, and provide the filename.
std::string _errFName
File name of the gnuplot stderr fifo.
std::vector< std::string > _tempFiles
Vector of all temporary file names opened, used for removal on destruction.
int ulogy()
Unset the y axis from log scale.
int plotImpl(const void *y, size_t Nbytes, const std::string &binary, const std::string &modifiers, const std::string &title, const std::string &name)
Implementation of 1-D binary plotting.
bool _deleteTemp
Flag to control whether temporary files are deleted on destruction. Default is true (files deleted).
int logy()
Set the y axis to log scale.
int _errFD
File descriptor for the gnuplot stderr fifo.
std::string _errLocation
Where to create gnuplot stderr fifo.
int ulogxy()
Unset the x and y axes from log scale.
int replot()
Issue the replot command.
int logxy()
Set the x and y axes to log scale.
int yrange()
Unset the y-axis range.
void listCurves()
List the curves and their specifications.
int checkResponse(std::string &response, double timeout=0)
Check for a response from gnuplot.
bool gpError()
Return the value of the gpError flag.
void modifiers(const std::string &name, const std::string &modifiers)
Modify the modifiers for a curve.
int xrange()
Unset the x-axis range.
int ulogx()
Unset the x axis from log scale.
int yrange(double y0, double y1)
Set the y-axis range.
std::string _tempLocation
Location of temporary files.
int circle(double xcen, double ycen, double radius, const std::string &modifiers="", const std::string &title="", int npoints=10)
Draw a circle on the plot.
int command(const std::string &com, bool flush=true)
Send a command to gnuplot.
int logx()
Set the x axis to log scale.
std::string gpErrorMsg()
Return the gnuplot error message.
void clear()
Clear all the curves.
@ timeout
A timeout occurred.
Declarations of some libarary wide utilities.
MXLIB_DEFAULT_VERBOSITY d
The default verbosity.
Utilities for working with time.