A Discrete-Event Network Simulator
API
gnuplot.cc
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 #include "gnuplot.h"
22 #include "ns3/assert.h"
23 #include <ostream>
24 #include <stdexcept>
25 
26 namespace ns3 {
27 
28 // --- GnuplotDataset::Data ------------------------------------------------ //
29 
37 {
38  // *** Data Variables ***
39 
40  unsigned int m_references;
41 
42  std::string m_title;
43  std::string m_extra;
44 
49  Data(const std::string& title);
50 
52  virtual ~Data();
53 
58  virtual std::string GetCommand () const = 0;
59 
74  virtual void PrintExpression (std::ostream &os,
75  bool generateOneOutputFile,
76  unsigned int dataFileDatasetIndex,
77  std::string &dataFileName) const = 0;
78 
86  virtual void PrintDataFile (std::ostream &os, bool generateOneOutputFile) const = 0;
87 
92  virtual bool IsEmpty () const = 0;
93 };
94 
95 GnuplotDataset::Data::Data(const std::string& title)
96  : m_references (1),
97  m_title (title),
98  m_extra (m_defaultExtra)
99 {
100 }
101 
103 {
104 }
105 
106 // --- GnuplotDataset ------------------------------------------------------ //
107 
108 std::string GnuplotDataset::m_defaultExtra = "";
109 
111  : m_data (data)
112 {
113 }
114 
116  : m_data (original.m_data)
117 {
118  ++m_data->m_references;
119 }
120 
122 {
123  if (--m_data->m_references == 0)
124  delete m_data;
125 }
126 
128 {
129  if (this != &original)
130  {
131  if (--m_data->m_references == 0)
132  delete m_data;
133 
134  m_data = original.m_data;
135  ++m_data->m_references;
136  }
137  return *this;
138 }
139 
140 void
141 GnuplotDataset::SetTitle (const std::string& title)
142 {
143  m_data->m_title = title;
144 }
145 
146 void
147 GnuplotDataset::SetDefaultExtra (const std::string& extra)
148 {
149  m_defaultExtra = extra;
150 }
151 void
152 GnuplotDataset::SetExtra (const std::string& extra)
153 {
154  m_data->m_extra = extra;
155 }
156 
157 // --- Gnuplot2dDataset::Data2d -------------------------------------------- //
158 
165 {
166  // *** Data Variables ***
167 
168  enum Style m_style;
169  enum ErrorBars m_errorBars;
170 
172 
177  Data2d(const std::string& title);
178 
179  virtual std::string GetCommand () const;
180  virtual void PrintExpression (std::ostream &os,
181  bool generateOneOutputFile,
182  unsigned int dataFileDatasetIndex,
183  std::string &dataFileName) const;
184  virtual void PrintDataFile (std::ostream &os, bool generateOneOutputFile) const;
185  virtual bool IsEmpty () const;
186 };
187 
188 Gnuplot2dDataset::Data2d::Data2d(const std::string& title)
189  : Data (title),
190  m_style (m_defaultStyle),
191  m_errorBars (m_defaultErrorBars)
192 {
193 }
194 
195 std::string
197 {
198  return "plot";
199 }
200 
201 void
203  bool generateOneOutputFile,
204  unsigned int dataFileDatasetIndex,
205  std::string &dataFileName) const
206 {
207  // Print the appropriate thing based on whether separate output and
208  // date files are being generated.
209  if (generateOneOutputFile)
210  {
211  os << "\"-\" ";
212  }
213  else
214  {
215  os << "\"" << dataFileName << "\" index " << dataFileDatasetIndex;
216  }
217 
218  if (m_title.size ())
219  os << " title \"" << m_title << "\"";
220 
221  switch (m_style) {
222  case LINES:
223  os << " with lines";
224  break;
225  case POINTS:
226  switch (m_errorBars)
227  {
228  case NONE:
229  os << " with points";
230  break;
231  case X:
232  os << " with xerrorbars";
233  break;
234  case Y:
235  os << " with yerrorbars";
236  break;
237  case XY:
238  os << " with xyerrorbars";
239  break;
240  }
241  break;
242  case LINES_POINTS:
243  switch (m_errorBars)
244  {
245  case NONE:
246  os << " with linespoints";
247  break;
248  case X:
249  os << " with errorlines";
250  break;
251  case Y:
252  os << " with yerrorlines";
253  break;
254  case XY:
255  os << " with xyerrorlines";
256  break;
257  }
258  break;
259  case DOTS:
260  os << " with dots";
261  break;
262  case IMPULSES:
263  os << " with impulses";
264  break;
265  case STEPS:
266  os << " with steps";
267  break;
268  case FSTEPS:
269  os << " with fsteps";
270  break;
271  case HISTEPS:
272  os << " with histeps";
273  case FILLEDCURVE:
274  os << " with filledcurve";
275  break;
276  }
277 
278  if (m_extra.size ())
279  os << " " << m_extra;
280 }
281 
282 void
283 Gnuplot2dDataset::Data2d::PrintDataFile (std::ostream &os, bool generateOneOutputFile) const
284 {
285  for (PointSet::const_iterator i = m_pointset.begin ();
286  i != m_pointset.end (); ++i)
287  {
288  if (i->empty) {
289  os << std::endl;
290  continue;
291  }
292 
293  switch (m_errorBars) {
294  case NONE:
295  os << i->x << " " << i->y << std::endl;
296  break;
297  case X:
298  os << i->x << " " << i->y << " " << i->dx << std::endl;
299  break;
300  case Y:
301  os << i->x << " " << i->y << " " << i->dy << std::endl;
302  break;
303  case XY:
304  os << i->x << " " << i->y << " " << i->dx << " " << i->dy << std::endl;
305  break;
306  }
307  }
308 
309  // Print the appropriate thing based on whether separate output and
310  // date files are being generated.
311  if (generateOneOutputFile)
312  {
313  os << "e" << std::endl;
314  }
315  else
316  {
317  os << std::endl;
318  os << std::endl;
319  }
320 }
321 
322 bool
324 {
325  return (m_pointset.size () == 0);
326 }
327 
328 // --- Gnuplot2dDataset ---------------------------------------------------- //
329 
334 
335 Gnuplot2dDataset::Gnuplot2dDataset (const std::string& title)
336  : GnuplotDataset ( new Data2d (title) )
337 {
338 }
339 
340 void
342 {
343  m_defaultStyle = style;
344 }
345 void
347 {
348  reinterpret_cast<Data2d*>(m_data)->m_style = style;
349 }
350 
351 void
353 {
354  m_defaultErrorBars = errorBars;
355 }
356 void
358 {
359  reinterpret_cast<Data2d*>(m_data)->m_errorBars = errorBars;
360 }
361 
362 void
363 Gnuplot2dDataset::Add (double x, double y)
364 {
365  NS_ASSERT (reinterpret_cast<Data2d*>(m_data)->m_errorBars == NONE);
366 
367  struct Point data;
368  data.empty = false;
369  data.x = x;
370  data.y = y;
371  data.dx = 0.0;
372  data.dy = 0.0;
373  reinterpret_cast<Data2d*>(m_data)->m_pointset.push_back (data);
374 }
375 
376 void
377 Gnuplot2dDataset::Add (double x, double y, double errorDelta)
378 {
379  NS_ASSERT ( reinterpret_cast<Data2d*>(m_data)->m_errorBars == X ||
380  reinterpret_cast<Data2d*>(m_data)->m_errorBars == Y );
381 
382  struct Point data;
383  data.empty = false;
384  data.x = x;
385  data.y = y;
386  data.dx = errorDelta;
387  data.dy = errorDelta;
388  reinterpret_cast<Data2d*>(m_data)->m_pointset.push_back (data);
389 }
390 
391 void
392 Gnuplot2dDataset::Add (double x, double y, double xErrorDelta, double yErrorDelta)
393 {
394  NS_ASSERT ( reinterpret_cast<Data2d*>(m_data)->m_errorBars == XY );
395 
396  struct Point data;
397  data.empty = false;
398  data.x = x;
399  data.y = y;
400  data.dx = xErrorDelta;
401  data.dy = yErrorDelta;
402  reinterpret_cast<Data2d*>(m_data)->m_pointset.push_back (data);
403 }
404 
405 void
407 {
408  struct Point data;
409  data.empty = true;
410  reinterpret_cast<Data2d*>(m_data)->m_pointset.push_back (data);
411 }
412 
413 // --- Gnuplot2dFunction::Function2d --------------------------------------- //
414 
421 {
422  // *** Data Variables ***
423 
424  std::string m_function;
425 
432  Function2d(const std::string& title, const std::string& function);
433 
434  virtual std::string GetCommand () const;
435  virtual void PrintExpression (std::ostream &os,
436  bool generateOneOutputFile,
437  unsigned int dataFileDatasetIndex,
438  std::string &dataFileName) const;
439  virtual void PrintDataFile (std::ostream &os, bool generateOneOutputFile) const;
440  virtual bool IsEmpty () const;
441 };
442 
443 Gnuplot2dFunction::Function2d::Function2d(const std::string& title, const std::string& function)
444  : Data (title),
445  m_function (function)
446 {
447 }
448 
449 std::string
451 {
452  return "plot";
453 }
454 
455 void
457  bool generateOneOutputFile,
458  unsigned int dataFileDatasetIndex,
459  std::string &dataFileName) const
460 {
461  os << m_function;
462 
463  if (m_title.size ())
464  os << " title \"" << m_title << "\"";
465 
466  if (m_extra.size ())
467  os << " " << m_extra;
468 }
469 
470 void
471 Gnuplot2dFunction::Function2d::PrintDataFile (std::ostream &os, bool generateOneOutputFile) const
472 {
473 }
474 
475 bool
477 {
478  return false;
479 }
480 
481 // --- Gnuplot2dFunction --------------------------------------------------- //
482 
483 Gnuplot2dFunction::Gnuplot2dFunction (const std::string& title, const std::string& function)
484  : GnuplotDataset ( new Function2d (title, function) )
485 {
486 }
487 
488 void
489 Gnuplot2dFunction::SetFunction (const std::string& function)
490 {
491  reinterpret_cast<Function2d*>(m_data)->m_function = function;
492 }
493 
494 // --- Gnuplot3dDataset::Data3d -------------------------------------------- //
495 
502 {
503  // *** Data Variables ***
504 
505  std::string m_style;
506 
508 
513  Data3d(const std::string& title);
514 
515  virtual std::string GetCommand () const;
516  virtual void PrintExpression (std::ostream &os,
517  bool generateOneOutputFile,
518  unsigned int dataFileDatasetIndex,
519  std::string &dataFileName) const;
520  virtual void PrintDataFile (std::ostream &os, bool generateOneOutputFile) const;
521  virtual bool IsEmpty () const;
522 };
523 
524 Gnuplot3dDataset::Data3d::Data3d(const std::string& title)
525  : Data (title),
526  m_style (m_defaultStyle)
527 {
528 }
529 
530 std::string
532 {
533  return "splot";
534 }
535 
536 void
538  bool generateOneOutputFile,
539  unsigned int dataFileDatasetIndex,
540  std::string &dataFileName) const
541 {
542  os << "\"-\" ";
543 
544  if (m_style.size ())
545  os << " " << m_style;
546 
547  if (m_title.size ())
548  os << " title \"" << m_title << "\"";
549 
550  if (m_extra.size ())
551  os << " " << m_extra;
552 }
553 
554 void
555 Gnuplot3dDataset::Data3d::PrintDataFile (std::ostream &os, bool generateOneOutputFile) const
556 {
557  for (PointSet::const_iterator i = m_pointset.begin ();
558  i != m_pointset.end (); ++i)
559  {
560  if (i->empty) {
561  os << std::endl;
562  continue;
563  }
564 
565  os << i->x << " " << i->y << " " << i->z << std::endl;
566  }
567  os << "e" << std::endl;
568 }
569 
570 bool
572 {
573  return (m_pointset.size () == 0);
574 }
575 
576 // --- Gnuplot3dDataset ---------------------------------------------------- //
577 
578 std::string Gnuplot3dDataset::m_defaultStyle = "";
579 
580 Gnuplot3dDataset::Gnuplot3dDataset (const std::string& title)
581  : GnuplotDataset ( new Data3d (title) )
582 {
583 }
584 
585 void
586 Gnuplot3dDataset::SetDefaultStyle (const std::string& style)
587 {
588  m_defaultStyle = style;
589 }
590 void
591 Gnuplot3dDataset::SetStyle (const std::string& style)
592 {
593  reinterpret_cast<Data3d*>(m_data)->m_style = style;
594 }
595 
596 void
597 Gnuplot3dDataset::Add (double x, double y, double z)
598 {
599  struct Point data;
600  data.empty = false;
601  data.x = x;
602  data.y = y;
603  data.z = z;
604  reinterpret_cast<Data3d*>(m_data)->m_pointset.push_back (data);
605 }
606 
607 void
609 {
610  struct Point data;
611  data.empty = true;
612  reinterpret_cast<Data3d*>(m_data)->m_pointset.push_back (data);
613 }
614 
615 // --- Gnuplot3dFunction::Function3d --------------------------------------- //
616 
623 {
624  // *** Data Variables ***
625 
626  std::string m_function;
627 
634  Function3d(const std::string& title, const std::string& function);
635 
636  virtual std::string GetCommand () const;
637  virtual void PrintExpression (std::ostream &os,
638  bool generateOneOutputFile,
639  unsigned int dataFileDatasetIndex,
640  std::string &dataFileName) const;
641  virtual void PrintDataFile (std::ostream &os, bool generateOneOutputFile) const;
642  virtual bool IsEmpty () const;
643 };
644 
645 Gnuplot3dFunction::Function3d::Function3d(const std::string& title, const std::string& function)
646  : Data (title),
647  m_function (function)
648 {
649 }
650 
651 std::string
653 {
654  return "splot";
655 }
656 
657 void
659  bool generateOneOutputFile,
660  unsigned int dataFileDatasetIndex,
661  std::string &dataFileName) const
662 {
663  os << m_function;
664 
665  if (m_title.size ())
666  os << " title \"" << m_title << "\"";
667 
668  if (m_extra.size ())
669  os << " " << m_extra;
670 }
671 
672 void
673 Gnuplot3dFunction::Function3d::PrintDataFile (std::ostream &os, bool generateOneOutputFile) const
674 {
675 }
676 
677 bool
679 {
680  return false;
681 }
682 
683 // --- Gnuplot3dFunction --------------------------------------------------- //
684 
685 Gnuplot3dFunction::Gnuplot3dFunction (const std::string& title, const std::string& function)
686  : GnuplotDataset ( new Function3d (title, function) )
687 {
688 }
689 
690 void
691 Gnuplot3dFunction::SetFunction (const std::string& function)
692 {
693  reinterpret_cast<Function3d*>(m_data)->m_function = function;
694 }
695 
696 // ------------------------------------------------------------------------- //
697 
698 Gnuplot::Gnuplot (const std::string& outputFilename, const std::string& title)
699  : m_outputFilename (outputFilename),
700  m_terminal ( DetectTerminal (outputFilename) ),
701  m_title (title),
702  m_generateOneOutputFile (false),
703  m_dataFileDatasetIndex (0)
704 {
705 }
706 
707 void Gnuplot::SetOutputFilename (const std::string& outputFilename)
708 {
709  m_outputFilename = outputFilename;
710 }
711 
712 std::string Gnuplot::DetectTerminal (const std::string& filename)
713 {
714  std::string::size_type dotpos = filename.rfind ('.');
715  if (dotpos == std::string::npos) return "";
716 
717  if (filename.substr (dotpos) == ".png") {
718  return "png";
719  }
720  else if (filename.substr (dotpos) == ".pdf") {
721  return "pdf";
722  }
723 
724  return "";
725 }
726 
727 void
728 Gnuplot::SetTerminal (const std::string& terminal)
729 {
730  m_terminal = terminal;
731 }
732 
733 void
734 Gnuplot::SetTitle (const std::string& title)
735 {
736  m_title = title;
737 }
738 
739 void
740 Gnuplot::SetLegend (const std::string& xLegend, const std::string& yLegend)
741 {
742  m_xLegend = xLegend;
743  m_yLegend = yLegend;
744 }
745 
746 void
747 Gnuplot::SetExtra (const std::string& extra)
748 {
749  m_extra = extra;
750 }
751 
752 void
753 Gnuplot::AppendExtra (const std::string& extra)
754 {
755  m_extra += "\n";
756  m_extra += extra;
757 }
758 
759 void
761 {
762  m_datasets.push_back (dataset);
763 }
764 
765 void
766 Gnuplot::GenerateOutput (std::ostream &os)
767 {
768  // If this version of this function is called, it is assumed that a
769  // single output file is being generated.
771 
772  // Send the gnuplot metadata to the same stream as the data stream.
773  GenerateOutput (os, os, "");
774 }
775 
776 void
777 Gnuplot::GenerateOutput (std::ostream &osControl,
778  std::ostream &osData,
779  std::string dataFileName)
780 {
781  if (m_terminal.size ())
782  osControl << "set terminal " << m_terminal << std::endl;
783 
784  if (m_outputFilename.size ())
785  osControl << "set output \"" << m_outputFilename << "\"" << std::endl;
786 
787  if (m_title.size ())
788  osControl << "set title \"" << m_title << "\"" << std::endl;
789 
790  if (m_xLegend.size ())
791  osControl << "set xlabel \"" << m_xLegend << "\"" << std::endl;
792 
793  if (m_yLegend.size ())
794  osControl << "set ylabel \"" << m_yLegend << "\"" << std::endl;
795 
796  if (m_extra.size ())
797  osControl << m_extra << std::endl;
798 
799  if (m_datasets.empty ())
800  return;
801 
802  // Determine the GetCommand() values of all datasets included. Check that all
803  // are equal and print the command.
804 
805  std::string command = m_datasets.begin ()->m_data->GetCommand ();
806 
807  for (Datasets::const_iterator i = m_datasets.begin () + 1;
808  i != m_datasets.end (); ++i)
809  {
810  NS_ASSERT_MSG (command == i->m_data->GetCommand (),
811  "Cannot mix 'plot' and 'splot' GnuplotDatasets.");
812  }
813 
814  osControl << command << " ";
815 
816  // Print all dataset expressions
817 
818  bool isDataEmpty;
819  for (Datasets::const_iterator i = m_datasets.begin (); i != m_datasets.end ();)
820  {
821  // Only print the dataset if it's not empty.
822  isDataEmpty = i->m_data->IsEmpty ();
823  if (!isDataEmpty)
824  {
825  // Print the appropriate expression based on whether we are
826  // generating separate output and date files.
827  i->m_data->PrintExpression (osControl,
830  dataFileName);
831 
833  }
834 
835  i++;
836  if (i != m_datasets.end () && !isDataEmpty)
837  {
838  osControl << ", ";
839  }
840  }
841  osControl << std::endl;
842 
843  // followed by the inline datafile.
844 
845  for (Datasets::const_iterator i = m_datasets.begin (); i != m_datasets.end (); i++)
846  {
847  i->m_data->PrintDataFile (osData, m_generateOneOutputFile);
848  }
849 }
850 
851 void
853 {
854  m_dataFileDatasetIndex = index;
855 }
856 
857 // ------------------------------------------------------------------------- //
858 
859 GnuplotCollection::GnuplotCollection (const std::string& outputFilename)
860  : m_outputFilename (outputFilename),
861  m_terminal ( Gnuplot::DetectTerminal (outputFilename) )
862 {
863 }
864 
865 void
866 GnuplotCollection::SetTerminal (const std::string& terminal)
867 {
868  m_terminal = terminal;
869 }
870 
871 void
873 {
874  m_plots.push_back (plot);
875 }
876 
877 Gnuplot&
878 GnuplotCollection::GetPlot (unsigned int id)
879 {
880  if (id >= m_plots.size ())
881  throw(std::range_error ("Gnuplot id is out of range"));
882  else
883  return m_plots[id];
884 }
885 
886 void
888 {
889  // If this version of this function is called, it is assumed that a
890  // single output file is being generated.
891 
892  if (m_terminal.size ())
893  os << "set terminal " << m_terminal << std::endl;
894 
895  if (m_outputFilename.size ())
896  os << "set output \"" << m_outputFilename << "\"" << std::endl;
897 
898  for (Plots::iterator i = m_plots.begin (); i != m_plots.end (); ++i)
899  {
900  i->GenerateOutput (os);
901  }
902 }
903 
904 void
905 GnuplotCollection::GenerateOutput (std::ostream &osControl, std::ostream &osData,
906 std::string dataFileName)
907 {
908  // If this version of this function is called, it is assumed that
909  // separate output and date files are being generated.
910 
911  if (m_terminal.size ())
912  osControl << "set terminal " << m_terminal << std::endl;
913 
914  if (m_outputFilename.size ())
915  osControl << "set output \"" << m_outputFilename << "\"" << std::endl;
916 
917  for (Plots::iterator i = m_plots.begin (); i != m_plots.end (); ++i)
918  {
919  i->GenerateOutput (osControl, osData, dataFileName);
920  }
921 }
922 
923 // ------------------------------------------------------------------------- //
924 
925 } // namespace ns3
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
void SetFunction(const std::string &function)
Definition: gnuplot.cc:489
Gnuplot2dFunction(const std::string &title="Untitled", const std::string &function="")
Definition: gnuplot.cc:483
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
Gnuplot3dFunction(const std::string &title="Untitled", const std::string &function="")
Definition: gnuplot.cc:685
void SetFunction(const std::string &function)
Definition: gnuplot.cc:691
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
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
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
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:67
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:88
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
virtual void PrintExpression(std::ostream &os, bool generateOneOutputFile, unsigned int dataFileDatasetIndex, std::string &dataFileName) const
Prints the plot description used as argument to (s)plot.
Definition: gnuplot.cc:202
enum ErrorBars m_errorBars
Whether errorbars should be used for this dataset.
Definition: gnuplot.cc:169
virtual std::string GetCommand() const
Returns the plot type ("plot" or "splot").
Definition: gnuplot.cc:196
virtual void PrintDataFile(std::ostream &os, bool generateOneOutputFile) const
Print the inline data file contents trailing the plot command.
Definition: gnuplot.cc:283
PointSet m_pointset
The set of points in this data set.
Definition: gnuplot.cc:171
virtual bool IsEmpty() const
Checks to see if this GnuplotDataset is empty.
Definition: gnuplot.cc:323
Data2d(const std::string &title)
Initializes with the values from m_defaultStyle and m_defaultErrorBars.
Definition: gnuplot.cc:188
enum Style m_style
The plotting style to use for this dataset.
Definition: gnuplot.cc:168
A point in a 2D plot.
Definition: gnuplot.h:218
Structure storing the function to be used for a 2D plot.
Definition: gnuplot.cc:421
virtual void PrintDataFile(std::ostream &os, bool generateOneOutputFile) const
Print the inline data file contents trailing the plot command.
Definition: gnuplot.cc:471
Function2d(const std::string &title, const std::string &function)
Initializes with the function and title.
Definition: gnuplot.cc:443
virtual void PrintExpression(std::ostream &os, bool generateOneOutputFile, unsigned int dataFileDatasetIndex, std::string &dataFileName) const
Prints the plot description used as argument to (s)plot.
Definition: gnuplot.cc:456
std::string m_function
Function to use.
Definition: gnuplot.cc:424
virtual std::string GetCommand() const
Returns the plot type ("plot" or "splot").
Definition: gnuplot.cc:450
virtual bool IsEmpty() const
Checks to see if this GnuplotDataset is empty.
Definition: gnuplot.cc:476
Structure storing the data for a 3D plot.
Definition: gnuplot.cc:502
virtual void PrintExpression(std::ostream &os, bool generateOneOutputFile, unsigned int dataFileDatasetIndex, std::string &dataFileName) const
Prints the plot description used as argument to (s)plot.
Definition: gnuplot.cc:537
virtual std::string GetCommand() const
Returns the plot type ("plot" or "splot").
Definition: gnuplot.cc:531
virtual bool IsEmpty() const
Checks to see if this GnuplotDataset is empty.
Definition: gnuplot.cc:571
std::string m_style
The plotting style to use for this dataset.
Definition: gnuplot.cc:505
PointSet m_pointset
The set of points in this data set.
Definition: gnuplot.cc:507
virtual void PrintDataFile(std::ostream &os, bool generateOneOutputFile) const
Print the inline data file contents trailing the plot command.
Definition: gnuplot.cc:555
Data3d(const std::string &title)
Initializes with value from m_defaultStyle.
Definition: gnuplot.cc:524
A point in a 3D plot.
Definition: gnuplot.h:315
Structure storing the function to be used for a 3D plot.
Definition: gnuplot.cc:623
std::string m_function
Function to use.
Definition: gnuplot.cc:626
virtual void PrintDataFile(std::ostream &os, bool generateOneOutputFile) const
Print the inline data file contents trailing the plot command.
Definition: gnuplot.cc:673
virtual void PrintExpression(std::ostream &os, bool generateOneOutputFile, unsigned int dataFileDatasetIndex, std::string &dataFileName) const
Prints the plot description used as argument to (s)plot.
Definition: gnuplot.cc:658
Function3d(const std::string &title, const std::string &function)
Initializes with the function and title.
Definition: gnuplot.cc:645
virtual bool IsEmpty() const
Checks to see if this GnuplotDataset is empty.
Definition: gnuplot.cc:678
virtual std::string GetCommand() const
Returns the plot type ("plot" or "splot").
Definition: gnuplot.cc:652
Structure storing the data to plot.
Definition: gnuplot.cc:37
unsigned int m_references
ref/unref counter for garbage collection
Definition: gnuplot.cc:40
std::string m_extra
Extra parameters for the plot.
Definition: gnuplot.cc:43
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 ~Data()
Required.
Definition: gnuplot.cc:102
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.
Definition: gnuplot.cc:95
std::string m_title
Dataset title.
Definition: gnuplot.cc:42
virtual std::string GetCommand() const =0
Returns the plot type ("plot" or "splot").