Modular Megafauna Model 1.1.5
A physiological, dynamic herbivore simulator in C++.
Loading...
Searching...
No Matches
text_table_writer.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2020 W. Traylor <wolfgang.traylor@senckenberg.de>
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
11#ifndef FAUNA_OUTPUT_TEXT_TABLE_WRITER_H
12#define FAUNA_OUTPUT_TEXT_TABLE_WRITER_H
13
14#include <fstream>
15#include <vector>
16#include "parameters.h"
17#include "writer_interface.h"
18
19namespace Fauna {
20namespace Output {
21// Forward declarations
22class HerbivoreData;
23
25
34 public:
36
46 const std::set<std::string> hft_names);
47
49
74 virtual void write_datapoint(const Datapoint& datapoint);
75
77 static const char* NA_VALUE;
78
80 static const char FIELD_SEPARATOR = '\t';
81
83 static const char* FILE_EXTENSION;
84
85 private:
87 static void check_file_exists(const std::string& path);
88
90
100 const HerbivoreData* get_hft_data(const Datapoint* datapoint,
101 const std::string& hft_name) const;
102
104
110 void start_row(const Datapoint& datapoint, std::ofstream& table);
111
113
121 void write_captions(const Datapoint& datapoint);
122
124 bool captions_written = false;
125
127 std::vector<std::ofstream*> file_streams;
128
130 const std::set<std::string> hft_names;
131
134
137
139 std::ofstream available_forage;
140 std::ofstream body_fat;
141 std::ofstream digestibility;
142 std::ofstream eaten_forage_per_ind;
144 std::ofstream individual_density;
145 std::ofstream mass_density;
146 std::ofstream mass_density_per_hft; // deprecated
147 // Add new output variables here (alphabetical order). // File Streams
149};
150} // namespace Output
151} // namespace Fauna
152
153#endif // FAUNA_OUTPUT_TEXT_TABLE_WRITER_H
Writes output data to tabular plaintext files.
Definition: text_table_writer.h:33
static const char * NA_VALUE
String to print for values that are not available (NA).
Definition: text_table_writer.h:77
bool captions_written
Whether column captions have already been written to file.
Definition: text_table_writer.h:124
static const char FIELD_SEPARATOR
Character to separate columns.
Definition: text_table_writer.h:80
std::ofstream eaten_forage_per_ind
Definition: text_table_writer.h:142
const std::set< std::string > hft_names
List of Hft names (Fauna::Hft::name) in constant order.
Definition: text_table_writer.h:130
virtual void write_datapoint(const Datapoint &datapoint)
Append spatially & temporally aggregated output data to table files.
Definition: text_table_writer.cpp:141
const TextTableWriterOptions options
User options from the instruction file.
Definition: text_table_writer.h:136
const OutputInterval interval
User-selected utput interval.
Definition: text_table_writer.h:133
std::ofstream available_forage
Definition: text_table_writer.h:139
void start_row(const Datapoint &datapoint, std::ofstream &table)
Create a new row by writing year/month/day and aggregation unit.
Definition: text_table_writer.cpp:108
static void check_file_exists(const std::string &path)
Throw an exception if output file already exists.
Definition: text_table_writer.cpp:90
std::ofstream individual_density
Definition: text_table_writer.h:144
std::vector< std::ofstream * > file_streams
List of pointers to the user-selected and active file streams.
Definition: text_table_writer.h:127
std::ofstream mass_density_per_hft
Definition: text_table_writer.h:146
static const char * FILE_EXTENSION
File extension for tabular plaintext files.
Definition: text_table_writer.h:83
std::ofstream digestibility
Definition: text_table_writer.h:141
const HerbivoreData * get_hft_data(const Datapoint *datapoint, const std::string &hft_name) const
Retrieve herbivore data from datapoint for given HFT.
Definition: text_table_writer.cpp:98
std::ofstream mass_density
Definition: text_table_writer.h:145
std::ofstream eaten_nitrogen_per_ind
Definition: text_table_writer.h:143
std::ofstream body_fat
Definition: text_table_writer.h:140
void write_captions(const Datapoint &datapoint)
Write the first line in the output files: column headers.
Definition: text_table_writer.cpp:261
Definition: average.h:16
OutputInterval
Time interval for aggregating output.
Definition: parameters.h:37
Global parameters for the megafauna library.
Simple container for spatially and temporally aggregated output data.
Definition: datapoint.h:31
Herbivore output data for one time unit.
Definition: herbivore_data.h:22
Options for Fauna::Output::TextTableWriter.
Definition: text_table_writer_options.h:25
Interface class for all classes that implement writing output.
Definition: writer_interface.h:20
Abstract definition for output writing classes.