A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
gnuplot.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007 INRIA, 2008 Timo Bingmann
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Original Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 * Enhancements: Timo Bingmann <timo.bingmann@student.kit.edu>
8 */
9#include "gnuplot.h"
10
11#include "ns3/assert.h"
12
13#include <ostream>
14#include <stdexcept>
15
16namespace ns3
17{
18
19// --- GnuplotDataset::Data ------------------------------------------------ //
20
21/**
22 * \ingroup gnuplot
23 *
24 * Structure storing the data to plot.
25 * Derived classes subclass this struct and add their own data fields.
26 */
28{
29 // *** Data Variables ***
30
31 unsigned int m_references; //!< ref/unref counter for garbage collection
32
33 std::string m_title; //!< Dataset title
34 std::string m_extra; //!< Extra parameters for the plot
35
36 /**
37 * Initializes the reference counter to 1 and sets m_title and m_extra.
38 * \param title Dataset title
39 */
40 Data(const std::string& title);
41
42 /// Required.
43 virtual ~Data();
44
45 /**
46 * \brief Returns the plot type ("plot" or "splot").
47 * \returns the plot type ("plot" or "splot").
48 */
49 virtual std::string GetCommand() const = 0;
50
51 /**
52 * Prints the plot description used as argument to (s)plot. Either
53 * the function expression or a datafile description. Should include
54 * m_title and m_extra in the output.
55 *
56 * If more than one output file is being generated, i.e. separate
57 * data and control files, then the index for the current dataset
58 * and the name for the data file are also included.
59 *
60 * \param os Output stream
61 * \param generateOneOutputFile If true, generate only one output file.
62 * \param dataFileDatasetIndex Dataset Index
63 * \param dataFileName Dataset file name
64 */
65 virtual void PrintExpression(std::ostream& os,
66 bool generateOneOutputFile,
67 unsigned int dataFileDatasetIndex,
68 std::string& dataFileName) const = 0;
69
70 /**
71 * Print the inline data file contents trailing the plot command. Empty for
72 * functions.
73 *
74 * \param os Output stream
75 * \param generateOneOutputFile If true, generate only one output file.
76 */
77 virtual void PrintDataFile(std::ostream& os, bool generateOneOutputFile) const = 0;
78
79 /**
80 * Checks to see if this GnuplotDataset is empty.
81 * \return indicates if this GnuplotDataset is empty.
82 */
83 virtual bool IsEmpty() const = 0;
84};
85
86GnuplotDataset::Data::Data(const std::string& title)
87 : m_references(1),
88 m_title(title),
89 m_extra(m_defaultExtra)
90{
91}
92
96
97// --- GnuplotDataset ------------------------------------------------------ //
98
99std::string GnuplotDataset::m_defaultExtra = "";
100
105
107 : m_data(original.m_data)
108{
110}
111
113{
114 if (--m_data->m_references == 0)
115 {
116 delete m_data;
117 }
118}
119
122{
123 if (this != &original)
124 {
125 if (--m_data->m_references == 0)
126 {
127 delete m_data;
128 }
129
130 m_data = original.m_data;
132 }
133 return *this;
134}
135
136void
137GnuplotDataset::SetTitle(const std::string& title)
138{
139 m_data->m_title = title;
140}
141
142void
143GnuplotDataset::SetDefaultExtra(const std::string& extra)
144{
145 m_defaultExtra = extra;
146}
147
148void
149GnuplotDataset::SetExtra(const std::string& extra)
150{
151 m_data->m_extra = extra;
152}
153
154// --- Gnuplot2dDataset::Data2d -------------------------------------------- //
155
156/**
157 * \ingroup gnuplot
158 *
159 * Structure storing the data to for a 2D plot.
160 */
162{
163 // *** Data Variables ***
164
165 Style m_style; //!< The plotting style to use for this dataset.
166 ErrorBars m_errorBars; //!< Whether errorbars should be used for this dataset.
167
168 PointSet m_pointset; //!< The set of points in this data set
169
170 /**
171 * Initializes with the values from m_defaultStyle and m_defaultErrorBars.
172 * \param title Dataset title
173 */
174 Data2d(const std::string& title);
175
176 std::string GetCommand() const override;
177 void PrintExpression(std::ostream& os,
178 bool generateOneOutputFile,
179 unsigned int dataFileDatasetIndex,
180 std::string& dataFileName) const override;
181 void PrintDataFile(std::ostream& os, bool generateOneOutputFile) const override;
182 bool IsEmpty() const override;
183};
184
185Gnuplot2dDataset::Data2d::Data2d(const std::string& title)
186 : Data(title),
187 m_style(m_defaultStyle),
188 m_errorBars(m_defaultErrorBars)
189{
190}
191
192std::string
194{
195 return "plot";
196}
197
198void
200 bool generateOneOutputFile,
201 unsigned int dataFileDatasetIndex,
202 std::string& dataFileName) const
203{
204 // Print the appropriate thing based on whether separate output and
205 // date files are being generated.
206 if (generateOneOutputFile)
207 {
208 os << "\"-\" ";
209 }
210 else
211 {
212 os << "\"" << dataFileName << "\" index " << dataFileDatasetIndex;
213 }
214
215 if (!m_title.empty())
216 {
217 os << " title \"" << m_title << "\"";
218 }
219
220 switch (m_style)
221 {
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.empty())
277 {
278 os << " " << m_extra;
279 }
280}
281
282void
283Gnuplot2dDataset::Data2d::PrintDataFile(std::ostream& os, bool generateOneOutputFile) const
284{
285 for (auto i = m_pointset.begin(); i != m_pointset.end(); ++i)
286 {
287 if (i->empty)
288 {
289 os << std::endl;
290 continue;
291 }
292
293 switch (m_errorBars)
294 {
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
323bool
325{
326 return m_pointset.empty();
327}
328
329// --- Gnuplot2dDataset ---------------------------------------------------- //
330
331/// Default plot style static instance
333/// Default error bars type static instance
335
336Gnuplot2dDataset::Gnuplot2dDataset(const std::string& title)
337 : GnuplotDataset(new Data2d(title))
338{
339}
340
341void
346
347void
349{
350 reinterpret_cast<Data2d*>(m_data)->m_style = style;
351}
352
353void
358
359void
361{
362 reinterpret_cast<Data2d*>(m_data)->m_errorBars = errorBars;
363}
364
365void
366Gnuplot2dDataset::Add(double x, double y)
367{
368 NS_ASSERT(reinterpret_cast<Data2d*>(m_data)->m_errorBars == NONE);
369
370 Point data;
371 data.empty = false;
372 data.x = x;
373 data.y = y;
374 data.dx = 0.0;
375 data.dy = 0.0;
376 reinterpret_cast<Data2d*>(m_data)->m_pointset.push_back(data);
377}
378
379void
380Gnuplot2dDataset::Add(double x, double y, double errorDelta)
381{
382 NS_ASSERT(reinterpret_cast<Data2d*>(m_data)->m_errorBars == X ||
383 reinterpret_cast<Data2d*>(m_data)->m_errorBars == Y);
384
385 Point data;
386 data.empty = false;
387 data.x = x;
388 data.y = y;
389 data.dx = errorDelta;
390 data.dy = errorDelta;
391 reinterpret_cast<Data2d*>(m_data)->m_pointset.push_back(data);
392}
393
394void
395Gnuplot2dDataset::Add(double x, double y, double xErrorDelta, double yErrorDelta)
396{
397 NS_ASSERT(reinterpret_cast<Data2d*>(m_data)->m_errorBars == XY);
398
399 Point data;
400 data.empty = false;
401 data.x = x;
402 data.y = y;
403 data.dx = xErrorDelta;
404 data.dy = yErrorDelta;
405 reinterpret_cast<Data2d*>(m_data)->m_pointset.push_back(data);
406}
407
408void
410{
411 Point data;
412 data.empty = true;
413 reinterpret_cast<Data2d*>(m_data)->m_pointset.push_back(data);
414}
415
416// --- Gnuplot2dFunction::Function2d --------------------------------------- //
417
418/**
419 * \ingroup gnuplot
420 *
421 * Structure storing the function to be used for a 2D plot.
422 */
424{
425 // *** Data Variables ***
426
427 std::string m_function; //!< Function to use
428
429 /**
430 * Initializes with the function and title.
431 *
432 * \param title Title of the plot
433 * \param function Function to plot
434 */
435 Function2d(const std::string& title, const std::string& function);
436
437 std::string GetCommand() const override;
438 void PrintExpression(std::ostream& os,
439 bool generateOneOutputFile,
440 unsigned int dataFileDatasetIndex,
441 std::string& dataFileName) const override;
442 void PrintDataFile(std::ostream& os, bool generateOneOutputFile) const override;
443 bool IsEmpty() const override;
444};
445
446Gnuplot2dFunction::Function2d::Function2d(const std::string& title, const std::string& function)
447 : Data(title),
448 m_function(function)
449{
450}
451
452std::string
454{
455 return "plot";
456}
457
458void
460 bool generateOneOutputFile,
461 unsigned int dataFileDatasetIndex,
462 std::string& dataFileName) const
463{
464 os << m_function;
465
466 if (!m_title.empty())
467 {
468 os << " title \"" << m_title << "\"";
469 }
470
471 if (!m_extra.empty())
472 {
473 os << " " << m_extra;
474 }
475}
476
477void
478Gnuplot2dFunction::Function2d::PrintDataFile(std::ostream& os, bool generateOneOutputFile) const
479{
480}
481
482bool
484{
485 return false;
486}
487
488// --- Gnuplot2dFunction --------------------------------------------------- //
489
490Gnuplot2dFunction::Gnuplot2dFunction(const std::string& title, const std::string& function)
491 : GnuplotDataset(new Function2d(title, function))
492{
493}
494
495void
496Gnuplot2dFunction::SetFunction(const std::string& function)
497{
498 reinterpret_cast<Function2d*>(m_data)->m_function = function;
499}
500
501// --- Gnuplot3dDataset::Data3d -------------------------------------------- //
502
503/**
504 * \ingroup gnuplot
505 *
506 * Structure storing the data for a 3D plot.
507 */
509{
510 // *** Data Variables ***
511
512 std::string m_style; //!< The plotting style to use for this dataset.
513
514 PointSet m_pointset; //!< The set of points in this data set
515
516 /**
517 * Initializes with value from m_defaultStyle.
518 * \param title Dataset title
519 */
520 Data3d(const std::string& title);
521
522 std::string GetCommand() const override;
523 void PrintExpression(std::ostream& os,
524 bool generateOneOutputFile,
525 unsigned int dataFileDatasetIndex,
526 std::string& dataFileName) const override;
527 void PrintDataFile(std::ostream& os, bool generateOneOutputFile) const override;
528 bool IsEmpty() const override;
529};
530
531Gnuplot3dDataset::Data3d::Data3d(const std::string& title)
532 : Data(title),
533 m_style(m_defaultStyle)
534{
535}
536
537std::string
539{
540 return "splot";
541}
542
543void
545 bool generateOneOutputFile,
546 unsigned int dataFileDatasetIndex,
547 std::string& dataFileName) const
548{
549 os << "\"-\" ";
550
551 if (!m_style.empty())
552 {
553 os << " " << m_style;
554 }
555
556 if (!m_title.empty())
557 {
558 os << " title \"" << m_title << "\"";
559 }
560
561 if (!m_extra.empty())
562 {
563 os << " " << m_extra;
564 }
565}
566
567void
568Gnuplot3dDataset::Data3d::PrintDataFile(std::ostream& os, bool generateOneOutputFile) const
569{
570 for (auto i = m_pointset.begin(); i != m_pointset.end(); ++i)
571 {
572 if (i->empty)
573 {
574 os << std::endl;
575 continue;
576 }
577
578 os << i->x << " " << i->y << " " << i->z << std::endl;
579 }
580 os << "e" << std::endl;
581}
582
583bool
585{
586 return m_pointset.empty();
587}
588
589// --- Gnuplot3dDataset ---------------------------------------------------- //
590
591std::string Gnuplot3dDataset::m_defaultStyle = "";
592
593Gnuplot3dDataset::Gnuplot3dDataset(const std::string& title)
594 : GnuplotDataset(new Data3d(title))
595{
596}
597
598void
599Gnuplot3dDataset::SetDefaultStyle(const std::string& style)
600{
601 m_defaultStyle = style;
602}
603
604void
605Gnuplot3dDataset::SetStyle(const std::string& style)
606{
607 reinterpret_cast<Data3d*>(m_data)->m_style = style;
608}
609
610void
611Gnuplot3dDataset::Add(double x, double y, double z)
612{
613 Point data;
614 data.empty = false;
615 data.x = x;
616 data.y = y;
617 data.z = z;
618 reinterpret_cast<Data3d*>(m_data)->m_pointset.push_back(data);
619}
620
621void
623{
624 Point data;
625 data.empty = true;
626 reinterpret_cast<Data3d*>(m_data)->m_pointset.push_back(data);
627}
628
629// --- Gnuplot3dFunction::Function3d --------------------------------------- //
630
631/**
632 * \ingroup gnuplot
633 *
634 * Structure storing the function to be used for a 3D plot.
635 */
637{
638 // *** Data Variables ***
639
640 std::string m_function; //!< Function to use
641
642 /**
643 * Initializes with the function and title.
644 *
645 * \param title Title of the plot
646 * \param function Function to plot
647 */
648 Function3d(const std::string& title, const std::string& function);
649
650 std::string GetCommand() const override;
651 void PrintExpression(std::ostream& os,
652 bool generateOneOutputFile,
653 unsigned int dataFileDatasetIndex,
654 std::string& dataFileName) const override;
655 void PrintDataFile(std::ostream& os, bool generateOneOutputFile) const override;
656 bool IsEmpty() const override;
657};
658
659Gnuplot3dFunction::Function3d::Function3d(const std::string& title, const std::string& function)
660 : Data(title),
661 m_function(function)
662{
663}
664
665std::string
667{
668 return "splot";
669}
670
671void
673 bool generateOneOutputFile,
674 unsigned int dataFileDatasetIndex,
675 std::string& dataFileName) const
676{
677 os << m_function;
678
679 if (!m_title.empty())
680 {
681 os << " title \"" << m_title << "\"";
682 }
683
684 if (!m_extra.empty())
685 {
686 os << " " << m_extra;
687 }
688}
689
690void
691Gnuplot3dFunction::Function3d::PrintDataFile(std::ostream& os, bool generateOneOutputFile) const
692{
693}
694
695bool
697{
698 return false;
699}
700
701// --- Gnuplot3dFunction --------------------------------------------------- //
702
703Gnuplot3dFunction::Gnuplot3dFunction(const std::string& title, const std::string& function)
704 : GnuplotDataset(new Function3d(title, function))
705{
706}
707
708void
709Gnuplot3dFunction::SetFunction(const std::string& function)
710{
711 reinterpret_cast<Function3d*>(m_data)->m_function = function;
712}
713
714// ------------------------------------------------------------------------- //
715
716Gnuplot::Gnuplot(const std::string& outputFilename, const std::string& title)
717 : m_outputFilename(outputFilename),
718 m_terminal(DetectTerminal(outputFilename)),
719 m_title(title),
720 m_generateOneOutputFile(false),
721 m_dataFileDatasetIndex(0)
722{
723}
724
725void
726Gnuplot::SetOutputFilename(const std::string& outputFilename)
727{
728 m_outputFilename = outputFilename;
729}
730
731std::string
732Gnuplot::DetectTerminal(const std::string& filename)
733{
734 std::string::size_type dotpos = filename.rfind('.');
735 if (dotpos == std::string::npos)
736 {
737 return "";
738 }
739
740 if (filename.substr(dotpos) == ".png")
741 {
742 return "png";
743 }
744 else if (filename.substr(dotpos) == ".pdf")
745 {
746 return "pdf";
747 }
748
749 return "";
750}
751
752void
753Gnuplot::SetTerminal(const std::string& terminal)
754{
755 m_terminal = terminal;
756}
757
758void
759Gnuplot::SetTitle(const std::string& title)
760{
761 m_title = title;
762}
763
764void
765Gnuplot::SetLegend(const std::string& xLegend, const std::string& yLegend)
766{
767 m_xLegend = xLegend;
768 m_yLegend = yLegend;
769}
770
771void
772Gnuplot::SetExtra(const std::string& extra)
773{
774 m_extra = extra;
775}
776
777void
778Gnuplot::AppendExtra(const std::string& extra)
779{
780 m_extra += "\n";
781 m_extra += extra;
782}
783
784void
786{
787 m_datasets.push_back(dataset);
788}
789
790void
791Gnuplot::GenerateOutput(std::ostream& os)
792{
793 // If this version of this function is called, it is assumed that a
794 // single output file is being generated.
796
797 // Send the gnuplot metadata to the same stream as the data stream.
798 GenerateOutput(os, os, "");
799}
800
801void
802Gnuplot::GenerateOutput(std::ostream& osControl, std::ostream& osData, std::string dataFileName)
803{
804 if (!m_terminal.empty())
805 {
806 osControl << "set terminal " << m_terminal << std::endl;
807 }
808
809 if (!m_outputFilename.empty())
810 {
811 osControl << "set output \"" << m_outputFilename << "\"" << std::endl;
812 }
813
814 if (!m_title.empty())
815 {
816 osControl << "set title \"" << m_title << "\"" << std::endl;
817 }
818
819 if (!m_xLegend.empty())
820 {
821 osControl << "set xlabel \"" << m_xLegend << "\"" << std::endl;
822 }
823
824 if (!m_yLegend.empty())
825 {
826 osControl << "set ylabel \"" << m_yLegend << "\"" << std::endl;
827 }
828
829 if (!m_extra.empty())
830 {
831 osControl << m_extra << std::endl;
832 }
833
834 if (m_datasets.empty())
835 {
836 return;
837 }
838
839 // Determine the GetCommand() values of all datasets included. Check that all
840 // are equal and print the command.
841
842 std::string command = m_datasets.begin()->m_data->GetCommand();
843
844 for (auto i = m_datasets.begin() + 1; i != m_datasets.end(); ++i)
845 {
846 NS_ASSERT_MSG(command == i->m_data->GetCommand(),
847 "Cannot mix 'plot' and 'splot' GnuplotDatasets.");
848 }
849
850 osControl << command << " ";
851
852 // Print all dataset expressions
853
854 bool isDataEmpty;
855 for (auto i = m_datasets.begin(); i != m_datasets.end();)
856 {
857 // Only print the dataset if it's not empty.
858 isDataEmpty = i->m_data->IsEmpty();
859 if (!isDataEmpty)
860 {
861 // Print the appropriate expression based on whether we are
862 // generating separate output and date files.
863 i->m_data->PrintExpression(osControl,
866 dataFileName);
867
869 }
870
871 i++;
872 if (i != m_datasets.end() && !isDataEmpty)
873 {
874 osControl << ", ";
875 }
876 }
877 osControl << std::endl;
878
879 // followed by the inline datafile.
880
881 for (auto i = m_datasets.begin(); i != m_datasets.end(); i++)
882 {
883 i->m_data->PrintDataFile(osData, m_generateOneOutputFile);
884 }
885}
886
887void
889{
891}
892
893// ------------------------------------------------------------------------- //
894
895GnuplotCollection::GnuplotCollection(const std::string& outputFilename)
896 : m_outputFilename(outputFilename),
897 m_terminal(Gnuplot::DetectTerminal(outputFilename))
898{
899}
900
901void
902GnuplotCollection::SetTerminal(const std::string& terminal)
903{
904 m_terminal = terminal;
905}
906
907void
909{
910 m_plots.push_back(plot);
911}
912
913Gnuplot&
915{
916 if (id >= m_plots.size())
917 {
918 throw(std::range_error("Gnuplot id is out of range"));
919 }
920 else
921 {
922 return m_plots[id];
923 }
924}
925
926void
928{
929 // If this version of this function is called, it is assumed that a
930 // single output file is being generated.
931
932 if (!m_terminal.empty())
933 {
934 os << "set terminal " << m_terminal << std::endl;
935 }
936
937 if (!m_outputFilename.empty())
938 {
939 os << "set output \"" << m_outputFilename << "\"" << std::endl;
940 }
941
942 for (auto i = m_plots.begin(); i != m_plots.end(); ++i)
943 {
944 i->GenerateOutput(os);
945 }
946}
947
948void
949GnuplotCollection::GenerateOutput(std::ostream& osControl,
950 std::ostream& osData,
951 std::string dataFileName)
952{
953 // If this version of this function is called, it is assumed that
954 // separate output and date files are being generated.
955
956 if (!m_terminal.empty())
957 {
958 osControl << "set terminal " << m_terminal << std::endl;
959 }
960
961 if (!m_outputFilename.empty())
962 {
963 osControl << "set output \"" << m_outputFilename << "\"" << std::endl;
964 }
965
966 for (auto i = m_plots.begin(); i != m_plots.end(); ++i)
967 {
968 i->GenerateOutput(osControl, osData, dataFileName);
969 }
970}
971
972// ------------------------------------------------------------------------- //
973
974} // namespace ns3
void AddEmptyLine()
Add an empty line in the data output sequence.
Definition gnuplot.cc:409
static Style m_defaultStyle
default plot style
Definition gnuplot.h:217
static void SetDefaultStyle(Style style)
Change default style for all newly created objects.
Definition gnuplot.cc:342
ErrorBars
Whether errorbars should be used for this dataset.
Definition gnuplot.h:126
static void SetDefaultErrorBars(ErrorBars errorBars)
Change default errorbars style for all newly created objects.
Definition gnuplot.cc:354
void SetErrorBars(ErrorBars errorBars)
Definition gnuplot.cc:360
std::vector< Point > PointSet
The set of points in the dataset.
Definition gnuplot.h:215
void SetStyle(Style style)
Definition gnuplot.cc:348
void Add(double x, double y)
Definition gnuplot.cc:366
Style
The plotting style to use for this dataset.
Definition gnuplot.h:111
static ErrorBars m_defaultErrorBars
default error bars type
Definition gnuplot.h:218
Gnuplot2dDataset(const std::string &title="Untitled")
Definition gnuplot.cc:336
void SetFunction(const std::string &function)
Definition gnuplot.cc:496
Gnuplot2dFunction(const std::string &title="Untitled", const std::string &function="")
Definition gnuplot.cc:490
void AddEmptyLine()
Add an empty line in the data output sequence.
Definition gnuplot.cc:622
Gnuplot3dDataset(const std::string &title="Untitled")
Definition gnuplot.cc:593
std::vector< Point > PointSet
The set of points in the dataset.
Definition gnuplot.h:310
static std::string m_defaultStyle
default plot style
Definition gnuplot.h:312
void Add(double x, double y, double z)
Definition gnuplot.cc:611
static void SetDefaultStyle(const std::string &style)
Change default style for all newly created objects.
Definition gnuplot.cc:599
void SetStyle(const std::string &style)
Definition gnuplot.cc:605
Gnuplot3dFunction(const std::string &title="Untitled", const std::string &function="")
Definition gnuplot.cc:703
void SetFunction(const std::string &function)
Definition gnuplot.cc:709
std::string m_outputFilename
Output file name.
Definition gnuplot.h:521
GnuplotCollection(const std::string &outputFilename)
Definition gnuplot.cc:895
void AddPlot(const Gnuplot &plot)
Definition gnuplot.cc:908
void SetTerminal(const std::string &terminal)
Definition gnuplot.cc:902
Gnuplot & GetPlot(unsigned int id)
Return a pointer to one of the added plots.
Definition gnuplot.cc:914
std::string m_terminal
Gnuplot "terminal" to use.
Definition gnuplot.h:522
Plots m_plots
Plots in the collection.
Definition gnuplot.h:524
void GenerateOutput(std::ostream &os)
Definition gnuplot.cc:927
Abstract class to store a plot line to be used by ns3::Gnuplot.
Definition gnuplot.h:28
GnuplotDataset(const GnuplotDataset &original)
Reference-counting copy constructor.
Definition gnuplot.cc:106
static void SetDefaultExtra(const std::string &extra)
Change extra formatting style parameters for newly created objects.
Definition gnuplot.cc:143
GnuplotDataset & operator=(const GnuplotDataset &original)
Reference-counting assignment operator.
Definition gnuplot.cc:121
void SetExtra(const std::string &extra)
Add extra formatting parameters to this dataset.
Definition gnuplot.cc:149
Data * m_data
Reference counted data object.
Definition gnuplot.h:94
static std::string m_defaultExtra
Extra gnuplot parameters set on every newly created dataset.
Definition gnuplot.h:78
void SetTitle(const std::string &title)
Change line title.
Definition gnuplot.cc:137
~GnuplotDataset()
Reference-counting destructor.
Definition gnuplot.cc:112
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
Definition gnuplot.h:359
std::string m_yLegend
Y axis legend.
Definition gnuplot.h:458
void AddDataset(const GnuplotDataset &dataset)
Definition gnuplot.cc:785
void SetLegend(const std::string &xLegend, const std::string &yLegend)
Definition gnuplot.cc:765
void SetTerminal(const std::string &terminal)
Definition gnuplot.cc:753
std::string m_terminal
Gnuplot "terminal" to use.
Definition gnuplot.h:452
std::string m_extra
extra parameters for the plot
Definition gnuplot.h:459
unsigned int m_dataFileDatasetIndex
Data set index to plot.
Definition gnuplot.h:463
void AppendExtra(const std::string &extra)
Definition gnuplot.cc:778
Datasets m_datasets
Data sets.
Definition gnuplot.h:454
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
Definition gnuplot.cc:791
std::string m_title
Plot title.
Definition gnuplot.h:456
void SetDataFileDatasetIndex(unsigned int index)
Sets the current data stream index in the data file.
Definition gnuplot.cc:888
std::string m_xLegend
X axis legend.
Definition gnuplot.h:457
std::string m_outputFilename
Output file name.
Definition gnuplot.h:451
Gnuplot(const std::string &outputFilename="", const std::string &title="")
Definition gnuplot.cc:716
void SetExtra(const std::string &extra)
Definition gnuplot.cc:772
void SetTitle(const std::string &title)
Definition gnuplot.cc:759
void SetOutputFilename(const std::string &outputFilename)
Definition gnuplot.cc:726
bool m_generateOneOutputFile
true if only one plot will be generated
Definition gnuplot.h:461
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:732
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#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:75
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:162
Style m_style
The plotting style to use for this dataset.
Definition gnuplot.cc:165
void PrintDataFile(std::ostream &os, bool generateOneOutputFile) const override
Print the inline data file contents trailing the plot command.
Definition gnuplot.cc:283
void PrintExpression(std::ostream &os, bool generateOneOutputFile, unsigned int dataFileDatasetIndex, std::string &dataFileName) const override
Prints the plot description used as argument to (s)plot.
Definition gnuplot.cc:199
PointSet m_pointset
The set of points in this data set.
Definition gnuplot.cc:168
bool IsEmpty() const override
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:185
std::string GetCommand() const override
Returns the plot type ("plot" or "splot").
Definition gnuplot.cc:193
ErrorBars m_errorBars
Whether errorbars should be used for this dataset.
Definition gnuplot.cc:166
A point in a 2D plot.
Definition gnuplot.h:206
Structure storing the function to be used for a 2D plot.
Definition gnuplot.cc:424
std::string GetCommand() const override
Returns the plot type ("plot" or "splot").
Definition gnuplot.cc:453
void PrintDataFile(std::ostream &os, bool generateOneOutputFile) const override
Print the inline data file contents trailing the plot command.
Definition gnuplot.cc:478
Function2d(const std::string &title, const std::string &function)
Initializes with the function and title.
Definition gnuplot.cc:446
void PrintExpression(std::ostream &os, bool generateOneOutputFile, unsigned int dataFileDatasetIndex, std::string &dataFileName) const override
Prints the plot description used as argument to (s)plot.
Definition gnuplot.cc:459
std::string m_function
Function to use.
Definition gnuplot.cc:427
bool IsEmpty() const override
Checks to see if this GnuplotDataset is empty.
Definition gnuplot.cc:483
Structure storing the data for a 3D plot.
Definition gnuplot.cc:509
std::string GetCommand() const override
Returns the plot type ("plot" or "splot").
Definition gnuplot.cc:538
bool IsEmpty() const override
Checks to see if this GnuplotDataset is empty.
Definition gnuplot.cc:584
void PrintExpression(std::ostream &os, bool generateOneOutputFile, unsigned int dataFileDatasetIndex, std::string &dataFileName) const override
Prints the plot description used as argument to (s)plot.
Definition gnuplot.cc:544
void PrintDataFile(std::ostream &os, bool generateOneOutputFile) const override
Print the inline data file contents trailing the plot command.
Definition gnuplot.cc:568
std::string m_style
The plotting style to use for this dataset.
Definition gnuplot.cc:512
PointSet m_pointset
The set of points in this data set.
Definition gnuplot.cc:514
Data3d(const std::string &title)
Initializes with value from m_defaultStyle.
Definition gnuplot.cc:531
A point in a 3D plot.
Definition gnuplot.h:302
Structure storing the function to be used for a 3D plot.
Definition gnuplot.cc:637
bool IsEmpty() const override
Checks to see if this GnuplotDataset is empty.
Definition gnuplot.cc:696
std::string m_function
Function to use.
Definition gnuplot.cc:640
void PrintExpression(std::ostream &os, bool generateOneOutputFile, unsigned int dataFileDatasetIndex, std::string &dataFileName) const override
Prints the plot description used as argument to (s)plot.
Definition gnuplot.cc:672
Function3d(const std::string &title, const std::string &function)
Initializes with the function and title.
Definition gnuplot.cc:659
void PrintDataFile(std::ostream &os, bool generateOneOutputFile) const override
Print the inline data file contents trailing the plot command.
Definition gnuplot.cc:691
std::string GetCommand() const override
Returns the plot type ("plot" or "splot").
Definition gnuplot.cc:666
Structure storing the data to plot.
Definition gnuplot.cc:28
unsigned int m_references
ref/unref counter for garbage collection
Definition gnuplot.cc:31
std::string m_extra
Extra parameters for the plot.
Definition gnuplot.cc:34
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:93
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:86
std::string m_title
Dataset title.
Definition gnuplot.cc:33
virtual std::string GetCommand() const =0
Returns the plot type ("plot" or "splot").