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