A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
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
24
using namespace
ns3
;
25
26
namespace
{
27
32
void
CreateCommaSeparatedFile
()
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
72
void
CreateSpaceSeparatedFile
()
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
112
void
CreateFormattedFile
()
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
154
int
main (
int
argc,
char
*argv[])
155
{
156
CreateCommaSeparatedFile
();
157
CreateSpaceSeparatedFile
();
158
CreateFormattedFile
();
159
160
return
0;
161
}
ns3::FileAggregator::FORMATTED
@ FORMATTED
Definition:
file-aggregator.h:45
ns3::FileAggregator::COMMA_SEPARATED
@ COMMA_SEPARATED
Definition:
file-aggregator.h:47
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition:
ptr.h:74
anonymous_namespace{file-aggregator-example.cc}::CreateCommaSeparatedFile
void CreateCommaSeparatedFile()
This function creates a file with 2 columns of values and separated by commas.
Definition:
file-aggregator-example.cc:32
anonymous_namespace{file-aggregator-example.cc}::CreateFormattedFile
void CreateFormattedFile()
This function creates a file with formatted values.
Definition:
file-aggregator-example.cc:112
anonymous_namespace{file-aggregator-example.cc}::CreateSpaceSeparatedFile
void CreateSpaceSeparatedFile()
This function creates a file with 2 columns of values and separated by commas.
Definition:
file-aggregator-example.cc:72
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
stats
examples
file-aggregator-example.cc
Generated on Tue Feb 6 2024 19:21:27 for ns-3 by
1.9.1