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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mitch Watrous (watrous@u.washington.edu)
7 */
8
9#include "ns3/core-module.h"
10#include "ns3/stats-module.h"
11
12using namespace ns3;
13
14namespace
15{
16
17/**
18 * This function creates a 2-Dimensional plot.
19 */
20void
22{
23 std::string fileNameWithoutExtension = "gnuplot-aggregator";
24 std::string plotTitle = "Gnuplot Aggregator Plot";
25 std::string plotXAxisHeading = "Time (seconds)";
26 std::string plotYAxisHeading = "Double Values";
27 std::string plotDatasetLabel = "Data Values";
28 std::string datasetContext = "Dataset/Context/String";
29
30 // Create an aggregator.
31 Ptr<GnuplotAggregator> aggregator = CreateObject<GnuplotAggregator>(fileNameWithoutExtension);
32
33 // Set the aggregator's properties.
34 aggregator->SetTerminal("png");
35 aggregator->SetTitle(plotTitle);
36 aggregator->SetLegend(plotXAxisHeading, plotYAxisHeading);
37
38 // Add a data set to the aggregator.
39 aggregator->Add2dDataset(datasetContext, plotDatasetLabel);
40
41 // aggregator must be turned on
42 aggregator->Enable();
43
44 double time;
45 double value;
46
47 // Create the 2-D dataset.
48 for (time = -5.0; time <= +5.0; time += 1.0)
49 {
50 // Calculate the 2-D curve
51 //
52 // 2
53 // value = time .
54 //
55 value = time * time;
56
57 // Add this point to the plot.
58 aggregator->Write2d(datasetContext, time, value);
59 }
60
61 // Disable logging of data for the aggregator.
62 aggregator->Disable();
63}
64
65} // unnamed namespace
66
67int
68main(int argc, char* argv[])
69{
71
72 return 0;
73}
Smart pointer class similar to boost::intrusive_ptr.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
void Create2dPlot()
This function creates a 2-Dimensional plot.
Every class exported by the ns3 library is enclosed in the ns3 namespace.