21#include "pism/icemodel/IceModel.hh"
23#include "pism/util/pism_utilities.hh"
24#include "pism/util/Profiling.hh"
25#include "pism/util/io/io_helpers.hh"
36 double eps =
m_config->get_number(
"time_stepping.resolution");
39 "reporting (-save_times)");
47 auto save_times =
m_config->get_string(
"output.snapshot.times");
53 bool times_set = not save_times.empty();
55 if (filename_set ^ times_set) {
57 "you need to set both output.snapshot.file and output.snapshot.times"
58 " to save snapshots.");
61 if (not (filename_set and times_set)) {
76 std::vector<double> times =
m_time->parse_times(save_times);
80 for (
const auto &t : times) {
92 "output.snapshot.times was set, but all requested times"
93 " are outside of the modeled time interval");
97 m_log->message(2,
"PISM WARNING: snapshots file name does not have the '.nc' suffix!\n");
100 m_log->message(2,
"saving model state snapshots to '%s%s'%s\n",
105 m_log->message(2,
" times requested: %s\n", save_times.c_str());
113 double saving_after = -1.0e30;
139 profiling.
begin(
"io.snapshots");
140 std::string filename;
159 m_log->message(2,
"saving snapshot to %s at %s, for time-step goal %s\n", filename.c_str(),
176 profiling.
end(
"io.snapshots");
unsigned int m_current_snapshot
std::set< std::string > m_snapshot_vars
std::string m_snapshots_filename
void define_variables(const OutputFile &file, const std::set< VariableMetadata > &variables) const
void write_snapshot()
Writes a snapshot of the model state (if necessary)
std::set< std::string > m_spatial_vars
std::shared_ptr< Config > m_config
Configuration flags and parameters.
void define_time(const OutputFile &file, bool with_bounds=false) const
void write_run_stats(const OutputFile &file) const
std::vector< double > m_snapshot_times
MaxTimestep snapshots_max_timestep(double my_t)
Computes the maximum time-step we can take and still hit all -save_times.
std::shared_ptr< Context > m_ctx
Execution context.
std::shared_ptr< Logger > m_log
Logger.
virtual std::set< VariableMetadata > diagnostic_variables(const std::set< std::string > &variable_names) const
std::shared_ptr< OutputFile > m_snapshot_file
std::set< VariableMetadata > state_variables_diagnostics(const std::set< std::string > &variable_names) const
virtual std::set< VariableMetadata > state_variables() const
std::shared_ptr< OutputWriter > m_snapshot_writer
std::shared_ptr< Time > m_time
Time manager.
std::set< VariableMetadata > common_metadata() const
void write_state_diagnostics(const OutputFile &file, const std::set< std::string > &variable_names) const
void write_diagnostics(const OutputFile &file, const std::set< std::string > &variable_names) const
Writes variables listed in variable_names to file.
std::set< VariableMetadata > m_snapshot_file_contents
set of variables that will be written to snapshot files
virtual std::set< std::string > output_variables(const std::string &keyword)
Assembles a list of diagnostics corresponding to an output file size.
void init_snapshots()
Initializes the snapshot-saving mechanism.
void scalar_diagnostics_flush_buffers()
Flush scalar time-series.
virtual void write_state(const OutputFile &file) const
Combines the max. time step with the flag indicating if a restriction is active. Makes is possible to...
void begin(const char *name) const
void end(const char *name) const
void add_context(const std::string &message)
Add a message providing some context. This way we can (sort of) get a stack trace even though C++ exc...
#define PISM_ERROR_LOCATION
void write_config(const Config &config, const std::string &variable_name, const OutputFile &file)
MaxTimestep reporting_max_timestep(const std::vector< double > ×, double t, double eps, const std::string &description)
bool ends_with(const std::string &str, const std::string &suffix)
Returns true if str ends with suffix and false otherwise.
std::string printf(const char *format,...)
T combine(const T &a, const T &b)
std::string replace_character(const std::string &input, char from, char to)