Writes output data to tabular plaintext files.
More...
#include <text_table_writer.h>
Writes output data to tabular plaintext files.
In Parameters there are boolean variables prefixed with "text_tables". They are switches to enable and disable the creation of different data tables in plaintext files. The files have the same name as the corresponding boolean variable in TextTableWriterOptions. All files are created in a directory specified by TextTableWriterOptions::directory.
◆ TextTableWriter()
Constructor.
Create all files that are selected in options as empty files. Herbivore output files are only created if hft_names is not empty.
- Parameters
-
| interval | Selector if output is daily/monthly/annual/... |
| options | Specific user-defined options for this class. |
| hft_names | All HFTs in the simulation (see Fauna::Hft::name). |
- Exceptions
-
| std::runtime_error | If one of the output files already exists. |
◆ check_file_exists()
| void TextTableWriter::check_file_exists |
( |
const std::string & |
path | ) |
|
|
staticprivate |
Throw an exception if output file already exists.
◆ get_hft_data()
| const HerbivoreData * TextTableWriter::get_hft_data |
( |
const Datapoint * |
datapoint, |
|
|
const std::string & |
hft_name |
|
) |
| const |
|
private |
Retrieve herbivore data from datapoint for given HFT.
The return type is a pointer in order to minimize copying memory. It is save as long as datapoint is stable. If there is no data for the given HFT, an empty record is returned.
- Parameters
-
- Returns
- Pointer to HerbivoreData in
datapoint if it exists, otherwise a pointer to an empty HerbivoreData object.
- See also
- HerbivoreInterface::get_output_group() is the “HFT”.
◆ start_row()
| void TextTableWriter::start_row |
( |
const Datapoint & |
datapoint, |
|
|
std::ofstream & |
table |
|
) |
| |
|
private |
Create a new row by writing year/month/day and aggregation unit.
There is no FIELD_SEPARATOR at the end of the row.
- Parameters
-
| datapoint | Contains the date and aggregation unit. |
| table | Output stream to write to. This is a member variable of this class. |
◆ write_captions()
| void TextTableWriter::write_captions |
( |
const Datapoint & |
datapoint | ) |
|
|
private |
Write the first line in the output files: column headers.
- Parameters
-
| datapoint | Any output data with the same structure (e.g. list of HFTs) as following output data points will have. |
- Exceptions
-
◆ write_datapoint()
| void TextTableWriter::write_datapoint |
( |
const Datapoint & |
datapoint | ) |
|
|
virtual |
Append spatially & temporally aggregated output data to table files.
- Parameters
-
| datapoint | The output data to write. |
- Warning
datapoint must not change its structure between calls. For example, the list of HFTs must not change. This is because the column captions are written in the first call to this function. In subsequent calls there is no check whether the data tuples match the column captions.
- Exceptions
-
| std::invalid_argument | If an HFT name contains whitespaces or the FIELD_SEPARATOR (only checked on first call). |
| std::invalid_argument | If datapoint.data.datapoint_count is zero. |
| std::invalid_argument | If datapoint.interval does not match the given OutputInterval. |
| std::invalid_argument | If datapoint.aggregation_unit contains a whitespace or FIELD_SEPARATOR. |
| std::logic_error | If the OutputInterval is not implemented. |
| std::runtime_error | If datapoint.data.hft_data contains an unknown HFT (checked by comparing Fauna::Hft::name). |
Implements Fauna::Output::WriterInterface.
◆ available_forage
| std::ofstream Fauna::Output::TextTableWriter::available_forage |
|
private |
◆ body_fat
| std::ofstream Fauna::Output::TextTableWriter::body_fat |
|
private |
◆ captions_written
| bool Fauna::Output::TextTableWriter::captions_written = false |
|
private |
Whether column captions have already been written to file.
◆ digestibility
| std::ofstream Fauna::Output::TextTableWriter::digestibility |
|
private |
◆ eaten_forage_per_ind
| std::ofstream Fauna::Output::TextTableWriter::eaten_forage_per_ind |
|
private |
◆ eaten_nitrogen_per_ind
| std::ofstream Fauna::Output::TextTableWriter::eaten_nitrogen_per_ind |
|
private |
◆ FIELD_SEPARATOR
| const char Fauna::Output::TextTableWriter::FIELD_SEPARATOR = '\t' |
|
static |
Character to separate columns.
◆ FILE_EXTENSION
| const char * TextTableWriter::FILE_EXTENSION = ".tsv" |
|
static |
File extension for tabular plaintext files.
◆ file_streams
| std::vector<std::ofstream*> Fauna::Output::TextTableWriter::file_streams |
|
private |
List of pointers to the user-selected and active file streams.
◆ hft_names
| const std::set<std::string> Fauna::Output::TextTableWriter::hft_names |
|
private |
◆ individual_density
| std::ofstream Fauna::Output::TextTableWriter::individual_density |
|
private |
◆ interval
User-selected utput interval.
◆ mass_density
| std::ofstream Fauna::Output::TextTableWriter::mass_density |
|
private |
◆ mass_density_per_hft
| std::ofstream Fauna::Output::TextTableWriter::mass_density_per_hft |
|
private |
◆ NA_VALUE
| const char * TextTableWriter::NA_VALUE = "NA" |
|
static |
String to print for values that are not available (NA).
◆ options
User options from the instruction file.
The documentation for this class was generated from the following files:
- /home/docs/checkouts/readthedocs.org/user_builds/modular-megafauna-model/checkouts/latest/src/Fauna/Output/text_table_writer.h
- /home/docs/checkouts/readthedocs.org/user_builds/modular-megafauna-model/checkouts/latest/src/Fauna/Output/text_table_writer.cpp