This class is used for building, formatting, and outputting tables of numbers. More...
#include <FormattedTable.h>
Public Member Functions | |
FormattedTable () | |
Default constructor - The default constructor takes an optional parameter to turn off stateful printing. More... | |
FormattedTable (const FormattedTable &o) | |
Copy constructor - The copy constructor will duplicate the data structures but is not designed to work with FormattedTables with open streams (e.g. More... | |
~FormattedTable () | |
The destructor is used to close the file handle. More... | |
bool | empty () const |
Returns a boolean value based on whether the FormattedTable contains data or not. More... | |
void | append (bool append_existing_file) |
Sets append mode which means an existing file is not truncated on opening. More... | |
void | addRow (Real time) |
Force a new row in the table with the passed in time. More... | |
template<typename T = Real> | |
void | addData (const std::string &name, const T &value) |
Method for adding data to the output table. More... | |
template<typename T = Real> | |
void | addData (const std::string &name, const T &value, Real time) |
Method for adding data to the output table. More... | |
template<typename T = Real> | |
void | addData (const std::string &name, const std::vector< T > &vector) |
Method for adding an entire vector to a table at a time. More... | |
Real | getLastTime () |
Retrieve the last time (or independent variable) value. More... | |
template<typename T = Real> | |
T & | getLastData (const std::string &name) |
Retrieve Data for last value of given name. More... | |
void | clear () |
void | outputTimeColumn (bool output_time) |
Set whether or not to output time column. More... | |
void | printTable (std::ostream &out, unsigned int last_n_entries=0) |
Methods for dumping the table to the stream - either by filename or by stream handle. More... | |
void | printTable (std::ostream &out, unsigned int last_n_entries, const MooseEnum &suggested_term_width) |
void | printTable (const std::string &file_name) |
void | printCSV (const std::string &file_name, int interval=1, bool align=false) |
Method for dumping the table to a csv file - opening and closing the file handle is handled. More... | |
void | printEnsight (const std::string &file_name) |
void | writeExodus (ExodusII_IO *ex_out, Real time) |
void | makeGnuplot (const std::string &base_file, const std::string &format) |
void | setDelimiter (std::string delimiter) |
By default printCSV places "," between each entry, this allows this to be changed. More... | |
void | setPrecision (unsigned int precision) |
By default printCSV prints output to a precision of 14, this allows this to be changed. More... | |
void | sortColumns () |
Sorts columns alphabetically. More... | |
Static Public Member Functions | |
static MooseEnum | getWidthModes () |
Protected Member Functions | |
void | printTablePiece (std::ostream &out, unsigned int last_n_entries, std::map< std::string, unsigned short > &col_widths, std::vector< std::string >::iterator &col_begin, std::vector< std::string >::iterator &col_end) |
void | printOmittedRow (std::ostream &out, std::map< std::string, unsigned short > &col_widths, std::vector< std::string >::iterator &col_begin, std::vector< std::string >::iterator &col_end) const |
void | printRowDivider (std::ostream &out, std::map< std::string, unsigned short > &col_widths, std::vector< std::string >::iterator &col_begin, std::vector< std::string >::iterator &col_end) const |
void | printNoDataRow (char intersect_char, char fill_char, std::ostream &out, std::map< std::string, unsigned short > &col_widths, std::vector< std::string >::iterator &col_begin, std::vector< std::string >::iterator &col_end) const |
Protected Attributes | |
std::vector< std::pair< Real, std::map< std::string, std::shared_ptr< TableValueBase > > > > | _data |
Data structure for the console table: The first part of the pair tracks the independent variable (normally time) and is associated with the second part of the table which is the map of dependent variables and their associated values. More... | |
std::map< std::string, unsigned int > | _align_widths |
Alignment widths (only used if asked to print aligned to CSV output) More... | |
std::vector< std::string > | _column_names |
The set of column names updated when data is inserted through the setter methods. More... | |
Static Protected Attributes | |
static const unsigned short | _column_width = 15 |
The single cell width used for all columns in the table. More... | |
static const unsigned short | _min_pps_width = 40 |
The absolute minimum PPS table width. More... | |
Private Member Functions | |
void | close () |
Close the underlying output file stream if any. This is idempotent. More... | |
void | open (const std::string &file_name) |
Open or switch the underlying file stream to point to file_name. This is idempotent. More... | |
void | printRow (std::pair< Real, std::map< std::string, std::shared_ptr< TableValueBase >>> &row_data, bool align) |
void | fillEmptyValues () |
Fill any values that are not defined (usually when there are mismatched column lengths) More... | |
Private Attributes | |
std::string | _output_file_name |
The optional output file stream. More... | |
std::ofstream | _output_file |
The stream handle (corresponds to _output_file_name) More... | |
std::size_t | _output_row_index |
Keeps track of the index indicating which vector elements have been output. More... | |
bool | _headers_output |
Keeps track of whether the header has been output. More... | |
bool | _append |
Keeps track of whether we want to open an existing file for appending or overwriting. More... | |
bool | _output_time |
Whether or not to output the Time column. More... | |
std::string | _csv_delimiter |
*.csv file delimiter, defaults to "," More... | |
unsigned int | _csv_precision |
*.csv file precision, defaults to 14 More... | |
bool | _column_names_unsorted = true |
Flag indicating that sorting is necessary (used by sortColumns method). More... | |
Friends | |
void | dataStore (std::ostream &stream, FormattedTable &table, void *context) |
void | dataLoad (std::istream &stream, FormattedTable &v, void *context) |
This class is used for building, formatting, and outputting tables of numbers.
Definition at line 109 of file FormattedTable.h.
FormattedTable::FormattedTable | ( | ) |
Default constructor - The default constructor takes an optional parameter to turn off stateful printing.
This means that each time you ask the FormattedTable to print to a file, it'll, print the entire table. The default is to only print the part of the table that hasn't already been printed.
Definition at line 143 of file FormattedTable.C.
FormattedTable::FormattedTable | ( | const FormattedTable & | o | ) |
Copy constructor - The copy constructor will duplicate the data structures but is not designed to work with FormattedTables with open streams (e.g.
Definition at line 153 of file FormattedTable.C.
FormattedTable::~FormattedTable | ( | ) |
The destructor is used to close the file handle.
Definition at line 171 of file FormattedTable.C.
void FormattedTable::addData | ( | const std::string & | name, |
const T & | value | ||
) |
Method for adding data to the output table.
Data is added to the last row. Method will error if called on an empty table.
Definition at line 327 of file FormattedTable.h.
Referenced by AutomaticMortarGeneration::msmStatistics(), TableOutput::outputPostprocessors(), TableOutput::outputReporter(), TableOutput::outputScalarVariables(), and TableOutput::outputVectorPostprocessors().
void FormattedTable::addData | ( | const std::string & | name, |
const T & | value, | ||
Real | time | ||
) |
Method for adding data to the output table.
The dependent variable is named "time"
Definition at line 345 of file FormattedTable.h.
void FormattedTable::addData | ( | const std::string & | name, |
const std::vector< T > & | vector | ||
) |
Method for adding an entire vector to a table at a time.
Checks are made to ensure that the dependent variable index lines up with the vector indices.
Definition at line 373 of file FormattedTable.h.
Force a new row in the table with the passed in time.
Definition at line 186 of file FormattedTable.C.
Referenced by AutomaticMortarGeneration::msmStatistics(), TableOutput::outputPostprocessors(), and TableOutput::outputReporter().
void FormattedTable::append | ( | bool | append_existing_file | ) |
Sets append mode which means an existing file is not truncated on opening.
This mode is typically used for recovery.
Definition at line 180 of file FormattedTable.C.
Referenced by CSV::initialSetup().
void FormattedTable::clear | ( | ) |
Definition at line 568 of file FormattedTable.C.
Referenced by TableOutput::clear(), and AutomaticMortarGeneration::msmStatistics().
|
private |
Close the underlying output file stream if any. This is idempotent.
Definition at line 111 of file FormattedTable.C.
Referenced by open(), and ~FormattedTable().
bool FormattedTable::empty | ( | ) | const |
Returns a boolean value based on whether the FormattedTable contains data or not.
Definition at line 174 of file FormattedTable.C.
Referenced by addData(), getLastData(), getLastTime(), Gnuplot::output(), CSV::output(), TableOutput::outputPostprocessors(), Console::outputPostprocessors(), TableOutput::outputReporter(), Console::outputReporters(), and Console::outputScalarVariables().
|
private |
Fill any values that are not defined (usually when there are mismatched column lengths)
Definition at line 576 of file FormattedTable.C.
Referenced by dataStore(), makeGnuplot(), printCSV(), and printTablePiece().
T & FormattedTable::getLastData | ( | const std::string & | name | ) |
Retrieve Data for last value of given name.
Definition at line 397 of file FormattedTable.h.
Real FormattedTable::getLastTime | ( | ) |
Retrieve the last time (or independent variable) value.
Definition at line 192 of file FormattedTable.C.
Referenced by TableOutput::outputPostprocessors(), and TableOutput::outputReporter().
|
static |
Definition at line 586 of file FormattedTable.C.
Referenced by Console::validParams().
void FormattedTable::makeGnuplot | ( | const std::string & | base_file, |
const std::string & | format | ||
) |
Definition at line 474 of file FormattedTable.C.
Referenced by Gnuplot::output().
|
private |
Open or switch the underlying file stream to point to file_name. This is idempotent.
Definition at line 121 of file FormattedTable.C.
Referenced by printCSV(), and printTable().
|
inline |
Set whether or not to output time column.
Definition at line 183 of file FormattedTable.h.
Referenced by TableOutput::outputReporter(), TableOutput::outputVectorPostprocessors(), and TableOutput::TableOutput().
void FormattedTable::printCSV | ( | const std::string & | file_name, |
int | interval = 1 , |
||
bool | align = false |
||
) |
Method for dumping the table to a csv file - opening and closing the file handle is handled.
Note: Only call this on processor 0!
When the alignment option is set to true, the widths of the columns needs to be computed based on longest of the column name of the data supplied. This is done here by creating a map of the widths for each of the columns, including time
Definition at line 350 of file FormattedTable.C.
Referenced by CSV::output().
void FormattedTable::printEnsight | ( | const std::string & | file_name | ) |
|
protected |
Definition at line 217 of file FormattedTable.C.
Referenced by printOmittedRow(), and printRowDivider().
|
protected |
Definition at line 199 of file FormattedTable.C.
Referenced by printTablePiece().
|
private |
Definition at line 431 of file FormattedTable.C.
Referenced by printCSV().
|
protected |
Definition at line 208 of file FormattedTable.C.
Referenced by printTablePiece().
Methods for dumping the table to the stream - either by filename or by stream handle.
If a filename is supplied opening and closing of the file is properly handled. In the screen version of the method, an optional parameters can be passed to print only the last "n" entries. A value of zero means don't skip any rows
Note: Only call these from processor 0!
Definition at line 244 of file FormattedTable.C.
Referenced by AutomaticMortarGeneration::msmStatistics(), Console::outputPostprocessors(), Console::outputReporters(), Console::outputScalarVariables(), and printTable().
void FormattedTable::printTable | ( | std::ostream & | out, |
unsigned int | last_n_entries, | ||
const MooseEnum & | suggested_term_width | ||
) |
Definition at line 250 of file FormattedTable.C.
void FormattedTable::printTable | ( | const std::string & | file_name | ) |
Definition at line 237 of file FormattedTable.C.
|
protected |
Print out the header row
Definition at line 300 of file FormattedTable.C.
Referenced by printTable().
|
inline |
By default printCSV places "," between each entry, this allows this to be changed.
Definition at line 217 of file FormattedTable.h.
Referenced by CSV::initialSetup().
By default printCSV prints output to a precision of 14, this allows this to be changed.
Definition at line 222 of file FormattedTable.h.
Referenced by CSV::initialSetup().
void FormattedTable::sortColumns | ( | ) |
Sorts columns alphabetically.
Definition at line 592 of file FormattedTable.C.
Referenced by CSV::output(), Console::outputPostprocessors(), Console::outputReporters(), and Console::outputScalarVariables().
|
friend |
Definition at line 39 of file FormattedTable.C.
|
friend |
Definition at line 27 of file FormattedTable.C.
|
protected |
Alignment widths (only used if asked to print aligned to CSV output)
Definition at line 261 of file FormattedTable.h.
Referenced by dataLoad(), dataStore(), printCSV(), and printRow().
|
private |
Keeps track of whether we want to open an existing file for appending or overwriting.
Definition at line 306 of file FormattedTable.h.
|
protected |
The set of column names updated when data is inserted through the setter methods.
Definition at line 264 of file FormattedTable.h.
Referenced by addData(), dataLoad(), dataStore(), fillEmptyValues(), makeGnuplot(), printCSV(), printRow(), printTable(), and sortColumns().
|
private |
Flag indicating that sorting is necessary (used by sortColumns method).
Definition at line 318 of file FormattedTable.h.
Referenced by addData(), and sortColumns().
|
staticprotected |
The single cell width used for all columns in the table.
Definition at line 267 of file FormattedTable.h.
Referenced by printNoDataRow(), printTable(), and printTablePiece().
|
private |
*.csv file delimiter, defaults to ","
Definition at line 312 of file FormattedTable.h.
Referenced by printCSV(), printRow(), and setDelimiter().
|
private |
*.csv file precision, defaults to 14
Definition at line 315 of file FormattedTable.h.
Referenced by printCSV(), printRow(), and setPrecision().
|
protected |
Data structure for the console table: The first part of the pair tracks the independent variable (normally time) and is associated with the second part of the table which is the map of dependent variables and their associated values.
Definition at line 258 of file FormattedTable.h.
Referenced by addData(), addRow(), clear(), dataLoad(), dataStore(), empty(), fillEmptyValues(), FormattedTable(), getLastData(), getLastTime(), makeGnuplot(), printCSV(), and printTablePiece().
|
private |
Keeps track of whether the header has been output.
This is separate from _output_row_index because it's possible to output the header with zero rows. We don't consider this a bug, it helps users understand that they have declared vectors properly but maybe haven't populated them correctly.
Definition at line 303 of file FormattedTable.h.
Referenced by dataLoad(), dataStore(), open(), and printCSV().
|
staticprotected |
The absolute minimum PPS table width.
Definition at line 270 of file FormattedTable.h.
Referenced by printTable().
|
private |
The stream handle (corresponds to _output_file_name)
Definition at line 289 of file FormattedTable.h.
Referenced by clear(), close(), FormattedTable(), open(), printCSV(), printRow(), and printTable().
|
private |
The optional output file stream.
Definition at line 286 of file FormattedTable.h.
|
private |
Keeps track of the index indicating which vector elements have been output.
All items with an index less than this index have been output. Higher values have not.
Definition at line 295 of file FormattedTable.h.
Referenced by clear(), dataLoad(), dataStore(), open(), and printCSV().
|
private |
Whether or not to output the Time column.
Definition at line 309 of file FormattedTable.h.
Referenced by outputTimeColumn(), printCSV(), printNoDataRow(), printRow(), and printTablePiece().