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;
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  break;
274  }
275 
276  if (m_extra.size ())
277  os << " " << m_extra;
278 }
279 
280 void
281 Gnuplot2dDataset::Data2d::PrintDataFile (std::ostream &os, bool generateOneOutputFile) const
282 {
283  for (PointSet::const_iterator i = m_pointset.begin ();
284  i != m_pointset.end (); ++i)
285  {
286  if (i->empty) {
287  os << std::endl;
288  continue;
289  }
290 
291  switch (m_errorBars) {
292  case NONE:
293  os << i->x << " " << i->y << std::endl;
294  break;
295  case X:
296  os << i->x << " " << i->y << " " << i->dx << std::endl;
297  break;
298  case Y:
299  os << i->x << " " << i->y << " " << i->dy << std::endl;
300  break;
301  case XY:
302  os << i->x << " " << i->y << " " << i->dx << " " << i->dy << std::endl;
303  break;
304  }
305  }
306 
307  // Print the appropriate thing based on whether separate output and
308  // date files are being generated.
309  if (generateOneOutputFile)
310  {
311  os << "e" << std::endl;
312  }
313  else
314  {
315  os << std::endl;
316  os << std::endl;
317  }
318 }
319 
320 bool
322 {
323  return (m_pointset.size () == 0);
324 }
325 
326 // --- Gnuplot2dDataset ---------------------------------------------------- //
327 
330 
331 Gnuplot2dDataset::Gnuplot2dDataset (const std::string& title)
332  : GnuplotDataset ( new Data2d (title) )
333 {
334 }
335 
336 void
338 {
339  m_defaultStyle = style;
340 }
341 void
343 {
344  reinterpret_cast<Data2d*>(m_data)->m_style = style;
345 }
346 
347 void
349 {
350  m_defaultErrorBars = errorBars;
351 }
352 void
354 {
355  reinterpret_cast<Data2d*>(m_data)->m_errorBars = errorBars;
356 }
357 
358 void
359 Gnuplot2dDataset::Add (double x, double y)
360 {
361  NS_ASSERT (reinterpret_cast<Data2d*>(m_data)->m_errorBars == NONE);
362 
363  struct Point data;
364  data.empty = false;
365  data.x = x;
366  data.y = y;
367  data.dx = 0.0;
368  data.dy = 0.0;
369  reinterpret_cast<Data2d*>(m_data)->m_pointset.push_back (data);
370 }
371 
372 void
373 Gnuplot2dDataset::Add (double x, double y, double errorDelta)
374 {
375  NS_ASSERT ( reinterpret_cast<Data2d*>(m_data)->m_errorBars == X ||
376  reinterpret_cast<Data2d*>(m_data)->m_errorBars == Y );
377 
378  struct Point data;
379  data.empty = false;
380  data.x = x;
381  data.y = y;
382  data.dx = errorDelta;
383  data.dy = errorDelta;
384  reinterpret_cast<Data2d*>(m_data)->m_pointset.push_back (data);
385 }
386 
387 void
388 Gnuplot2dDataset::Add (double x, double y, double xErrorDelta, double yErrorDelta)
389 {
390  NS_ASSERT ( reinterpret_cast<Data2d*>(m_data)->m_errorBars == XY );
391 
392  struct Point data;
393  data.empty = false;
394  data.x = x;
395  data.y = y;
396  data.dx = xErrorDelta;
397  data.dy = yErrorDelta;
398  reinterpret_cast<Data2d*>(m_data)->m_pointset.push_back (data);
399 }
400 
401 void
403 {
404  struct Point data;
405  data.empty = true;
406  reinterpret_cast<Data2d*>(m_data)->m_pointset.push_back (data);
407 }
408 
409 // --- Gnuplot2dFunction::Function2d --------------------------------------- //
410 
417 {
418  // *** Data Variables ***
419 
420  std::string m_function;
421 
428  Function2d(const std::string& title, const std::string& function);
429 
430  virtual std::string GetCommand () const;
431  virtual void PrintExpression (std::ostream &os,
432  bool generateOneOutputFile,
433  unsigned int dataFileDatasetIndex,
434  std::string &dataFileName) const;
435  virtual void PrintDataFile (std::ostream &os, bool generateOneOutputFile) const;
436  virtual bool IsEmpty () const;
437 };
438 
439 Gnuplot2dFunction::Function2d::Function2d(const std::string& title, const std::string& function)
440  : Data (title),
441  m_function (function)
442 {
443 }
444 
445 std::string
447 {
448  return "plot";
449 }
450 
451 void
453  bool generateOneOutputFile,
454  unsigned int dataFileDatasetIndex,
455  std::string &dataFileName) const
456 {
457  os << m_function;
458 
459  if (m_title.size ())
460  os << " title \"" << m_title << "\"";
461 
462  if (m_extra.size ())
463  os << " " << m_extra;
464 }
465 
466 void
467 Gnuplot2dFunction::Function2d::PrintDataFile (std::ostream &os, bool generateOneOutputFile) const
468 {
469 }
470 
471 bool
473 {
474  return false;
475 }
476 
477 // --- Gnuplot2dFunction --------------------------------------------------- //
478 
479 Gnuplot2dFunction::Gnuplot2dFunction (const std::string& title, const std::string& function)
480  : GnuplotDataset ( new Function2d (title, function) )
481 {
482 }
483 
484 void
485 Gnuplot2dFunction::SetFunction (const std::string& function)
486 {
487  reinterpret_cast<Function2d*>(m_data)->m_function = function;
488 }
489 
490 // --- Gnuplot3dDataset::Data3d -------------------------------------------- //
491 
498 {
499  // *** Data Variables ***
500 
501  std::string m_style;
502 
504 
509  Data3d(const std::string& title);
510 
511  virtual std::string GetCommand () const;
512  virtual void PrintExpression (std::ostream &os,
513  bool generateOneOutputFile,
514  unsigned int dataFileDatasetIndex,
515  std::string &dataFileName) const;
516  virtual void PrintDataFile (std::ostream &os, bool generateOneOutputFile) const;
517  virtual bool IsEmpty () const;
518 };
519 
520 Gnuplot3dDataset::Data3d::Data3d(const std::string& title)
521  : Data (title),
522  m_style (m_defaultStyle)
523 {
524 }
525 
526 std::string
528 {
529  return "splot";
530 }
531 
532 void
534  bool generateOneOutputFile,
535  unsigned int dataFileDatasetIndex,
536  std::string &dataFileName) const
537 {
538  os << "\"-\" ";
539 
540  if (m_style.size ())
541  os << " " << m_style;
542 
543  if (m_title.size ())
544  os << " title \"" << m_title << "\"";
545 
546  if (m_extra.size ())
547  os << " " << m_extra;
548 }
549 
550 void
551 Gnuplot3dDataset::Data3d::PrintDataFile (std::ostream &os, bool generateOneOutputFile) const
552 {
553  for (PointSet::const_iterator i = m_pointset.begin ();
554  i != m_pointset.end (); ++i)
555  {
556  if (i->empty) {
557  os << std::endl;
558  continue;
559  }
560 
561  os << i->x << " " << i->y << " " << i->z << std::endl;
562  }
563  os << "e" << std::endl;
564 }
565 
566 bool
568 {
569  return (m_pointset.size () == 0);
570 }
571 
572 // --- Gnuplot3dDataset ---------------------------------------------------- //
573 
574 std::string Gnuplot3dDataset::m_defaultStyle = "";
575 
576 Gnuplot3dDataset::Gnuplot3dDataset (const std::string& title)
577  : GnuplotDataset ( new Data3d (title) )
578 {
579 }
580 
581 void
582 Gnuplot3dDataset::SetDefaultStyle (const std::string& style)
583 {
584  m_defaultStyle = style;
585 }
586 void
587 Gnuplot3dDataset::SetStyle (const std::string& style)
588 {
589  reinterpret_cast<Data3d*>(m_data)->m_style = style;
590 }
591 
592 void
593 Gnuplot3dDataset::Add (double x, double y, double z)
594 {
595  struct Point data;
596  data.empty = false;
597  data.x = x;
598  data.y = y;
599  data.z = z;
600  reinterpret_cast<Data3d*>(m_data)->m_pointset.push_back (data);
601 }
602 
603 void
605 {
606  struct Point data;
607  data.empty = true;
608  reinterpret_cast<Data3d*>(m_data)->m_pointset.push_back (data);
609 }
610 
611 // --- Gnuplot3dFunction::Function3d --------------------------------------- //
612 
619 {
620  // *** Data Variables ***
621 
622  std::string m_function;
623 
630  Function3d(const std::string& title, const std::string& function);
631 
632  virtual std::string GetCommand () const;
633  virtual void PrintExpression (std::ostream &os,
634  bool generateOneOutputFile,
635  unsigned int dataFileDatasetIndex,
636  std::string &dataFileName) const;
637  virtual void PrintDataFile (std::ostream &os, bool generateOneOutputFile) const;
638  virtual bool IsEmpty () const;
639 };
640 
641 Gnuplot3dFunction::Function3d::Function3d(const std::string& title, const std::string& function)
642  : Data (title),
643  m_function (function)
644 {
645 }
646 
647 std::string
649 {
650  return "splot";
651 }
652 
653 void
655  bool generateOneOutputFile,
656  unsigned int dataFileDatasetIndex,
657  std::string &dataFileName) const
658 {
659  os << m_function;
660 
661  if (m_title.size ())
662  os << " title \"" << m_title << "\"";
663 
664  if (m_extra.size ())
665  os << " " << m_extra;
666 }
667 
668 void
669 Gnuplot3dFunction::Function3d::PrintDataFile (std::ostream &os, bool generateOneOutputFile) const
670 {
671 }
672 
673 bool
675 {
676  return false;
677 }
678 
679 // --- Gnuplot3dFunction --------------------------------------------------- //
680 
681 Gnuplot3dFunction::Gnuplot3dFunction (const std::string& title, const std::string& function)
682  : GnuplotDataset ( new Function3d (title, function) )
683 {
684 }
685 
686 void
687 Gnuplot3dFunction::SetFunction (const std::string& function)
688 {
689  reinterpret_cast<Function3d*>(m_data)->m_function = function;
690 }
691 
692 // ------------------------------------------------------------------------- //
693 
694 Gnuplot::Gnuplot (const std::string& outputFilename, const std::string& title)
695  : m_outputFilename (outputFilename),
696  m_terminal ( DetectTerminal (outputFilename) ),
697  m_title (title),
698  m_generateOneOutputFile (false),
699  m_dataFileDatasetIndex (0)
700 {
701 }
702 
703 void Gnuplot::SetOutputFilename (const std::string& outputFilename)
704 {
705  m_outputFilename = outputFilename;
706 }
707 
708 std::string Gnuplot::DetectTerminal (const std::string& filename)
709 {
710  std::string::size_type dotpos = filename.rfind ('.');
711  if (dotpos == std::string::npos) return "";
712 
713  if (filename.substr (dotpos) == ".png") {
714  return "png";
715  }
716  else if (filename.substr (dotpos) == ".pdf") {
717  return "pdf";
718  }
719 
720  return "";
721 }
722 
723 void
724 Gnuplot::SetTerminal (const std::string& terminal)
725 {
726  m_terminal = terminal;
727 }
728 
729 void
730 Gnuplot::SetTitle (const std::string& title)
731 {
732  m_title = title;
733 }
734 
735 void
736 Gnuplot::SetLegend (const std::string& xLegend, const std::string& yLegend)
737 {
738  m_xLegend = xLegend;
739  m_yLegend = yLegend;
740 }
741 
742 void
743 Gnuplot::SetExtra (const std::string& extra)
744 {
745  m_extra = extra;
746 }
747 
748 void
749 Gnuplot::AppendExtra (const std::string& extra)
750 {
751  m_extra += "\n";
752  m_extra += extra;
753 }
754 
755 void
757 {
758  m_datasets.push_back (dataset);
759 }
760 
761 void
762 Gnuplot::GenerateOutput (std::ostream &os)
763 {
764  // If this version of this function is called, it is assumed that a
765  // single output file is being generated.
767 
768  // Send the gnuplot metadata to the same stream as the data stream.
769  GenerateOutput (os, os, "");
770 }
771 
772 void
773 Gnuplot::GenerateOutput (std::ostream &osControl,
774  std::ostream &osData,
775  std::string dataFileName)
776 {
777  if (m_terminal.size ())
778  osControl << "set terminal " << m_terminal << std::endl;
779 
780  if (m_outputFilename.size ())
781  osControl << "set output \"" << m_outputFilename << "\"" << std::endl;
782 
783  if (m_title.size ())
784  osControl << "set title \"" << m_title << "\"" << std::endl;
785 
786  if (m_xLegend.size ())
787  osControl << "set xlabel \"" << m_xLegend << "\"" << std::endl;
788 
789  if (m_yLegend.size ())
790  osControl << "set ylabel \"" << m_yLegend << "\"" << std::endl;
791 
792  if (m_extra.size ())
793  osControl << m_extra << std::endl;
794 
795  if (m_datasets.empty ())
796  return;
797 
798  // Determine the GetCommand() values of all datasets included. Check that all
799  // are equal and print the command.
800 
801  std::string command = m_datasets.begin ()->m_data->GetCommand ();
802 
803  for (Datasets::const_iterator i = m_datasets.begin () + 1;
804  i != m_datasets.end (); ++i)
805  {
806  NS_ASSERT_MSG (command == i->m_data->GetCommand (),
807  "Cannot mix 'plot' and 'splot' GnuplotDatasets.");
808  }
809 
810  osControl << command << " ";
811 
812  // Print all dataset expressions
813 
814  bool isDataEmpty;
815  for (Datasets::const_iterator i = m_datasets.begin (); i != m_datasets.end ();)
816  {
817  // Only print the dataset if it's not empty.
818  isDataEmpty = i->m_data->IsEmpty ();
819  if (!isDataEmpty)
820  {
821  // Print the appropriate expression based on whether we are
822  // generating separate output and date files.
823  i->m_data->PrintExpression (osControl,
826  dataFileName);
827 
829  }
830 
831  i++;
832  if (i != m_datasets.end () && !isDataEmpty)
833  {
834  osControl << ", ";
835  }
836  }
837  osControl << std::endl;
838 
839  // followed by the inline datafile.
840 
841  for (Datasets::const_iterator i = m_datasets.begin (); i != m_datasets.end (); i++)
842  {
843  i->m_data->PrintDataFile (osData, m_generateOneOutputFile);
844  }
845 }
846 
847 void
849 {
850  m_dataFileDatasetIndex = index;
851 }
852 
853 // ------------------------------------------------------------------------- //
854 
855 GnuplotCollection::GnuplotCollection (const std::string& outputFilename)
856  : m_outputFilename (outputFilename),
857  m_terminal ( Gnuplot::DetectTerminal (outputFilename) )
858 {
859 }
860 
861 void
862 GnuplotCollection::SetTerminal (const std::string& terminal)
863 {
864  m_terminal = terminal;
865 }
866 
867 void
869 {
870  m_plots.push_back (plot);
871 }
872 
873 Gnuplot&
874 GnuplotCollection::GetPlot (unsigned int id)
875 {
876  if (id >= m_plots.size ())
877  throw(std::range_error ("Gnuplot id is out of range"));
878  else
879  return m_plots[id];
880 }
881 
882 void
884 {
885  // If this version of this function is called, it is assumed that a
886  // single output file is being generated.
887 
888  if (m_terminal.size ())
889  os << "set terminal " << m_terminal << std::endl;
890 
891  if (m_outputFilename.size ())
892  os << "set output \"" << m_outputFilename << "\"" << std::endl;
893 
894  for (Plots::iterator i = m_plots.begin (); i != m_plots.end (); ++i)
895  {
896  i->GenerateOutput (os);
897  }
898 }
899 
900 void
901 GnuplotCollection::GenerateOutput (std::ostream &osControl, std::ostream &osData,
902 std::string dataFileName)
903 {
904  // If this version of this function is called, it is assumed that
905  // separate output and date files are being generated.
906 
907  if (m_terminal.size ())
908  osControl << "set terminal " << m_terminal << std::endl;
909 
910  if (m_outputFilename.size ())
911  osControl << "set output \"" << m_outputFilename << "\"" << std::endl;
912 
913  for (Plots::iterator i = m_plots.begin (); i != m_plots.end (); ++i)
914  {
915  i->GenerateOutput (osControl, osData, dataFileName);
916  }
917 }
918 
919 // ------------------------------------------------------------------------- //
920 
921 } // namespace ns3
Structure storing the function to be used for a 3D plot.
Definition: gnuplot.cc:618
Plots m_plots
Plots in the collection.
Definition: gnuplot.h:541
void AppendExtra(const std::string &extra)
Definition: gnuplot.cc:749
A point in a 2D plot.
Definition: gnuplot.h:217
Function3d(const std::string &title, const std::string &function)
Initializes with the function and title.
Definition: gnuplot.cc:641
virtual std::string GetCommand() const
Returns the plot type ("plot" or "splot").
Definition: gnuplot.cc:527
virtual std::string GetCommand() const
Returns the plot type ("plot" or "splot").
Definition: gnuplot.cc:648
void SetTitle(const std::string &title)
Change line title.
Definition: gnuplot.cc:141
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
Abstract class to store a plot line to be used by ns3::Gnuplot.
Definition: gnuplot.h:38
Gnuplot(const std::string &outputFilename="", const std::string &title="")
Definition: gnuplot.cc:694
Gnuplot2dDataset(const std::string &title="Untitled")
Definition: gnuplot.cc:331
static void SetDefaultExtra(const std::string &extra)
Change extra formatting style parameters for newly created objects.
Definition: gnuplot.cc:147
void Add(double x, double y, double z)
Definition: gnuplot.cc:593
enum ErrorBars m_errorBars
Whether errorbars should be used for this dataset.
Definition: gnuplot.cc:169
unsigned int m_references
ref/unref counter for garbage collection
Definition: gnuplot.cc:40
std::string m_style
The plotting style to use for this dataset.
Definition: gnuplot.cc:501
#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
GnuplotDataset & operator=(const GnuplotDataset &original)
Reference-counting assignment operator.
Definition: gnuplot.cc:127
static std::string m_defaultExtra
Extra gnuplot parameters set on every newly created dataset.
Definition: gnuplot.h:91
void SetFunction(const std::string &function)
Definition: gnuplot.cc:485
void AddDataset(const GnuplotDataset &dataset)
Definition: gnuplot.cc:756
virtual bool IsEmpty() const =0
Checks to see if this GnuplotDataset is empty.
Data3d(const std::string &title)
Initializes with value from m_defaultStyle.
Definition: gnuplot.cc:520
std::vector< struct Point > PointSet
The set of points in the dataset.
Definition: gnuplot.h:322
void SetExtra(const std::string &extra)
Add extra formatting parameters to this dataset.
Definition: gnuplot.cc:152
void SetErrorBars(enum ErrorBars errorBars)
Definition: gnuplot.cc:353
~GnuplotDataset()
Reference-counting destructor.
Definition: gnuplot.cc:121
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
Print the inline data file contents trailing the plot command.
Definition: gnuplot.cc:551
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:533
std::string m_xLegend
X axis legend.
Definition: gnuplot.h:472
virtual bool IsEmpty() const
Checks to see if this GnuplotDataset is empty.
Definition: gnuplot.cc:674
std::string m_outputFilename
Output file name.
Definition: gnuplot.h:466
void SetOutputFilename(const std::string &outputFilename)
Definition: gnuplot.cc:703
struct Data * m_data
Reference counted data object.
Definition: gnuplot.h:107
Structure storing the data to for a 2D plot.
Definition: gnuplot.cc:164
Data2d(const std::string &title)
Initializes with the values from m_defaultStyle and m_defaultErrorBars.
Definition: gnuplot.cc:188
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
Definition: gnuplot.h:371
void SetTitle(const std::string &title)
Definition: gnuplot.cc:730
static std::string m_defaultStyle
default plot style
Definition: gnuplot.h:324
uint8_t data[writeSize]
void AddEmptyLine()
Add an empty line in the data output sequence.
Definition: gnuplot.cc:604
std::string m_title
Dataset title.
Definition: gnuplot.cc:42
Gnuplot3dDataset(const std::string &title="Untitled")
Definition: gnuplot.cc:576
Function2d(const std::string &title, const std::string &function)
Initializes with the function and title.
Definition: gnuplot.cc:439
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
Definition: gnuplot.cc:762
void Add(double x, double y)
Definition: gnuplot.cc:359
Gnuplot2dFunction(const std::string &title="Untitled", const std::string &function="")
Definition: gnuplot.cc:479
virtual void PrintDataFile(std::ostream &os, bool generateOneOutputFile) const
Print the inline data file contents trailing the plot command.
Definition: gnuplot.cc:281
std::string m_extra
Extra parameters for the plot.
Definition: gnuplot.cc:43
Gnuplot3dFunction(const std::string &title="Untitled", const std::string &function="")
Definition: gnuplot.cc:681
void AddPlot(const Gnuplot &plot)
Definition: gnuplot.cc:868
A point in a 3D plot.
Definition: gnuplot.h:314
void SetLegend(const std::string &xLegend, const std::string &yLegend)
Definition: gnuplot.cc:736
virtual bool IsEmpty() const
Checks to see if this GnuplotDataset is empty.
Definition: gnuplot.cc:567
static void SetDefaultErrorBars(enum ErrorBars errorBars)
Change default errorbars style for all newly created objects.
Definition: gnuplot.cc:348
virtual std::string GetCommand() const =0
Returns the plot type ("plot" or "splot").
GnuplotCollection(const std::string &outputFilename)
Definition: gnuplot.cc:855
void GenerateOutput(std::ostream &os)
Definition: gnuplot.cc:883
static void SetDefaultStyle(enum Style style)
Change default style for all newly created objects.
Definition: gnuplot.cc:337
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Style
The plotting style to use for this dataset.
Definition: gnuplot.h:123
ErrorBars
Whether errorbars should be used for this dataset.
Definition: gnuplot.h:137
Structure storing the data to plot.
Definition: gnuplot.cc:36
Datasets m_datasets
Data sets.
Definition: gnuplot.h:469
std::vector< struct Point > PointSet
The set of points in the dataset.
Definition: gnuplot.h:226
virtual void PrintDataFile(std::ostream &os, bool generateOneOutputFile) const =0
Print the inline data file contents trailing the plot command.
void SetStyle(enum Style style)
Definition: gnuplot.cc:342
void SetExtra(const std::string &extra)
Definition: gnuplot.cc:743
virtual bool IsEmpty() const
Checks to see if this GnuplotDataset is empty.
Definition: gnuplot.cc:472
void SetStyle(const std::string &style)
Definition: gnuplot.cc:587
virtual std::string GetCommand() const
Returns the plot type ("plot" or "splot").
Definition: gnuplot.cc:196
PointSet m_pointset
The set of points in this data set.
Definition: gnuplot.cc:503
std::string m_outputFilename
Output file name.
Definition: gnuplot.h:538
std::string m_extra
extra parameters for the plot
Definition: gnuplot.h:474
void SetTerminal(const std::string &terminal)
Definition: gnuplot.cc:862
unsigned int m_dataFileDatasetIndex
Data set index to plot.
Definition: gnuplot.h:478
std::string m_terminal
Gnuplot "terminal" to use.
Definition: gnuplot.h:539
void SetFunction(const std::string &function)
Definition: gnuplot.cc:687
std::string m_title
Plot title.
Definition: gnuplot.h:471
GnuplotDataset(const GnuplotDataset &original)
Reference-counting copy constructor.
Definition: gnuplot.cc:115
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
bool m_generateOneOutputFile
true if only one plot will be generated
Definition: gnuplot.h:476
Structure storing the data for a 3D plot.
Definition: gnuplot.cc:497
std::string m_function
Function to use.
Definition: gnuplot.cc:622
static void SetDefaultStyle(const std::string &style)
Change default style for all newly created objects.
Definition: gnuplot.cc:582
virtual std::string GetCommand() const
Returns the plot type ("plot" or "splot").
Definition: gnuplot.cc:446
static std::string DetectTerminal(const std::string &filename)
Crude attempt to auto-detect the correct terminal setting by inspecting the filename&#39;s extension...
Definition: gnuplot.cc:708
std::string m_function
Function to use.
Definition: gnuplot.cc:420
std::string m_yLegend
Y axis legend.
Definition: gnuplot.h:473
PointSet m_pointset
The set of points in this data set.
Definition: gnuplot.cc:171
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:452
void AddEmptyLine()
Add an empty line in the data output sequence.
Definition: gnuplot.cc:402
static enum Style m_defaultStyle
default plot style
Definition: gnuplot.h:228
void SetDataFileDatasetIndex(unsigned int index)
Sets the current data stream index in the data file.
Definition: gnuplot.cc:848
std::string m_terminal
Gnuplot "terminal" to use.
Definition: gnuplot.h:467
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:654
virtual void PrintDataFile(std::ostream &os, bool generateOneOutputFile) const
Print the inline data file contents trailing the plot command.
Definition: gnuplot.cc:669
void SetTerminal(const std::string &terminal)
Definition: gnuplot.cc:724
Structure storing the function to be used for a 2D plot.
Definition: gnuplot.cc:416
Data(const std::string &title)
Initializes the reference counter to 1 and sets m_title and m_extra.
Definition: gnuplot.cc:95
virtual ~Data()
Required.
Definition: gnuplot.cc:102
enum Style m_style
The plotting style to use for this dataset.
Definition: gnuplot.cc:168
virtual void PrintDataFile(std::ostream &os, bool generateOneOutputFile) const
Print the inline data file contents trailing the plot command.
Definition: gnuplot.cc:467
Gnuplot & GetPlot(unsigned int id)
Return a pointer to one of the added plots.
Definition: gnuplot.cc:874
static enum ErrorBars m_defaultErrorBars
default error bars type
Definition: gnuplot.h:229
virtual bool IsEmpty() const
Checks to see if this GnuplotDataset is empty.
Definition: gnuplot.cc:321