|
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
|
2 /* |
|
3 * Copyright (c) 2007 INRIA, 2008 Timo Bingmann |
|
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 * Original Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
|
19 * Enhancements: Timo Bingmann <timo.bingmann@student.kit.edu> |
|
20 */ |
|
21 #include "gnuplot.h" |
|
22 #include "ns3/assert.h" |
|
23 #include <ostream> |
|
24 #include <stdexcept> |
|
25 |
|
26 namespace ns3 { |
|
27 |
|
28 // --- GnuplotDataset::Data ------------------------------------------------ // |
|
29 |
|
30 struct GnuplotDataset::Data |
|
31 { |
|
32 // *** Data Variables *** |
|
33 |
|
34 unsigned int m_references; |
|
35 |
|
36 std::string m_title; |
|
37 std::string m_extra; |
|
38 |
|
39 /** |
|
40 * Initializes the reference counter to 1 and sets m_title and m_extra. |
|
41 */ |
|
42 Data(const std::string& title); |
|
43 |
|
44 /// Required. |
|
45 virtual ~Data(); |
|
46 |
|
47 /** |
|
48 * Returns "plot" or "splot". |
|
49 */ |
|
50 virtual std::string GetCommand() const = 0; |
|
51 |
|
52 /** |
|
53 * Prints the plot description used as argument to (s)plot. Either the |
|
54 * function expression or a datafile description. Should include m_title and |
|
55 * m_extra in the output. |
|
56 */ |
|
57 virtual void PrintExpression(std::ostream &os) const = 0; |
|
58 |
|
59 /** |
|
60 * Print the inline data file contents trailing the plot command. Empty for |
|
61 * functions. |
|
62 */ |
|
63 virtual void PrintDatafile(std::ostream &os) const = 0; |
|
64 }; |
|
65 |
|
66 GnuplotDataset::Data::Data(const std::string& title) |
|
67 : m_references(1), |
|
68 m_title(title), |
|
69 m_extra(m_defaultExtra) |
|
70 { |
|
71 } |
|
72 |
|
73 GnuplotDataset::Data::~Data() |
|
74 { |
|
75 } |
|
76 |
|
77 // --- GnuplotDataset ------------------------------------------------------ // |
|
78 |
|
79 std::string GnuplotDataset::m_defaultExtra = ""; |
|
80 |
|
81 GnuplotDataset::GnuplotDataset (struct Data* data) |
|
82 : m_data(data) |
|
83 { |
|
84 } |
|
85 |
|
86 GnuplotDataset::GnuplotDataset (const GnuplotDataset& original) |
|
87 : m_data(original.m_data) |
|
88 { |
|
89 ++m_data->m_references; |
|
90 } |
|
91 |
|
92 GnuplotDataset::~GnuplotDataset() |
|
93 { |
|
94 if (--m_data->m_references == 0) |
|
95 delete m_data; |
|
96 } |
|
97 |
|
98 GnuplotDataset& GnuplotDataset::operator= (const GnuplotDataset& original) |
|
99 { |
|
100 if (this != &original) |
|
101 { |
|
102 if (--m_data->m_references == 0) |
|
103 delete m_data; |
|
104 |
|
105 m_data = original.m_data; |
|
106 ++m_data->m_references; |
|
107 } |
|
108 return *this; |
|
109 } |
|
110 |
|
111 void |
|
112 GnuplotDataset::SetTitle (const std::string& title) |
|
113 { |
|
114 m_data->m_title = title; |
|
115 } |
|
116 |
|
117 void |
|
118 GnuplotDataset::SetDefaultExtra (const std::string& extra) |
|
119 { |
|
120 m_defaultExtra = extra; |
|
121 } |
|
122 void |
|
123 GnuplotDataset::SetExtra (const std::string& extra) |
|
124 { |
|
125 m_data->m_extra = extra; |
|
126 } |
|
127 |
|
128 // --- Gnuplot2dDataset::Data2d -------------------------------------------- // |
|
129 |
|
130 struct Gnuplot2dDataset::Data2d : public GnuplotDataset::Data |
|
131 { |
|
132 // *** Data Variables *** |
|
133 |
|
134 enum Style m_style; |
|
135 enum ErrorBars m_errorBars; |
|
136 |
|
137 PointSet m_pointset; |
|
138 |
|
139 /** |
|
140 * Initializes with the values from m_defaultStyle and m_defaultErrorBars. |
|
141 */ |
|
142 Data2d(const std::string& title); |
|
143 |
|
144 virtual std::string GetCommand() const; |
|
145 virtual void PrintExpression(std::ostream &os) const; |
|
146 virtual void PrintDatafile(std::ostream &os) const; |
|
147 }; |
|
148 |
|
149 Gnuplot2dDataset::Data2d::Data2d(const std::string& title) |
|
150 : Data(title), |
|
151 m_style(m_defaultStyle), |
|
152 m_errorBars(m_defaultErrorBars) |
|
153 { |
|
154 } |
|
155 |
|
156 std::string |
|
157 Gnuplot2dDataset::Data2d::GetCommand() const |
|
158 { |
|
159 return "plot"; |
|
160 } |
|
161 |
|
162 void |
|
163 Gnuplot2dDataset::Data2d::PrintExpression(std::ostream &os) const |
|
164 { |
|
165 os << "'-' "; |
|
166 |
|
167 if (m_title.size()) |
|
168 os << " title '" << m_title << "'"; |
|
169 |
|
170 switch (m_style) { |
|
171 case LINES: |
|
172 os << " with lines"; |
|
173 break; |
|
174 case POINTS: |
|
175 switch (m_errorBars) |
|
176 { |
|
177 case NONE: |
|
178 os << " with points"; |
|
179 break; |
|
180 case X: |
|
181 os << " with xerrorbars"; |
|
182 break; |
|
183 case Y: |
|
184 os << " with yerrorbars"; |
|
185 break; |
|
186 case XY: |
|
187 os << " with xyerrorbars"; |
|
188 break; |
|
189 } |
|
190 break; |
|
191 case LINES_POINTS: |
|
192 switch (m_errorBars) |
|
193 { |
|
194 case NONE: |
|
195 os << " with linespoints"; |
|
196 break; |
|
197 case X: |
|
198 os << " with errorlines"; |
|
199 break; |
|
200 case Y: |
|
201 os << " with yerrorlines"; |
|
202 break; |
|
203 case XY: |
|
204 os << " with xyerrorlines"; |
|
205 break; |
|
206 } |
|
207 break; |
|
208 case DOTS: |
|
209 os << " with dots"; |
|
210 break; |
|
211 case IMPULSES: |
|
212 os << " with impulses"; |
|
213 break; |
|
214 case STEPS: |
|
215 os << " with steps"; |
|
216 break; |
|
217 case FSTEPS: |
|
218 os << " with fsteps"; |
|
219 break; |
|
220 case HISTEPS: |
|
221 os << " with histeps"; |
|
222 break; |
|
223 } |
|
224 |
|
225 if (m_extra.size()) |
|
226 os << " " << m_extra; |
|
227 } |
|
228 |
|
229 void |
|
230 Gnuplot2dDataset::Data2d::PrintDatafile(std::ostream &os) const |
|
231 { |
|
232 for (PointSet::const_iterator i = m_pointset.begin (); |
|
233 i != m_pointset.end (); ++i) |
|
234 { |
|
235 if (i->empty) { |
|
236 os << std::endl; |
|
237 continue; |
|
238 } |
|
239 |
|
240 switch (m_errorBars) { |
|
241 case NONE: |
|
242 os << i->x << " " << i->y << std::endl; |
|
243 break; |
|
244 case X: |
|
245 os << i->x << " " << i->y << " " << i->dx << std::endl; |
|
246 break; |
|
247 case Y: |
|
248 os << i->x << " " << i->y << " " << i->dy << std::endl; |
|
249 break; |
|
250 case XY: |
|
251 os << i->x << " " << i->y << " " << i->dx << " " << i->dy << std::endl; |
|
252 break; |
|
253 } |
|
254 } |
|
255 os << "e" << std::endl; |
|
256 } |
|
257 |
|
258 // --- Gnuplot2dDataset ---------------------------------------------------- // |
|
259 |
|
260 enum Gnuplot2dDataset::Style Gnuplot2dDataset::m_defaultStyle = LINES; |
|
261 enum Gnuplot2dDataset::ErrorBars Gnuplot2dDataset::m_defaultErrorBars = NONE; |
|
262 |
|
263 Gnuplot2dDataset::Gnuplot2dDataset (const std::string& title) |
|
264 : GnuplotDataset( new Data2d(title) ) |
|
265 { |
|
266 } |
|
267 |
|
268 void |
|
269 Gnuplot2dDataset::SetDefaultStyle (enum Style style) |
|
270 { |
|
271 m_defaultStyle = style; |
|
272 } |
|
273 void |
|
274 Gnuplot2dDataset::SetStyle (enum Style style) |
|
275 { |
|
276 reinterpret_cast<Data2d*>(m_data)->m_style = style; |
|
277 } |
|
278 |
|
279 void |
|
280 Gnuplot2dDataset::SetDefaultErrorBars (enum ErrorBars errorBars) |
|
281 { |
|
282 m_defaultErrorBars = errorBars; |
|
283 } |
|
284 void |
|
285 Gnuplot2dDataset::SetErrorBars (enum ErrorBars errorBars) |
|
286 { |
|
287 reinterpret_cast<Data2d*>(m_data)->m_errorBars = errorBars; |
|
288 } |
|
289 |
|
290 void |
|
291 Gnuplot2dDataset::Add (double x, double y) |
|
292 { |
|
293 NS_ASSERT (reinterpret_cast<Data2d*>(m_data)->m_errorBars == NONE); |
|
294 |
|
295 struct Point data; |
|
296 data.empty = false; |
|
297 data.x = x; |
|
298 data.y = y; |
|
299 data.dx = 0.0; |
|
300 data.dy = 0.0; |
|
301 reinterpret_cast<Data2d*>(m_data)->m_pointset.push_back (data); |
|
302 } |
|
303 |
|
304 void |
|
305 Gnuplot2dDataset::Add (double x, double y, double errorDelta) |
|
306 { |
|
307 NS_ASSERT ( reinterpret_cast<Data2d*>(m_data)->m_errorBars == X || |
|
308 reinterpret_cast<Data2d*>(m_data)->m_errorBars == Y ); |
|
309 |
|
310 struct Point data; |
|
311 data.empty = false; |
|
312 data.x = x; |
|
313 data.y = y; |
|
314 data.dx = errorDelta; |
|
315 data.dy = errorDelta; |
|
316 reinterpret_cast<Data2d*>(m_data)->m_pointset.push_back (data); |
|
317 } |
|
318 |
|
319 void |
|
320 Gnuplot2dDataset::Add (double x, double y, double minY, double maxY) |
|
321 { |
|
322 NS_ASSERT ( reinterpret_cast<Data2d*>(m_data)->m_errorBars == X || |
|
323 reinterpret_cast<Data2d*>(m_data)->m_errorBars == Y ); |
|
324 |
|
325 struct Point data; |
|
326 data.empty = false; |
|
327 data.x = x; |
|
328 data.y = y; |
|
329 data.dx = minY; |
|
330 data.dy = maxY; |
|
331 reinterpret_cast<Data2d*>(m_data)->m_pointset.push_back (data); |
|
332 } |
|
333 |
|
334 void |
|
335 Gnuplot2dDataset::AddEmptyLine() |
|
336 { |
|
337 struct Point data; |
|
338 data.empty = true; |
|
339 reinterpret_cast<Data2d*>(m_data)->m_pointset.push_back (data); |
|
340 } |
|
341 |
|
342 // --- Gnuplot2dFunction::Function2d --------------------------------------- // |
|
343 |
|
344 struct Gnuplot2dFunction::Function2d : public GnuplotDataset::Data |
|
345 { |
|
346 // *** Data Variables *** |
|
347 |
|
348 std::string m_function; |
|
349 |
|
350 /** |
|
351 * Initializes with the function and title. |
|
352 */ |
|
353 Function2d(const std::string& title, const std::string& function); |
|
354 |
|
355 virtual std::string GetCommand() const; |
|
356 virtual void PrintExpression(std::ostream &os) const; |
|
357 virtual void PrintDatafile(std::ostream &os) const; |
|
358 }; |
|
359 |
|
360 Gnuplot2dFunction::Function2d::Function2d(const std::string& title, const std::string& function) |
|
361 : Data(title), |
|
362 m_function(function) |
|
363 { |
|
364 } |
|
365 |
|
366 std::string |
|
367 Gnuplot2dFunction::Function2d::GetCommand() const |
|
368 { |
|
369 return "plot"; |
|
370 } |
|
371 |
|
372 void |
|
373 Gnuplot2dFunction::Function2d::PrintExpression(std::ostream &os) const |
|
374 { |
|
375 os << m_function; |
|
376 |
|
377 if (m_title.size()) |
|
378 os << " title '" << m_title << "'"; |
|
379 |
|
380 if (m_extra.size()) |
|
381 os << " " << m_extra; |
|
382 } |
|
383 |
|
384 void |
|
385 Gnuplot2dFunction::Function2d::PrintDatafile(std::ostream &os) const |
|
386 { |
|
387 } |
|
388 |
|
389 // --- Gnuplot2dFunction --------------------------------------------------- // |
|
390 |
|
391 Gnuplot2dFunction::Gnuplot2dFunction (const std::string& title, const std::string& function) |
|
392 : GnuplotDataset( new Function2d(title, function) ) |
|
393 { |
|
394 } |
|
395 |
|
396 void |
|
397 Gnuplot2dFunction::SetFunction (const std::string& function) |
|
398 { |
|
399 reinterpret_cast<Function2d*>(m_data)->m_function = function; |
|
400 } |
|
401 |
|
402 // --- Gnuplot3dDataset::Data3d -------------------------------------------- // |
|
403 |
|
404 struct Gnuplot3dDataset::Data3d : public GnuplotDataset::Data |
|
405 { |
|
406 // *** Data Variables *** |
|
407 |
|
408 std::string m_style; |
|
409 |
|
410 PointSet m_pointset; |
|
411 |
|
412 /** |
|
413 * Initializes with value from m_defaultStyle. |
|
414 */ |
|
415 Data3d(const std::string& title); |
|
416 |
|
417 virtual std::string GetCommand() const; |
|
418 virtual void PrintExpression(std::ostream &os) const; |
|
419 virtual void PrintDatafile(std::ostream &os) const; |
|
420 }; |
|
421 |
|
422 Gnuplot3dDataset::Data3d::Data3d(const std::string& title) |
|
423 : Data(title), |
|
424 m_style(m_defaultStyle) |
|
425 { |
|
426 } |
|
427 |
|
428 std::string |
|
429 Gnuplot3dDataset::Data3d::GetCommand() const |
|
430 { |
|
431 return "splot"; |
|
432 } |
|
433 |
|
434 void |
|
435 Gnuplot3dDataset::Data3d::PrintExpression(std::ostream &os) const |
|
436 { |
|
437 os << "'-' "; |
|
438 |
|
439 if (m_style.size()) |
|
440 os << " " << m_style; |
|
441 |
|
442 if (m_title.size()) |
|
443 os << " title '" << m_title << "'"; |
|
444 |
|
445 if (m_extra.size()) |
|
446 os << " " << m_extra; |
|
447 } |
|
448 |
|
449 void |
|
450 Gnuplot3dDataset::Data3d::PrintDatafile(std::ostream &os) const |
|
451 { |
|
452 for (PointSet::const_iterator i = m_pointset.begin (); |
|
453 i != m_pointset.end (); ++i) |
|
454 { |
|
455 if (i->empty) { |
|
456 os << std::endl; |
|
457 continue; |
|
458 } |
|
459 |
|
460 os << i->x << " " << i->y << " " << i->z << std::endl; |
|
461 } |
|
462 os << "e" << std::endl; |
|
463 } |
|
464 |
|
465 // --- Gnuplot3dDataset ---------------------------------------------------- // |
|
466 |
|
467 std::string Gnuplot3dDataset::m_defaultStyle = ""; |
|
468 |
|
469 Gnuplot3dDataset::Gnuplot3dDataset (const std::string& title) |
|
470 : GnuplotDataset( new Data3d(title) ) |
|
471 { |
|
472 } |
|
473 |
|
474 void |
|
475 Gnuplot3dDataset::SetDefaultStyle (const std::string& style) |
|
476 { |
|
477 m_defaultStyle = style; |
|
478 } |
|
479 void |
|
480 Gnuplot3dDataset::SetStyle (const std::string& style) |
|
481 { |
|
482 reinterpret_cast<Data3d*>(m_data)->m_style = style; |
|
483 } |
|
484 |
|
485 void |
|
486 Gnuplot3dDataset::Add (double x, double y, double z) |
|
487 { |
|
488 struct Point data; |
|
489 data.empty = false; |
|
490 data.x = x; |
|
491 data.y = y; |
|
492 data.z = z; |
|
493 reinterpret_cast<Data3d*>(m_data)->m_pointset.push_back (data); |
|
494 } |
|
495 |
|
496 void |
|
497 Gnuplot3dDataset::AddEmptyLine() |
|
498 { |
|
499 struct Point data; |
|
500 data.empty = true; |
|
501 reinterpret_cast<Data3d*>(m_data)->m_pointset.push_back (data); |
|
502 } |
|
503 |
|
504 // --- Gnuplot3dFunction::Function3d --------------------------------------- // |
|
505 |
|
506 struct Gnuplot3dFunction::Function3d : public GnuplotDataset::Data |
|
507 { |
|
508 // *** Data Variables *** |
|
509 |
|
510 std::string m_function; |
|
511 |
|
512 /** |
|
513 * Initializes with the function and title. |
|
514 */ |
|
515 Function3d(const std::string& title, const std::string& function); |
|
516 |
|
517 virtual std::string GetCommand() const; |
|
518 virtual void PrintExpression(std::ostream &os) const; |
|
519 virtual void PrintDatafile(std::ostream &os) const; |
|
520 }; |
|
521 |
|
522 Gnuplot3dFunction::Function3d::Function3d(const std::string& title, const std::string& function) |
|
523 : Data(title), |
|
524 m_function(function) |
|
525 { |
|
526 } |
|
527 |
|
528 std::string |
|
529 Gnuplot3dFunction::Function3d::GetCommand() const |
|
530 { |
|
531 return "splot"; |
|
532 } |
|
533 |
|
534 void |
|
535 Gnuplot3dFunction::Function3d::PrintExpression(std::ostream &os) const |
|
536 { |
|
537 os << m_function; |
|
538 |
|
539 if (m_title.size()) |
|
540 os << " title '" << m_title << "'"; |
|
541 |
|
542 if (m_extra.size()) |
|
543 os << " " << m_extra; |
|
544 } |
|
545 |
|
546 void |
|
547 Gnuplot3dFunction::Function3d::PrintDatafile(std::ostream &os) const |
|
548 { |
|
549 } |
|
550 |
|
551 // --- Gnuplot3dFunction --------------------------------------------------- // |
|
552 |
|
553 Gnuplot3dFunction::Gnuplot3dFunction (const std::string& title, const std::string& function) |
|
554 : GnuplotDataset( new Function3d(title, function) ) |
|
555 { |
|
556 } |
|
557 |
|
558 void |
|
559 Gnuplot3dFunction::SetFunction (const std::string& function) |
|
560 { |
|
561 reinterpret_cast<Function3d*>(m_data)->m_function = function; |
|
562 } |
|
563 |
|
564 // ------------------------------------------------------------------------- // |
|
565 |
|
566 Gnuplot::Gnuplot (const std::string& outputFilename, const std::string& title) |
|
567 : m_outputFilename(outputFilename), |
|
568 m_terminal( DetectTerminal(outputFilename) ), |
|
569 m_title(title) |
|
570 { |
|
571 } |
|
572 |
|
573 std::string Gnuplot::DetectTerminal (const std::string& filename) |
|
574 { |
|
575 std::string::size_type dotpos = filename.rfind('.'); |
|
576 if (dotpos == std::string::npos) return ""; |
|
577 |
|
578 if (filename.substr(dotpos) == ".png") { |
|
579 return "png"; |
|
580 } |
|
581 else if (filename.substr(dotpos) == ".pdf") { |
|
582 return "pdf"; |
|
583 } |
|
584 |
|
585 return ""; |
|
586 } |
|
587 |
|
588 void |
|
589 Gnuplot::SetTerminal (const std::string& terminal) |
|
590 { |
|
591 m_terminal = terminal; |
|
592 } |
|
593 |
|
594 void |
|
595 Gnuplot::SetTitle (const std::string& title) |
|
596 { |
|
597 m_title = title; |
|
598 } |
|
599 |
|
600 void |
|
601 Gnuplot::SetLegend (const std::string& xLegend, const std::string& yLegend) |
|
602 { |
|
603 m_xLegend = xLegend; |
|
604 m_yLegend = yLegend; |
|
605 } |
|
606 |
|
607 void |
|
608 Gnuplot::SetExtra (const std::string& extra) |
|
609 { |
|
610 m_extra = extra; |
|
611 } |
|
612 |
|
613 void |
|
614 Gnuplot::AppendExtra (const std::string& extra) |
|
615 { |
|
616 m_extra += "\n"; |
|
617 m_extra += extra; |
|
618 } |
|
619 |
|
620 void |
|
621 Gnuplot::AddDataset (const GnuplotDataset& dataset) |
|
622 { |
|
623 m_datasets.push_back (dataset); |
|
624 } |
|
625 |
|
626 void |
|
627 Gnuplot::GenerateOutput (std::ostream &os) const |
|
628 { |
|
629 if (m_terminal.size()) |
|
630 os << "set terminal " << m_terminal << std::endl; |
|
631 |
|
632 if (m_outputFilename.size()) |
|
633 os << "set output '" << m_outputFilename << "'" << std::endl; |
|
634 |
|
635 if (m_title.size()) |
|
636 os << "set title '" << m_title << "'" << std::endl; |
|
637 |
|
638 if (m_xLegend.size()) |
|
639 os << "set xlabel '" << m_xLegend << "'" << std::endl; |
|
640 |
|
641 if (m_yLegend.size()) |
|
642 os << "set ylabel '" << m_yLegend << "'" << std::endl; |
|
643 |
|
644 if (m_extra.size()) |
|
645 os << m_extra << std::endl; |
|
646 |
|
647 if (m_datasets.empty()) |
|
648 return; |
|
649 |
|
650 // Determine the GetCommand() values of all datasets included. Check that all |
|
651 // are equal and print the command. |
|
652 |
|
653 std::string command = m_datasets.begin()->m_data->GetCommand(); |
|
654 |
|
655 for (Datasets::const_iterator i = m_datasets.begin () + 1; |
|
656 i != m_datasets.end (); ++i) |
|
657 { |
|
658 NS_ASSERT_MSG(command == i->m_data->GetCommand(), |
|
659 "Cannot mix 'plot' and 'splot' GnuplotDatasets."); |
|
660 } |
|
661 |
|
662 os << command << " "; |
|
663 |
|
664 // Print all dataset expressions |
|
665 |
|
666 for (Datasets::const_iterator i = m_datasets.begin (); i != m_datasets.end ();) |
|
667 { |
|
668 i->m_data->PrintExpression(os); |
|
669 |
|
670 i++; |
|
671 |
|
672 if (i != m_datasets.end ()) |
|
673 { |
|
674 os << ", "; |
|
675 } |
|
676 } |
|
677 os << std::endl; |
|
678 |
|
679 // followed by the inline datafile. |
|
680 |
|
681 for (Datasets::const_iterator i = m_datasets.begin (); i != m_datasets.end (); i++) |
|
682 { |
|
683 i->m_data->PrintDatafile(os); |
|
684 } |
|
685 } |
|
686 |
|
687 // ------------------------------------------------------------------------- // |
|
688 |
|
689 GnuplotCollection::GnuplotCollection (const std::string& outputFilename) |
|
690 : m_outputFilename(outputFilename), |
|
691 m_terminal( Gnuplot::DetectTerminal(outputFilename) ) |
|
692 { |
|
693 } |
|
694 |
|
695 void |
|
696 GnuplotCollection::SetTerminal (const std::string& terminal) |
|
697 { |
|
698 m_terminal = terminal; |
|
699 } |
|
700 |
|
701 void |
|
702 GnuplotCollection::AddPlot (const Gnuplot& plot) |
|
703 { |
|
704 m_plots.push_back (plot); |
|
705 } |
|
706 |
|
707 Gnuplot& |
|
708 GnuplotCollection::GetPlot(unsigned int id) |
|
709 { |
|
710 if (id >= m_plots.size()) |
|
711 throw(std::range_error("Gnuplot id is out of range")); |
|
712 else |
|
713 return m_plots[id]; |
|
714 } |
|
715 |
|
716 void |
|
717 GnuplotCollection::GenerateOutput (std::ostream &os) const |
|
718 { |
|
719 if (m_terminal.size()) |
|
720 os << "set terminal " << m_terminal << std::endl; |
|
721 |
|
722 if (m_outputFilename.size()) |
|
723 os << "set output '" << m_outputFilename << "'" << std::endl; |
|
724 |
|
725 for (Plots::const_iterator i = m_plots.begin (); i != m_plots.end (); ++i) |
|
726 { |
|
727 i->GenerateOutput (os); |
|
728 } |
|
729 } |
|
730 |
|
731 // ------------------------------------------------------------------------- // |
|
732 |
|
733 } // namespace ns3 |