A Discrete-Event Network Simulator
API
file-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
24using namespace ns3;
25
26namespace {
27
33{
34 using namespace std;
35
36 string fileName = "file-aggregator-comma-separated.txt";
37 string datasetContext = "Dataset/Context/String";
38
39 // Create an aggregator.
40 Ptr<FileAggregator> aggregator =
41 CreateObject<FileAggregator> (fileName, FileAggregator::COMMA_SEPARATED);
42
43 // aggregator must be turned on
44 aggregator->Enable ();
45
46 double time;
47 double value;
48
49 // Create the 2-D dataset.
50 for (time = -5.0; time <= +5.0; time += 1.0)
51 {
52 // Calculate the 2-D curve
53 //
54 // 2
55 // value = time .
56 //
57 value = time * time;
58
59 // Add this point to the plot.
60 aggregator->Write2d (datasetContext, time, value);
61 }
62
63 // Disable logging of data for the aggregator.
64 aggregator->Disable ();
65}
66
67
73{
74 using namespace std;
75
76 string fileName = "file-aggregator-space-separated.txt";
77 string datasetContext = "Dataset/Context/String";
78
79 // Create an aggregator. Note that the default type is space
80 // separated.
81 Ptr<FileAggregator> aggregator =
82 CreateObject<FileAggregator> (fileName);
83
84 // aggregator must be turned on
85 aggregator->Enable ();
86
87 double time;
88 double value;
89
90 // Create the 2-D dataset.
91 for (time = -5.0; time <= +5.0; time += 1.0)
92 {
93 // Calculate the 2-D curve
94 //
95 // 2
96 // value = time .
97 //
98 value = time * time;
99
100 // Add this point to the plot.
101 aggregator->Write2d (datasetContext, time, value);
102 }
103
104 // Disable logging of data for the aggregator.
105 aggregator->Disable ();
106}
107
108
113{
114 using namespace std;
115
116 string fileName = "file-aggregator-formatted-values.txt";
117 string datasetContext = "Dataset/Context/String";
118
119 // Create an aggregator that will have formatted values.
120 Ptr<FileAggregator> aggregator =
121 CreateObject<FileAggregator> (fileName, FileAggregator::FORMATTED);
122
123 // Set the format for the values.
124 aggregator->Set2dFormat ("Time = %.3e\tValue = %.0f");
125
126 // aggregator must be turned on
127 aggregator->Enable ();
128
129 double time;
130 double value;
131
132 // Create the 2-D dataset.
133 for (time = -5.0; time < 5.5; time += 1.0)
134 {
135 // Calculate the 2-D curve
136 //
137 // 2
138 // value = time .
139 //
140 value = time * time;
141
142 // Add this point to the plot.
143 aggregator->Write2d (datasetContext, time, value);
144 }
145
146 // Disable logging of data for the aggregator.
147 aggregator->Disable ();
148}
149
150
151} // unnamed namespace
152
153
154int main (int argc, char *argv[])
155{
159
160 return 0;
161}
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
void CreateCommaSeparatedFile()
This function creates a file with 2 columns of values and separated by commas.
void CreateFormattedFile()
This function creates a file with formatted values.
void CreateSpaceSeparatedFile()
This function creates a file with 2 columns of values and separated by commas.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
STL namespace.