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