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 
31 void Create2dPlot ()
32 {
33  using namespace std;
34 
35  string fileNameWithoutExtension = "gnuplot-aggregator";
36  string plotTitle = "Gnuplot Aggregator Plot";
37  string plotXAxisHeading = "Time (seconds)";
38  string plotYAxisHeading = "Double Values";
39  string plotDatasetLabel = "Data Values";
40  string datasetContext = "Dataset/Context/String";
41 
42  // Create an aggregator.
43  Ptr<GnuplotAggregator> aggregator =
44  CreateObject<GnuplotAggregator> (fileNameWithoutExtension);
45 
46  // Set the aggregator's properties.
47  aggregator->SetTerminal ("png");
48  aggregator->SetTitle (plotTitle);
49  aggregator->SetLegend (plotXAxisHeading, plotYAxisHeading);
50 
51  // Add a data set to the aggregator.
52  aggregator->Add2dDataset (datasetContext, plotDatasetLabel);
53 
54  // aggregator must be turned on
55  aggregator->Enable ();
56 
57  double time;
58  double value;
59 
60  // Create the 2-D dataset.
61  for (time = -5.0; time <= +5.0; time += 1.0)
62  {
63  // Calculate the 2-D curve
64  //
65  // 2
66  // value = time .
67  //
68  value = time * time;
69 
70  // Add this point to the plot.
71  aggregator->Write2d (datasetContext, time, value);
72  }
73 
74  // Disable logging of data for the aggregator.
75  aggregator->Disable ();
76 }
77 
78 
79 } // unnamed namespace
80 
81 
82 int main (int argc, char *argv[])
83 {
84  Create2dPlot ();
85 
86  return 0;
87 }
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
void Create2dPlot()
This function creates a 2-Dimensional plot.
Every class exported by the ns3 library is enclosed in the ns3 namespace.