A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
gnuplot-aggregator-example.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013 University of Washington
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 * Author: Mitch Watrous (watrous@u.washington.edu)
18 */
19
20#include "ns3/core-module.h"
21#include "ns3/stats-module.h"
22
23using namespace ns3;
24
25namespace
26{
27
28/**
29 * This function creates a 2-Dimensional plot.
30 */
31void
33{
34 std::string fileNameWithoutExtension = "gnuplot-aggregator";
35 std::string plotTitle = "Gnuplot Aggregator Plot";
36 std::string plotXAxisHeading = "Time (seconds)";
37 std::string plotYAxisHeading = "Double Values";
38 std::string plotDatasetLabel = "Data Values";
39 std::string datasetContext = "Dataset/Context/String";
40
41 // Create an aggregator.
42 Ptr<GnuplotAggregator> aggregator = CreateObject<GnuplotAggregator>(fileNameWithoutExtension);
43
44 // Set the aggregator's properties.
45 aggregator->SetTerminal("png");
46 aggregator->SetTitle(plotTitle);
47 aggregator->SetLegend(plotXAxisHeading, plotYAxisHeading);
48
49 // Add a data set to the aggregator.
50 aggregator->Add2dDataset(datasetContext, plotDatasetLabel);
51
52 // aggregator must be turned on
53 aggregator->Enable();
54
55 double time;
56 double value;
57
58 // Create the 2-D dataset.
59 for (time = -5.0; time <= +5.0; time += 1.0)
60 {
61 // Calculate the 2-D curve
62 //
63 // 2
64 // value = time .
65 //
66 value = time * time;
67
68 // Add this point to the plot.
69 aggregator->Write2d(datasetContext, time, value);
70 }
71
72 // Disable logging of data for the aggregator.
73 aggregator->Disable();
74}
75
76} // unnamed namespace
77
78int
79main(int argc, char* argv[])
80{
82
83 return 0;
84}
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
void Create2dPlot()
This function creates a 2-Dimensional plot.
Every class exported by the ns3 library is enclosed in the ns3 namespace.