20#include "pism/icemodel/IceModel.hh"
22#include "pism/util/pism_utilities.hh"
23#include "pism/util/Profiling.hh"
35 double eps =
m_config->get_number(
"time_stepping.resolution");
38 "reporting (-save_times)");
46 auto save_times =
m_config->get_string(
"output.snapshot.times");
52 bool times_set = not save_times.empty();
54 if (filename_set ^ times_set) {
56 "you need to set both output.snapshot.file and output.snapshot.times"
57 " to save snapshots.");
60 if (not (filename_set and times_set)) {
67 std::vector<double> times =
m_time->parse_times(save_times);
71 for (
const auto &t : times) {
83 "output.snapshot.times was set, but all requested times"
84 " are outside of the modeled time interval");
93 m_log->message(2,
"PISM WARNING: snapshots file name does not have the '.nc' suffix!\n");
97 m_log->message(2,
"times requested: %s\n", save_times.c_str());
105 double saving_after = -1.0e30;
131 profiling.
begin(
"io.snapshots");
132 std::string filename;
150 m_log->message(2,
"saving snapshot to %s at %s, for time-step goal %s\n", filename.c_str(),
160 profiling.
end(
"io.snapshots");
unsigned int m_current_snapshot
std::set< std::string > m_snapshot_vars
std::string m_snapshots_filename
VariableMetadata run_stats() const
void write_snapshot()
Writes a snapshot of the model state (if necessary)
const Time::Ptr m_time
Time manager.
std::vector< double > m_snapshot_times
std::shared_ptr< Context > m_ctx
Execution context.
const Logger::Ptr m_log
Logger.
void flush_timeseries()
Flush scalar time-series.
Config::Ptr m_config
Configuration flags and parameters.
virtual void save_variables(const File &file, OutputKind kind, const std::set< std::string > &variables, double time, io::Type default_diagnostics_type=io::PISM_FLOAT) const
std::shared_ptr< File > m_snapshot_file
virtual std::set< std::string > output_variables(const std::string &keyword)
Assembles a list of diagnostics corresponding to an output file size.
MaxTimestep save_max_timestep(double my_t)
Computes the maximum time-step we can take and still hit all -save_times.
void init_snapshots()
Initializes the snapshot-saving mechanism.
virtual void write_metadata(const File &file, MappingTreatment mapping_flag, HistoryTreatment history_flag) const
Write time-independent metadata to a file.
const std::shared_ptr< Grid > m_grid
Computational grid.
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
@ PISM_READWRITE_MOVE
create a file for writing, move foo.nc to foo.nc~ if present
MaxTimestep reporting_max_timestep(const std::vector< double > ×, double t, double eps, const std::string &description)
io::Backend string_to_backend(const std::string &backend)
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,...)
std::string replace_character(const std::string &input, char from, char to)
void write_run_stats(const File &file, const pism::VariableMetadata &stats)