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
std::string fileName =
"file-aggregator-comma-separated.txt"
;
35
std::string datasetContext =
"Dataset/Context/String"
;
36
37
// Create an aggregator.
38
Ptr<FileAggregator>
aggregator =
39
CreateObject<FileAggregator> (fileName, FileAggregator::COMMA_SEPARATED);
40
41
// aggregator must be turned on
42
aggregator->Enable ();
43
44
double
time;
45
double
value;
46
47
// Create the 2-D dataset.
48
for
(time = -5.0; time <= +5.0; time += 1.0)
49
{
50
// Calculate the 2-D curve
51
//
52
// 2
53
// value = time .
54
//
55
value = time * time;
56
57
// Add this point to the plot.
58
aggregator->Write2d (datasetContext, time, value);
59
}
60
61
// Disable logging of data for the aggregator.
62
aggregator->Disable ();
63
}
64
65
70
void
CreateSpaceSeparatedFile
()
71
{
72
std::string fileName =
"file-aggregator-space-separated.txt"
;
73
std::string datasetContext =
"Dataset/Context/String"
;
74
75
// Create an aggregator. Note that the default type is space
76
// separated.
77
Ptr<FileAggregator>
aggregator =
78
CreateObject<FileAggregator> (fileName);
79
80
// aggregator must be turned on
81
aggregator->Enable ();
82
83
double
time;
84
double
value;
85
86
// Create the 2-D dataset.
87
for
(time = -5.0; time <= +5.0; time += 1.0)
88
{
89
// Calculate the 2-D curve
90
//
91
// 2
92
// value = time .
93
//
94
value = time * time;
95
96
// Add this point to the plot.
97
aggregator->Write2d (datasetContext, time, value);
98
}
99
100
// Disable logging of data for the aggregator.
101
aggregator->Disable ();
102
}
103
104
108
void
CreateFormattedFile
()
109
{
110
std::string fileName =
"file-aggregator-formatted-values.txt"
;
111
std::string datasetContext =
"Dataset/Context/String"
;
112
113
// Create an aggregator that will have formatted values.
114
Ptr<FileAggregator>
aggregator =
115
CreateObject<FileAggregator> (fileName, FileAggregator::FORMATTED);
116
117
// Set the format for the values.
118
aggregator->Set2dFormat (
"Time = %.3e\tValue = %.0f"
);
119
120
// aggregator must be turned on
121
aggregator->Enable ();
122
123
double
time;
124
double
value;
125
126
// Create the 2-D dataset.
127
for
(time = -5.0; time < 5.5; time += 1.0)
128
{
129
// Calculate the 2-D curve
130
//
131
// 2
132
// value = time .
133
//
134
value = time * time;
135
136
// Add this point to the plot.
137
aggregator->Write2d (datasetContext, time, value);
138
}
139
140
// Disable logging of data for the aggregator.
141
aggregator->Disable ();
142
}
143
144
145
}
// unnamed namespace
146
147
148
int
main (
int
argc,
char
*argv[])
149
{
150
CreateCommaSeparatedFile
();
151
CreateSpaceSeparatedFile
();
152
CreateFormattedFile
();
153
154
return
0;
155
}
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:108
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:70
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
stats
examples
file-aggregator-example.cc
Generated on Sat May 28 2022 18:23:05 for ns-3 by
1.9.3