11#include "ns3/assert.h"
27struct GnuplotDataset::Data
40 Data(
const std::string& title);
89 m_extra(m_defaultExtra)
161struct Gnuplot2dDataset::Data2d :
public GnuplotDataset::Data
166 ErrorBars m_errorBars;
178 bool generateOneOutputFile,
179 unsigned int dataFileDatasetIndex,
180 std::string& dataFileName)
const override;
181 void PrintDataFile(std::ostream& os,
bool generateOneOutputFile)
const override;
187 m_style(m_defaultStyle),
188 m_errorBars(m_defaultErrorBars)
215 if (!m_title.empty())
217 os <<
" title \"" << m_title <<
"\"";
229 os <<
" with points";
232 os <<
" with xerrorbars";
235 os <<
" with yerrorbars";
238 os <<
" with xyerrorbars";
246 os <<
" with linespoints";
249 os <<
" with errorlines";
252 os <<
" with yerrorlines";
255 os <<
" with xyerrorlines";
263 os <<
" with impulses";
269 os <<
" with fsteps";
272 os <<
" with histeps";
275 os <<
" with filledcurve";
279 if (!m_extra.empty())
281 os <<
" " << m_extra;
288 for (
auto i = m_pointset.begin();
i != m_pointset.end(); ++
i)
299 os <<
i->x <<
" " <<
i->y << std::endl;
302 os <<
i->x <<
" " <<
i->y <<
" " <<
i->dx << std::endl;
305 os <<
i->x <<
" " <<
i->y <<
" " <<
i->dy << std::endl;
308 os <<
i->x <<
" " <<
i->y <<
" " <<
i->dx <<
" " <<
i->dy << std::endl;
317 os <<
"e" << std::endl;
329 return m_pointset.empty();
353 reinterpret_cast<Data2d*
>(
m_data)->m_style =
style;
379 reinterpret_cast<Data2d*
>(
m_data)->m_pointset.push_back(
data);
386 reinterpret_cast<Data2d*
>(
m_data)->m_errorBars ==
Y);
394 reinterpret_cast<Data2d*
>(
m_data)->m_pointset.push_back(
data);
408 reinterpret_cast<Data2d*
>(
m_data)->m_pointset.push_back(
data);
416 reinterpret_cast<Data2d*
>(
m_data)->m_pointset.push_back(
data);
426struct Gnuplot2dFunction::Function2d :
public GnuplotDataset::Data
430 std::string m_function;
438 Function2d(
const std::string& title,
const std::string& function);
442 bool generateOneOutputFile,
443 unsigned int dataFileDatasetIndex,
444 std::string& dataFileName)
const override;
445 void PrintDataFile(std::ostream& os,
bool generateOneOutputFile)
const override;
469 if (!m_title.empty())
471 os <<
" title \"" << m_title <<
"\"";
474 if (!m_extra.empty())
476 os <<
" " << m_extra;
511struct Gnuplot3dDataset::Data3d :
public GnuplotDataset::Data
527 bool generateOneOutputFile,
528 unsigned int dataFileDatasetIndex,
529 std::string& dataFileName)
const override;
530 void PrintDataFile(std::ostream& os,
bool generateOneOutputFile)
const override;
536 m_style(m_defaultStyle)
554 if (!m_style.empty())
556 os <<
" " << m_style;
559 if (!m_title.empty())
561 os <<
" title \"" << m_title <<
"\"";
564 if (!m_extra.empty())
566 os <<
" " << m_extra;
573 for (
auto i = m_pointset.begin();
i != m_pointset.end(); ++
i)
581 os <<
i->x <<
" " <<
i->y <<
" " <<
i->z << std::endl;
583 os <<
"e" << std::endl;
589 return m_pointset.empty();
610 reinterpret_cast<Data3d*
>(
m_data)->m_style =
style;
621 reinterpret_cast<Data3d*
>(
m_data)->m_pointset.push_back(
data);
629 reinterpret_cast<Data3d*
>(
m_data)->m_pointset.push_back(
data);
639struct Gnuplot3dFunction::Function3d :
public GnuplotDataset::Data
643 std::string m_function;
651 Function3d(
const std::string& title,
const std::string& function);
655 bool generateOneOutputFile,
656 unsigned int dataFileDatasetIndex,
657 std::string& dataFileName)
const override;
658 void PrintDataFile(std::ostream& os,
bool generateOneOutputFile)
const override;
682 if (!m_title.empty())
684 os <<
" title \"" << m_title <<
"\"";
687 if (!m_extra.empty())
689 os <<
" " << m_extra;
723 m_generateOneOutputFile(
false),
724 m_dataFileDatasetIndex(0)
738 if (
dotpos == std::string::npos)
798 m_generateOneOutputFile =
true;
801 GenerateOutput(os, os,
"");
807 if (!m_terminal.empty())
809 osControl <<
"set terminal " << m_terminal << std::endl;
812 if (!m_outputFilename.empty())
814 osControl <<
"set output \"" << m_outputFilename <<
"\"" << std::endl;
817 if (!m_title.empty())
819 osControl <<
"set title \"" << m_title <<
"\"" << std::endl;
822 if (!m_xLegend.empty())
824 osControl <<
"set xlabel \"" << m_xLegend <<
"\"" << std::endl;
827 if (!m_yLegend.empty())
829 osControl <<
"set ylabel \"" << m_yLegend <<
"\"" << std::endl;
832 if (!m_extra.empty())
837 if (m_datasets.empty())
845 std::string
command = m_datasets.begin()->m_data->GetCommand();
847 for (
auto i = m_datasets.begin() + 1;
i != m_datasets.end(); ++
i)
850 "Cannot mix 'plot' and 'splot' GnuplotDatasets.");
858 for (
auto i = m_datasets.begin();
i != m_datasets.end();)
867 m_generateOneOutputFile,
868 m_dataFileDatasetIndex,
871 m_dataFileDatasetIndex++;
884 for (
auto i = m_datasets.begin();
i != m_datasets.end();
i++)
886 i->m_data->PrintDataFile(
osData, m_generateOneOutputFile);
893 m_dataFileDatasetIndex = index;
913 m_plots.push_back(
plot);
919 if (
id >= m_plots.size())
921 throw(std::range_error(
"Gnuplot id is out of range"));
935 if (!m_terminal.empty())
937 os <<
"set terminal " << m_terminal << std::endl;
940 if (!m_outputFilename.empty())
942 os <<
"set output \"" << m_outputFilename <<
"\"" << std::endl;
945 for (
auto i = m_plots.begin();
i != m_plots.end(); ++
i)
959 if (!m_terminal.empty())
961 osControl <<
"set terminal " << m_terminal << std::endl;
964 if (!m_outputFilename.empty())
966 osControl <<
"set output \"" << m_outputFilename <<
"\"" << std::endl;
969 for (
auto i = m_plots.begin();
i != m_plots.end(); ++
i)
void AddEmptyLine()
Add an empty line in the data output sequence.
static void SetDefaultStyle(Style style)
Change default style for all newly created objects.
static Style m_defaultStyle
default plot style
ErrorBars
Whether errorbars should be used for this dataset.
static void SetDefaultErrorBars(ErrorBars errorBars)
Change default errorbars style for all newly created objects.
void SetErrorBars(ErrorBars errorBars)
static ErrorBars m_defaultErrorBars
default error bars type
void SetStyle(Style style)
void Add(double x, double y)
Style
The plotting style to use for this dataset.
Gnuplot2dDataset(const std::string &title="Untitled")
void SetFunction(const std::string &function)
Gnuplot2dFunction(const std::string &title="Untitled", const std::string &function="")
void AddEmptyLine()
Add an empty line in the data output sequence.
Gnuplot3dDataset(const std::string &title="Untitled")
void Add(double x, double y, double z)
static void SetDefaultStyle(const std::string &style)
Change default style for all newly created objects.
void SetStyle(const std::string &style)
static std::string m_defaultStyle
default plot style
Gnuplot3dFunction(const std::string &title="Untitled", const std::string &function="")
void SetFunction(const std::string &function)
GnuplotCollection(const std::string &outputFilename)
void AddPlot(const Gnuplot &plot)
void SetTerminal(const std::string &terminal)
Gnuplot & GetPlot(unsigned int id)
Return a pointer to one of the added plots.
void GenerateOutput(std::ostream &os)
GnuplotDataset(const GnuplotDataset &original)
Reference-counting copy constructor.
friend class Gnuplot
Friend because it accesses m_data and it's virtual functions directly in GenerateOutput().
static std::string m_defaultExtra
Extra gnuplot parameters set on every newly created dataset.
static void SetDefaultExtra(const std::string &extra)
Change extra formatting style parameters for newly created objects.
GnuplotDataset & operator=(const GnuplotDataset &original)
Reference-counting assignment operator.
void SetExtra(const std::string &extra)
Add extra formatting parameters to this dataset.
Data * m_data
Reference counted data object.
void SetTitle(const std::string &title)
Change line title.
~GnuplotDataset()
Reference-counting destructor.
void AddDataset(const GnuplotDataset &dataset)
void SetLegend(const std::string &xLegend, const std::string &yLegend)
void SetTerminal(const std::string &terminal)
void AppendExtra(const std::string &extra)
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
void SetDataFileDatasetIndex(unsigned int index)
Sets the current data stream index in the data file.
Gnuplot(const std::string &outputFilename="", const std::string &title="")
void SetExtra(const std::string &extra)
void SetTitle(const std::string &title)
void SetOutputFilename(const std::string &outputFilename)
static std::string DetectTerminal(const std::string &filename)
Crude attempt to auto-detect the correct terminal setting by inspecting the filename's extension.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void PrintDataFile(std::ostream &os, bool generateOneOutputFile) const override
Print the inline data file contents trailing the plot command.
void PrintExpression(std::ostream &os, bool generateOneOutputFile, unsigned int dataFileDatasetIndex, std::string &dataFileName) const override
Prints the plot description used as argument to (s)plot.
bool IsEmpty() const override
Checks to see if this GnuplotDataset is empty.
Data2d(const std::string &title)
Initializes with the values from m_defaultStyle and m_defaultErrorBars.
std::string GetCommand() const override
Returns the plot type ("plot" or "splot").
std::string GetCommand() const override
Returns the plot type ("plot" or "splot").
void PrintDataFile(std::ostream &os, bool generateOneOutputFile) const override
Print the inline data file contents trailing the plot command.
Function2d(const std::string &title, const std::string &function)
Initializes with the function and title.
void PrintExpression(std::ostream &os, bool generateOneOutputFile, unsigned int dataFileDatasetIndex, std::string &dataFileName) const override
Prints the plot description used as argument to (s)plot.
bool IsEmpty() const override
Checks to see if this GnuplotDataset is empty.
std::string GetCommand() const override
Returns the plot type ("plot" or "splot").
bool IsEmpty() const override
Checks to see if this GnuplotDataset is empty.
void PrintExpression(std::ostream &os, bool generateOneOutputFile, unsigned int dataFileDatasetIndex, std::string &dataFileName) const override
Prints the plot description used as argument to (s)plot.
void PrintDataFile(std::ostream &os, bool generateOneOutputFile) const override
Print the inline data file contents trailing the plot command.
Data3d(const std::string &title)
Initializes with value from m_defaultStyle.
bool IsEmpty() const override
Checks to see if this GnuplotDataset is empty.
void PrintExpression(std::ostream &os, bool generateOneOutputFile, unsigned int dataFileDatasetIndex, std::string &dataFileName) const override
Prints the plot description used as argument to (s)plot.
Function3d(const std::string &title, const std::string &function)
Initializes with the function and title.
void PrintDataFile(std::ostream &os, bool generateOneOutputFile) const override
Print the inline data file contents trailing the plot command.
std::string GetCommand() const override
Returns the plot type ("plot" or "splot").
Structure storing the data to plot.
unsigned int m_references
ref/unref counter for garbage collection
std::string m_extra
Extra parameters for the plot.
virtual void PrintExpression(std::ostream &os, bool generateOneOutputFile, unsigned int dataFileDatasetIndex, std::string &dataFileName) const =0
Prints the plot description used as argument to (s)plot.
virtual void PrintDataFile(std::ostream &os, bool generateOneOutputFile) const =0
Print the inline data file contents trailing the plot command.
virtual bool IsEmpty() const =0
Checks to see if this GnuplotDataset is empty.
Data(const std::string &title)
Initializes the reference counter to 1 and sets m_title and m_extra.
std::string m_title
Dataset title.
virtual std::string GetCommand() const =0
Returns the plot type ("plot" or "splot").