A Discrete-Event Network Simulator
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
12using namespace ns3;
13
14namespace
15{
16
17/**
18 * This function creates a file with 2 columns of values and separated
19 * by commas.
20 */
21void
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 =
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 */
59void
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.
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 */
96void
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 =
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
135int
136main(int argc, char* argv[])
137{
141
142 return 0;
143}
Smart pointer class similar to boost::intrusive_ptr.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
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.