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 {
133  };
134 
138  enum ErrorBars {
140  X,
141  Y,
142  XY
143  };
144 
151  Gnuplot2dDataset (const std::string& title = "Untitled");
152 
157  static void SetDefaultStyle (enum Style style);
158 
162  void SetStyle (enum Style style);
163 
168  static void SetDefaultErrorBars (enum ErrorBars errorBars);
169 
178  void SetErrorBars (enum ErrorBars errorBars);
179 
186  void Add (double x, double y);
187 
195  void Add (double x, double y, double errorDelta);
196 
205  void Add (double x, double y, double xErrorDelta, double yErrorDelta);
206 
211  void AddEmptyLine ();
212 
213 private:
214 
218  struct Point {
219  bool empty;
220  double x;
221  double y;
222  double dx;
223  double dy;
224  };
225 
227  typedef std::vector<struct Point> PointSet;
228 
229  static enum Style m_defaultStyle;
230  static enum ErrorBars m_defaultErrorBars;
231 
233  struct Data2d;
234 };
235 
245 {
246 public:
254  Gnuplot2dFunction (const std::string& title = "Untitled", const std::string& function = "");
255 
259  void SetFunction (const std::string& function);
260 
261 private:
262 
264  struct Function2d;
265 };
266 
274 {
275 public:
282  Gnuplot3dDataset (const std::string& title = "Untitled");
283 
288  static void SetDefaultStyle (const std::string& style);
289 
293  void SetStyle (const std::string& style);
294 
302  void Add (double x, double y, double z);
303 
308  void AddEmptyLine ();
309 
310 private:
311 
315  struct Point {
316  bool empty;
317  double x;
318  double y;
319  double z;
320  };
321 
323  typedef std::vector<struct Point> PointSet;
324 
325  static std::string m_defaultStyle;
326 
328  struct Data3d;
329 };
330 
341 {
342 public:
350  Gnuplot3dFunction (const std::string& title = "Untitled", const std::string& function = "");
351 
355  void SetFunction (const std::string& function);
356 
357 private:
358 
360  struct Function3d;
361 };
362 
372 class Gnuplot
373 {
374 public:
381  Gnuplot (const std::string& outputFilename="", const std::string& title = "");
382 
388  void SetOutputFilename (const std::string& outputFilename);
389 
396  static std::string DetectTerminal (const std::string& filename);
397 
402  void SetTerminal (const std::string& terminal);
403 
407  void SetTitle (const std::string& title);
408 
413  void SetLegend (const std::string& xLegend, const std::string& yLegend);
414 
418  void SetExtra (const std::string& extra);
419 
423  void AppendExtra (const std::string& extra);
424 
428  void AddDataset (const GnuplotDataset& dataset);
429 
438  void GenerateOutput (std::ostream &os);
439 
452  void GenerateOutput (std::ostream &osControl,
453  std::ostream &osData,
454  std::string dataFileName);
455 
461  void SetDataFileDatasetIndex (unsigned int index);
462 
463 private:
465  typedef std::vector<GnuplotDataset> Datasets;
466 
467  std::string m_outputFilename;
468  std::string m_terminal;
469 
471 
472  std::string m_title;
473  std::string m_xLegend;
474  std::string m_yLegend;
475  std::string m_extra;
476 
478 
479  unsigned int m_dataFileDatasetIndex;
480 };
481 
489 {
490 public:
496  GnuplotCollection (const std::string& outputFilename);
497 
502  void SetTerminal (const std::string& terminal);
503 
507  void AddPlot (const Gnuplot& plot);
508 
514  Gnuplot& GetPlot (unsigned int id);
515 
520  void GenerateOutput (std::ostream &os);
521 
531  void GenerateOutput (std::ostream &osControl,
532  std::ostream &osData,
533  std::string dataFileName);
534 
535 private:
537  typedef std::vector<Gnuplot> Plots;
538 
539  std::string m_outputFilename;
540  std::string m_terminal;
541 
543 };
544 
545 } // namespace ns3
546 
547 #endif /* GNUPLOT_H */
Class to represent a 2D points plot.
Definition: gnuplot.h:118
void AddEmptyLine()
Add an empty line in the data output sequence.
Definition: gnuplot.cc:406
std::vector< struct Point > PointSet
The set of points in the dataset.
Definition: gnuplot.h:227
void SetErrorBars(enum ErrorBars errorBars)
Definition: gnuplot.cc:357
ErrorBars
Whether errorbars should be used for this dataset.
Definition: gnuplot.h:138
static enum Style m_defaultStyle
default plot style
Definition: gnuplot.h:229
void SetStyle(enum Style style)
Definition: gnuplot.cc:346
static void SetDefaultStyle(enum Style style)
Change default style for all newly created objects.
Definition: gnuplot.cc:341
void Add(double x, double y)
Definition: gnuplot.cc:363
Style
The plotting style to use for this dataset.
Definition: gnuplot.h:123
static void SetDefaultErrorBars(enum ErrorBars errorBars)
Change default errorbars style for all newly created objects.
Definition: gnuplot.cc:352
static enum ErrorBars m_defaultErrorBars
default error bars type
Definition: gnuplot.h:230
Gnuplot2dDataset(const std::string &title="Untitled")
Definition: gnuplot.cc:335
Class to represent a 2D function expression plot.
Definition: gnuplot.h:245
void SetFunction(const std::string &function)
Definition: gnuplot.cc:489
Gnuplot2dFunction(const std::string &title="Untitled", const std::string &function="")
Definition: gnuplot.cc:483
Class to represent a 3D points plot.
Definition: gnuplot.h:274
void AddEmptyLine()
Add an empty line in the data output sequence.
Definition: gnuplot.cc:608
Gnuplot3dDataset(const std::string &title="Untitled")
Definition: gnuplot.cc:580
static std::string m_defaultStyle
default plot style
Definition: gnuplot.h:325
std::vector< struct Point > PointSet
The set of points in the dataset.
Definition: gnuplot.h:323
void Add(double x, double y, double z)
Definition: gnuplot.cc:597
static void SetDefaultStyle(const std::string &style)
Change default style for all newly created objects.
Definition: gnuplot.cc:586
void SetStyle(const std::string &style)
Definition: gnuplot.cc:591
Class to represent a 3D function expression plot.
Definition: gnuplot.h:341
Gnuplot3dFunction(const std::string &title="Untitled", const std::string &function="")
Definition: gnuplot.cc:685
void SetFunction(const std::string &function)
Definition: gnuplot.cc:691
a simple class to group together multiple gnuplots into one file, e.g.
Definition: gnuplot.h:489
std::string m_outputFilename
Output file name.
Definition: gnuplot.h:539
GnuplotCollection(const std::string &outputFilename)
Definition: gnuplot.cc:859
void AddPlot(const Gnuplot &plot)
Definition: gnuplot.cc:872
void SetTerminal(const std::string &terminal)
Definition: gnuplot.cc:866
Gnuplot & GetPlot(unsigned int id)
Return a pointer to one of the added plots.
Definition: gnuplot.cc:878
std::string m_terminal
Gnuplot "terminal" to use.
Definition: gnuplot.h:540
Plots m_plots
Plots in the collection.
Definition: gnuplot.h:542
void GenerateOutput(std::ostream &os)
Definition: gnuplot.cc:887
std::vector< Gnuplot > Plots
Type of the Gnuplot collection.
Definition: gnuplot.h:537
Abstract class to store a plot line to be used by ns3::Gnuplot.
Definition: gnuplot.h:39
GnuplotDataset(const GnuplotDataset &original)
Reference-counting copy constructor.
Definition: gnuplot.cc:115
static void SetDefaultExtra(const std::string &extra)
Change extra formatting style parameters for newly created objects.
Definition: gnuplot.cc:147
GnuplotDataset & operator=(const GnuplotDataset &original)
Reference-counting assignment operator.
Definition: gnuplot.cc:127
struct Data * m_data
Reference counted data object.
Definition: gnuplot.h:107
void SetExtra(const std::string &extra)
Add extra formatting parameters to this dataset.
Definition: gnuplot.cc:152
static std::string m_defaultExtra
Extra gnuplot parameters set on every newly created dataset.
Definition: gnuplot.h:91
void SetTitle(const std::string &title)
Change line title.
Definition: gnuplot.cc:141
~GnuplotDataset()
Reference-counting destructor.
Definition: gnuplot.cc:121
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
Definition: gnuplot.h:373
std::string m_yLegend
Y axis legend.
Definition: gnuplot.h:474
void AddDataset(const GnuplotDataset &dataset)
Definition: gnuplot.cc:760
void SetLegend(const std::string &xLegend, const std::string &yLegend)
Definition: gnuplot.cc:740
void SetTerminal(const std::string &terminal)
Definition: gnuplot.cc:728
std::string m_terminal
Gnuplot "terminal" to use.
Definition: gnuplot.h:468
std::string m_extra
extra parameters for the plot
Definition: gnuplot.h:475
unsigned int m_dataFileDatasetIndex
Data set index to plot.
Definition: gnuplot.h:479
void AppendExtra(const std::string &extra)
Definition: gnuplot.cc:753
Datasets m_datasets
Data sets.
Definition: gnuplot.h:470
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
Definition: gnuplot.cc:766
std::string m_title
Plot title.
Definition: gnuplot.h:472
std::vector< GnuplotDataset > Datasets
Type for Datasets to be used in plots.
Definition: gnuplot.h:465
void SetDataFileDatasetIndex(unsigned int index)
Sets the current data stream index in the data file.
Definition: gnuplot.cc:852
std::string m_xLegend
X axis legend.
Definition: gnuplot.h:473
std::string m_outputFilename
Output file name.
Definition: gnuplot.h:467
Gnuplot(const std::string &outputFilename="", const std::string &title="")
Definition: gnuplot.cc:698
void SetExtra(const std::string &extra)
Definition: gnuplot.cc:747
void SetTitle(const std::string &title)
Definition: gnuplot.cc:734
void SetOutputFilename(const std::string &outputFilename)
Definition: gnuplot.cc:707
bool m_generateOneOutputFile
true if only one plot will be generated
Definition: gnuplot.h:477
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:712
Every class exported by the ns3 library is enclosed in the ns3 namespace.
list x
Random number samples.
uint8_t data[writeSize]
Structure storing the data to for a 2D plot.
Definition: gnuplot.cc:165
A point in a 2D plot.
Definition: gnuplot.h:218
double y
Y coordinate.
Definition: gnuplot.h:221
double dx
X error delta.
Definition: gnuplot.h:222
bool empty
the point is empty
Definition: gnuplot.h:219
double x
X coordinate.
Definition: gnuplot.h:220
double dy
Y error delta.
Definition: gnuplot.h:223
Structure storing the function to be used for a 2D plot.
Definition: gnuplot.cc:421
Structure storing the data for a 3D plot.
Definition: gnuplot.cc:502
A point in a 3D plot.
Definition: gnuplot.h:315
bool empty
the point is empty
Definition: gnuplot.h:316
double x
X coordinate.
Definition: gnuplot.h:317
double z
Z coordinate.
Definition: gnuplot.h:319
double y
Y coordinate.
Definition: gnuplot.h:318
Structure storing the function to be used for a 3D plot.
Definition: gnuplot.cc:623
Structure storing the data to plot.
Definition: gnuplot.cc:37