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