A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
file-aggregator-example.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2013 University of Washington
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Mitch Watrous (watrous@u.washington.edu)
7
*/
8
9
#include "ns3/core-module.h"
10
#include "ns3/stats-module.h"
11
12
using namespace
ns3
;
13
14
namespace
15
{
16
17
/**
18
* This function creates a file with 2 columns of values and separated
19
* by commas.
20
*/
21
void
22
CreateCommaSeparatedFile
()
23
{
24
std::string fileName =
"file-aggregator-comma-separated.txt"
;
25
std::string datasetContext =
"Dataset/Context/String"
;
26
27
// Create an aggregator.
28
Ptr<FileAggregator>
aggregator =
29
CreateObject<FileAggregator>
(fileName,
FileAggregator::COMMA_SEPARATED
);
30
31
// aggregator must be turned on
32
aggregator->Enable();
33
34
double
time;
35
double
value;
36
37
// Create the 2-D dataset.
38
for
(time = -5.0; time <= +5.0; time += 1.0)
39
{
40
// Calculate the 2-D curve
41
//
42
// 2
43
// value = time .
44
//
45
value = time * time;
46
47
// Add this point to the plot.
48
aggregator->Write2d(datasetContext, time, value);
49
}
50
51
// Disable logging of data for the aggregator.
52
aggregator->Disable();
53
}
54
55
/**
56
* This function creates a file with 2 columns of values and separated
57
* by commas.
58
*/
59
void
60
CreateSpaceSeparatedFile
()
61
{
62
std::string fileName =
"file-aggregator-space-separated.txt"
;
63
std::string datasetContext =
"Dataset/Context/String"
;
64
65
// Create an aggregator. Note that the default type is space
66
// separated.
67
Ptr<FileAggregator>
aggregator =
CreateObject<FileAggregator>
(fileName);
68
69
// aggregator must be turned on
70
aggregator->Enable();
71
72
double
time;
73
double
value;
74
75
// Create the 2-D dataset.
76
for
(time = -5.0; time <= +5.0; time += 1.0)
77
{
78
// Calculate the 2-D curve
79
//
80
// 2
81
// value = time .
82
//
83
value = time * time;
84
85
// Add this point to the plot.
86
aggregator->Write2d(datasetContext, time, value);
87
}
88
89
// Disable logging of data for the aggregator.
90
aggregator->Disable();
91
}
92
93
/**
94
* This function creates a file with formatted values.
95
*/
96
void
97
CreateFormattedFile
()
98
{
99
std::string fileName =
"file-aggregator-formatted-values.txt"
;
100
std::string datasetContext =
"Dataset/Context/String"
;
101
102
// Create an aggregator that will have formatted values.
103
Ptr<FileAggregator>
aggregator =
104
CreateObject<FileAggregator>
(fileName,
FileAggregator::FORMATTED
);
105
106
// Set the format for the values.
107
aggregator->Set2dFormat(
"Time = %.3e\tValue = %.0f"
);
108
109
// aggregator must be turned on
110
aggregator->Enable();
111
112
double
time;
113
double
value;
114
115
// Create the 2-D dataset.
116
for
(time = -5.0; time < 5.5; time += 1.0)
117
{
118
// Calculate the 2-D curve
119
//
120
// 2
121
// value = time .
122
//
123
value = time * time;
124
125
// Add this point to the plot.
126
aggregator->Write2d(datasetContext, time, value);
127
}
128
129
// Disable logging of data for the aggregator.
130
aggregator->Disable();
131
}
132
133
}
// unnamed namespace
134
135
int
136
main(
int
argc,
char
* argv[])
137
{
138
CreateCommaSeparatedFile
();
139
CreateSpaceSeparatedFile
();
140
CreateFormattedFile
();
141
142
return
0;
143
}
ns3::FileAggregator::FORMATTED
@ FORMATTED
Definition
file-aggregator.h:35
ns3::FileAggregator::COMMA_SEPARATED
@ COMMA_SEPARATED
Definition
file-aggregator.h:37
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
ns3::CreateObject
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition
object.h:619
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:22
anonymous_namespace{file-aggregator-example.cc}::CreateFormattedFile
void CreateFormattedFile()
This function creates a file with formatted values.
Definition
file-aggregator-example.cc:97
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:60
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
stats
examples
file-aggregator-example.cc
Generated on Fri Nov 8 2024 13:59:06 for ns-3 by
1.11.0