Cantera 2.6.0
plots.cpp
Go to the documentation of this file.
1/**
2 * @file plots.cpp
3 */
4
5// This file is part of Cantera. See License.txt in the top-level directory or
6// at https://cantera.org/license.txt for license and copyright information.
7
10
11using namespace std;
12
13namespace Cantera
14{
15
16void writePlotFile(const std::string& fname, const std::string& fmt,
17 const std::string& plotTitle,
18 const std::vector<std::string> &names,
19 const Array2D& data)
20{
21 warn_deprecated("writePlotFile", "To be removed after Cantera 2.6.");
22 ofstream f(fname);
23 if (!f) {
24 throw CanteraError("writePlotFile","could not open file "+fname+
25 " for writing.");
26 }
27 if (fmt == "TEC") {
28 outputTEC(f, plotTitle, names, data);
29 } else if (fmt == "XL" || fmt == "CSV") {
30 outputExcel(f, plotTitle, names, data);
31 } else {
32 throw CanteraError("writePlotFile",
33 "unsupported plot type:" + fmt);
34 }
35}
36
37void outputTEC(std::ostream& s, const std::string& title,
38 const std::vector<std::string>& names,
39 const Array2D& data)
40{
41 warn_deprecated("outputTEC", "To be removed after Cantera 2.6.");
42 s << "TITLE = \"" + title + "\"" << endl;
43 s << "VARIABLES = " << endl;
44 for (size_t i = 0; i < data.nRows(); i++) {
45 s << "\"" << names[i] << "\"" << endl;
46 }
47 s << "ZONE T=\"zone1\"" << endl;
48 s << " I=" << data.nColumns() << ",J=1,K=1,F=POINT" << endl;
49 s << "DT=( ";
50 for (size_t i = 0; i < data.nRows(); i++) {
51 s << " SINGLE";
52 }
53 s << " )" << endl;
54 for (size_t i = 0; i < data.nColumns(); i++) {
55 for (size_t j = 0; j < data.nRows(); j++) {
56 s << data(j,i) << " ";
57 }
58 s << endl;
59 }
60}
61
62void outputExcel(std::ostream& s, const std::string& title,
63 const std::vector<std::string>& names,
64 const Array2D& data)
65{
66 warn_deprecated("outputExcel", "To be removed after Cantera 2.6.");
67 if (!title.empty()) {
68 s << title + "," << endl;
69 }
70 for (size_t i = 0; i < data.nRows(); i++) {
71 s << names[i];
72 if (i != data.nRows()-1) {
73 s << ",";
74 }
75 }
76 s << endl;
77 for (size_t i = 0; i < data.nColumns(); i++) {
78 for (size_t j = 0; j < data.nRows(); j++) {
79 s << data(j,i);
80 if (j != data.nRows()-1) {
81 s << ",";
82 }
83 }
84 s << endl;
85 }
86}
87
88}
A class for 2D arrays stored in column-major (Fortran-compatible) form.
Definition: Array.h:30
size_t nRows() const
Number of rows.
Definition: Array.h:188
size_t nColumns() const
Number of columns.
Definition: Array.h:193
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
This file contains definitions for utility functions and text for modules, inputfiles,...
Namespace for the Cantera kernel.
Definition: AnyMap.h:29
void outputTEC(std::ostream &s, const std::string &title, const std::vector< std::string > &names, const Array2D &data)
Write a Tecplot data file.
Definition: plots.cpp:37
void warn_deprecated(const std::string &source, const AnyBase &node, const std::string &message)
A deprecation warning for syntax in an input file.
Definition: AnyMap.cpp:1901
void writePlotFile(const std::string &fname, const std::string &fmt, const std::string &plotTitle, const std::vector< std::string > &names, const Array2D &data)
Write a Plotting file.
Definition: plots.cpp:16
void outputExcel(std::ostream &s, const std::string &title, const std::vector< std::string > &names, const Array2D &data)
Write an Excel spreadsheet in 'csv' form.
Definition: plots.cpp:62
Versions 6.2.0 and 6.2.1 of fmtlib do not include this define before they include windows....
Definition: fmt.h:31
Contains declarations for utility functions for outputing to plotting programs.