A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 } // anonymous namespace
84 
85 
86 int main (int argc, char *argv[])
87 {
88  Create2dPlot ();
89 
90  return 0;
91 }
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
int main(int argc, char *argv[])