A Discrete-Event Network Simulator
API
gnuplot.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007 INRIA, 2008 Timo Bingmann
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Original Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  * Enhancements: Timo Bingmann <timo.bingmann@student.kit.edu>
20  */
21 #ifndef GNUPLOT_H
22 #define GNUPLOT_H
23 
24 #include <string>
25 #include <vector>
26 #include <utility>
27 
28 namespace ns3 {
29 
39 {
40 public:
41 
46  GnuplotDataset (const GnuplotDataset& original);
47 
52 
58  GnuplotDataset& operator= (const GnuplotDataset& original);
59 
68  void SetTitle (const std::string& title);
69 
74  static void SetDefaultExtra (const std::string& extra);
75 
80  void SetExtra (const std::string& extra);
81 
82 protected:
83 
86  friend class Gnuplot;
87 
91  static std::string m_defaultExtra;
92 
96  struct Data;
97 
102  GnuplotDataset (struct Data* data);
103 
107  struct Data* m_data;
108 };
109 
118 {
119 public:
123  enum Style {
132  };
133 
137  enum ErrorBars {
139  X,
140  Y,
141  XY
142  };
143 
150  Gnuplot2dDataset (const std::string& title = "Untitled");
151 
156  static void SetDefaultStyle (enum Style style);
157 
161  void SetStyle (enum Style style);
162 
167  static void SetDefaultErrorBars (enum ErrorBars errorBars);
168 
177  void SetErrorBars (enum ErrorBars errorBars);
178 
185  void Add (double x, double y);
186 
194  void Add (double x, double y, double errorDelta);
195 
204  void Add (double x, double y, double xErrorDelta, double yErrorDelta);
205 
210  void AddEmptyLine ();
211 
212 private:
213 
217  struct Point {
218  bool empty;
219  double x;
220  double y;
221  double dx;
222  double dy;
223  };
224 
226  typedef std::vector<struct Point> PointSet;
227 
228  static enum Style m_defaultStyle;
229  static enum ErrorBars m_defaultErrorBars;
230 
232  struct Data2d;
233 };
234 
244 {
245 public:
253  Gnuplot2dFunction (const std::string& title = "Untitled", const std::string& function = "");
254 
258  void SetFunction (const std::string& function);
259 
260 private:
261 
263  struct Function2d;
264 };
265 
273 {
274 public:
281  Gnuplot3dDataset (const std::string& title = "Untitled");
282 
287  static void SetDefaultStyle (const std::string& style);
288 
292  void SetStyle (const std::string& style);
293 
301  void Add (double x, double y, double z);
302 
307  void AddEmptyLine ();
308 
309 private:
310 
314  struct Point {
315  bool empty;
316  double x;
317  double y;
318  double z;
319  };
320 
322  typedef std::vector<struct Point> PointSet;
323 
324  static std::string m_defaultStyle;
325 
327  struct Data3d;
328 };
329 
340 {
341 public:
349  Gnuplot3dFunction (const std::string& title = "Untitled", const std::string& function = "");
350 
354  void SetFunction (const std::string& function);
355 
356 private:
357 
359  struct Function3d;
360 };
361 
371 class Gnuplot
372 {
373 public:
380  Gnuplot (const std::string& outputFilename="", const std::string& title = "");
381 
387  void SetOutputFilename (const std::string& outputFilename);
388 
395  static std::string DetectTerminal (const std::string& filename);
396 
401  void SetTerminal (const std::string& terminal);
402 
406  void SetTitle (const std::string& title);
407 
412  void SetLegend (const std::string& xLegend, const std::string& yLegend);
413 
417  void SetExtra (const std::string& extra);
418 
422  void AppendExtra (const std::string& extra);
423 
427  void AddDataset (const GnuplotDataset& dataset);
428 
437  void GenerateOutput (std::ostream &os);
438 
451  void GenerateOutput (std::ostream &osControl,
452  std::ostream &osData,
453  std::string dataFileName);
454 
460  void SetDataFileDatasetIndex (unsigned int index);
461 
462 private:
464  typedef std::vector<GnuplotDataset> Datasets;
465 
466  std::string m_outputFilename;
467  std::string m_terminal;
468 
470 
471  std::string m_title;
472  std::string m_xLegend;
473  std::string m_yLegend;
474  std::string m_extra;
475 
477 
478  unsigned int m_dataFileDatasetIndex;
479 };
480 
488 {
489 public:
495  GnuplotCollection (const std::string& outputFilename);
496 
501  void SetTerminal (const std::string& terminal);
502 
506  void AddPlot (const Gnuplot& plot);
507 
513  Gnuplot& GetPlot (unsigned int id);
514 
519  void GenerateOutput (std::ostream &os);
520 
530  void GenerateOutput (std::ostream &osControl,
531  std::ostream &osData,
532  std::string dataFileName);
533 
534 private:
536  typedef std::vector<Gnuplot> Plots;
537 
538  std::string m_outputFilename;
539  std::string m_terminal;
540 
542 };
543 
544 } // namespace ns3
545 
546 #endif /* GNUPLOT_H */
ns3::GnuplotCollection
a simple class to group together multiple gnuplots into one file, e.g.
Definition: gnuplot.h:488
ns3::Gnuplot2dDataset::SetStyle
void SetStyle(enum Style style)
Definition: gnuplot.cc:342
ns3::GnuplotDataset::~GnuplotDataset
~GnuplotDataset()
Reference-counting destructor.
Definition: gnuplot.cc:121
ns3::GnuplotCollection::SetTerminal
void SetTerminal(const std::string &terminal)
Definition: gnuplot.cc:862
ns3::Gnuplot3dDataset::Point::x
double x
X coordinate.
Definition: gnuplot.h:316
ns3::Gnuplot::Datasets
std::vector< GnuplotDataset > Datasets
Type for Datasets to be used in plots.
Definition: gnuplot.h:464
ns3::Gnuplot::SetLegend
void SetLegend(const std::string &xLegend, const std::string &yLegend)
Definition: gnuplot.cc:736
ns3::Gnuplot3dFunction::Function3d
Structure storing the function to be used for a 3D plot.
Definition: gnuplot.cc:619
ns3::Gnuplot2dDataset::IMPULSES
@ IMPULSES
Definition: gnuplot.h:128
ns3::Gnuplot2dDataset::m_defaultStyle
static enum Style m_defaultStyle
default plot style
Definition: gnuplot.h:228
ns3::Gnuplot2dDataset::STEPS
@ STEPS
Definition: gnuplot.h:129
ns3::Gnuplot2dDataset::m_defaultErrorBars
static enum ErrorBars m_defaultErrorBars
default error bars type
Definition: gnuplot.h:229
ns3::Gnuplot::m_dataFileDatasetIndex
unsigned int m_dataFileDatasetIndex
Data set index to plot.
Definition: gnuplot.h:478
ns3::Gnuplot::m_outputFilename
std::string m_outputFilename
Output file name.
Definition: gnuplot.h:466
ns3::Gnuplot::SetDataFileDatasetIndex
void SetDataFileDatasetIndex(unsigned int index)
Sets the current data stream index in the data file.
Definition: gnuplot.cc:848
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Gnuplot::m_yLegend
std::string m_yLegend
Y axis legend.
Definition: gnuplot.h:473
ns3::Gnuplot3dDataset::Add
void Add(double x, double y, double z)
Definition: gnuplot.cc:593
ns3::Gnuplot::m_datasets
Datasets m_datasets
Data sets.
Definition: gnuplot.h:469
ns3::Gnuplot::SetOutputFilename
void SetOutputFilename(const std::string &outputFilename)
Definition: gnuplot.cc:703
ns3::GnuplotDataset::m_data
struct Data * m_data
Reference counted data object.
Definition: gnuplot.h:107
ns3::Gnuplot3dFunction
Class to represent a 3D function expression plot.
Definition: gnuplot.h:340
ns3::Gnuplot3dDataset::Point::z
double z
Z coordinate.
Definition: gnuplot.h:318
ns3::Gnuplot2dDataset::LINES_POINTS
@ LINES_POINTS
Definition: gnuplot.h:126
ns3::Gnuplot3dDataset::PointSet
std::vector< struct Point > PointSet
The set of points in the dataset.
Definition: gnuplot.h:322
ns3::Gnuplot3dDataset::m_defaultStyle
static std::string m_defaultStyle
default plot style
Definition: gnuplot.h:324
ns3::Gnuplot2dDataset::Point::y
double y
Y coordinate.
Definition: gnuplot.h:220
ns3::Gnuplot3dFunction::SetFunction
void SetFunction(const std::string &function)
Definition: gnuplot.cc:687
ns3::Gnuplot
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
Definition: gnuplot.h:372
ns3::Gnuplot::SetTerminal
void SetTerminal(const std::string &terminal)
Definition: gnuplot.cc:724
ns3::GnuplotCollection::m_outputFilename
std::string m_outputFilename
Output file name.
Definition: gnuplot.h:538
ns3::Gnuplot::GenerateOutput
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
Definition: gnuplot.cc:762
ns3::Gnuplot::m_generateOneOutputFile
bool m_generateOneOutputFile
true if only one plot will be generated
Definition: gnuplot.h:476
ns3::Gnuplot3dDataset::SetDefaultStyle
static void SetDefaultStyle(const std::string &style)
Change default style for all newly created objects.
Definition: gnuplot.cc:582
ns3::Gnuplot::SetExtra
void SetExtra(const std::string &extra)
Definition: gnuplot.cc:743
ns3::Gnuplot3dDataset
Class to represent a 3D points plot.
Definition: gnuplot.h:273
ns3::Gnuplot2dDataset::Data2d
Structure storing the data to for a 2D plot.
Definition: gnuplot.cc:165
ns3::Gnuplot2dDataset::Add
void Add(double x, double y)
Definition: gnuplot.cc:359
ns3::Gnuplot2dDataset
Class to represent a 2D points plot.
Definition: gnuplot.h:118
ns3::Gnuplot2dDataset::Point::empty
bool empty
the point is empty
Definition: gnuplot.h:218
ns3::GnuplotDataset::operator=
GnuplotDataset & operator=(const GnuplotDataset &original)
Reference-counting assignment operator.
Definition: gnuplot.cc:127
ns3::Gnuplot3dDataset::Point
A point in a 3D plot.
Definition: gnuplot.h:314
ns3::Gnuplot::m_extra
std::string m_extra
extra parameters for the plot
Definition: gnuplot.h:474
ns3::GnuplotCollection::m_plots
Plots m_plots
Plots in the collection.
Definition: gnuplot.h:541
ns3::Gnuplot2dDataset::NONE
@ NONE
Definition: gnuplot.h:138
ns3::Gnuplot2dDataset::Point::dx
double dx
X error delta.
Definition: gnuplot.h:221
ns3::GnuplotCollection::GnuplotCollection
GnuplotCollection(const std::string &outputFilename)
Definition: gnuplot.cc:855
ns3::Gnuplot::Gnuplot
Gnuplot(const std::string &outputFilename="", const std::string &title="")
Definition: gnuplot.cc:694
ns3::Gnuplot2dDataset::Y
@ Y
Definition: gnuplot.h:140
ns3::Gnuplot2dDataset::Point::dy
double dy
Y error delta.
Definition: gnuplot.h:222
ns3::Gnuplot2dDataset::LINES
@ LINES
Definition: gnuplot.h:124
data
uint8_t data[writeSize]
Definition: socket-bound-tcp-static-routing.cc:53
ns3::Gnuplot2dDataset::PointSet
std::vector< struct Point > PointSet
The set of points in the dataset.
Definition: gnuplot.h:226
ns3::GnuplotDataset::GnuplotDataset
GnuplotDataset(const GnuplotDataset &original)
Reference-counting copy constructor.
Definition: gnuplot.cc:115
ns3::GnuplotCollection::Plots
std::vector< Gnuplot > Plots
Type of the Gnuplot collection.
Definition: gnuplot.h:536
ns3::Gnuplot::m_title
std::string m_title
Plot title.
Definition: gnuplot.h:471
ns3::Gnuplot2dDataset::Point::x
double x
X coordinate.
Definition: gnuplot.h:219
ns3::Gnuplot3dFunction::Gnuplot3dFunction
Gnuplot3dFunction(const std::string &title="Untitled", const std::string &function="")
Definition: gnuplot.cc:681
ns3::Gnuplot::AddDataset
void AddDataset(const GnuplotDataset &dataset)
Definition: gnuplot.cc:756
ns3::Gnuplot3dDataset::Point::empty
bool empty
the point is empty
Definition: gnuplot.h:315
ns3::Gnuplot2dDataset::FSTEPS
@ FSTEPS
Definition: gnuplot.h:130
ns3::Gnuplot2dDataset::HISTEPS
@ HISTEPS
Definition: gnuplot.h:131
ns3::Gnuplot3dDataset::SetStyle
void SetStyle(const std::string &style)
Definition: gnuplot.cc:587
ns3::Gnuplot2dDataset::SetDefaultStyle
static void SetDefaultStyle(enum Style style)
Change default style for all newly created objects.
Definition: gnuplot.cc:337
ns3::Gnuplot2dDataset::XY
@ XY
Definition: gnuplot.h:141
ns3::Gnuplot2dDataset::DOTS
@ DOTS
Definition: gnuplot.h:127
ns3::GnuplotDataset::Data
Structure storing the data to plot.
Definition: gnuplot.cc:37
ns3::Gnuplot2dFunction::SetFunction
void SetFunction(const std::string &function)
Definition: gnuplot.cc:485
ns3::Gnuplot2dDataset::AddEmptyLine
void AddEmptyLine()
Add an empty line in the data output sequence.
Definition: gnuplot.cc:402
ns3::Gnuplot3dDataset::Data3d
Structure storing the data for a 3D plot.
Definition: gnuplot.cc:498
ns3::GnuplotCollection::AddPlot
void AddPlot(const Gnuplot &plot)
Definition: gnuplot.cc:868
ns3::Gnuplot::SetTitle
void SetTitle(const std::string &title)
Definition: gnuplot.cc:730
ns3::Gnuplot3dDataset::Point::y
double y
Y coordinate.
Definition: gnuplot.h:317
ns3::Gnuplot2dFunction
Class to represent a 2D function expression plot.
Definition: gnuplot.h:244
ns3::Gnuplot2dDataset::POINTS
@ POINTS
Definition: gnuplot.h:125
sample-rng-plot.x
list x
Definition: sample-rng-plot.py:34
ns3::Gnuplot3dDataset::AddEmptyLine
void AddEmptyLine()
Add an empty line in the data output sequence.
Definition: gnuplot.cc:604
ns3::Gnuplot::AppendExtra
void AppendExtra(const std::string &extra)
Definition: gnuplot.cc:749
ns3::GnuplotDataset::m_defaultExtra
static std::string m_defaultExtra
Extra gnuplot parameters set on every newly created dataset.
Definition: gnuplot.h:91
ns3::GnuplotDataset::SetDefaultExtra
static void SetDefaultExtra(const std::string &extra)
Change extra formatting style parameters for newly created objects.
Definition: gnuplot.cc:147
ns3::GnuplotDataset::SetExtra
void SetExtra(const std::string &extra)
Add extra formatting parameters to this dataset.
Definition: gnuplot.cc:152
ns3::GnuplotDataset::SetTitle
void SetTitle(const std::string &title)
Change line title.
Definition: gnuplot.cc:141
ns3::Gnuplot2dDataset::ErrorBars
ErrorBars
Whether errorbars should be used for this dataset.
Definition: gnuplot.h:137
ns3::Gnuplot::DetectTerminal
static std::string DetectTerminal(const std::string &filename)
Crude attempt to auto-detect the correct terminal setting by inspecting the filename's extension.
Definition: gnuplot.cc:708
ns3::Gnuplot2dFunction::Gnuplot2dFunction
Gnuplot2dFunction(const std::string &title="Untitled", const std::string &function="")
Definition: gnuplot.cc:479
ns3::Gnuplot3dDataset::Gnuplot3dDataset
Gnuplot3dDataset(const std::string &title="Untitled")
Definition: gnuplot.cc:576
ns3::Gnuplot2dDataset::Point
A point in a 2D plot.
Definition: gnuplot.h:217
ns3::GnuplotCollection::m_terminal
std::string m_terminal
Gnuplot "terminal" to use.
Definition: gnuplot.h:539
ns3::Gnuplot2dDataset::X
@ X
Definition: gnuplot.h:139
ns3::Gnuplot2dDataset::SetErrorBars
void SetErrorBars(enum ErrorBars errorBars)
Definition: gnuplot.cc:353
ns3::Gnuplot::m_xLegend
std::string m_xLegend
X axis legend.
Definition: gnuplot.h:472
ns3::GnuplotCollection::GenerateOutput
void GenerateOutput(std::ostream &os)
Definition: gnuplot.cc:883
ns3::Gnuplot2dDataset::SetDefaultErrorBars
static void SetDefaultErrorBars(enum ErrorBars errorBars)
Change default errorbars style for all newly created objects.
Definition: gnuplot.cc:348
ns3::Gnuplot2dDataset::Gnuplot2dDataset
Gnuplot2dDataset(const std::string &title="Untitled")
Definition: gnuplot.cc:331
ns3::Gnuplot2dDataset::Style
Style
The plotting style to use for this dataset.
Definition: gnuplot.h:123
ns3::GnuplotDataset
Abstract class to store a plot line to be used by ns3::Gnuplot.
Definition: gnuplot.h:39
ns3::Gnuplot2dFunction::Function2d
Structure storing the function to be used for a 2D plot.
Definition: gnuplot.cc:417
ns3::GnuplotCollection::GetPlot
Gnuplot & GetPlot(unsigned int id)
Return a pointer to one of the added plots.
Definition: gnuplot.cc:874
ns3::Gnuplot::m_terminal
std::string m_terminal
Gnuplot "terminal" to use.
Definition: gnuplot.h:467