20 #include "pism/icemodel/IceModel.hh"
22 #include "pism/util/pism_utilities.hh"
23 #include "pism/util/Profiling.hh"
31 (not
m_config->get_flag(
"time_stepping.hit_save_times"))) {
35 double eps =
m_config->get_number(
"time_stepping.resolution");
38 "reporting (-save_times)");
48 auto save_times =
m_config->get_string(
"output.snapshot.times");
49 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 not times_set) {
68 std::vector<double> times =
m_time->parse_times(save_times);
72 for (
const auto &t : times) {
73 if (t >=
m_time->start() and t <= m_time->end()) {
84 "output.snapshot.times was set, but all requested times"
85 " are outside of the modeled time interval");
96 "PISM WARNING: snapshots file name does not have the '.nc' suffix!\n");
100 m_log->message(2,
"saving snapshots to '%s+year.nc'; ",
103 m_log->message(2,
"saving snapshots to '%s'; ",
107 m_log->message(2,
"times requested: %s\n", save_times.c_str());
112 double saving_after = -1.0e30;
117 std::string filename;
146 date_without_spaces.c_str());
152 "saving snapshot to %s at %s, for time-step goal %s\n",
153 filename.c_str(),
m_time->date(
m_time->current()).c_str(),
154 m_time->date(saving_after).c_str());
158 profiling.
begin(
"io.snapshots");
165 m_ctx->pio_iosys_id());
177 profiling.
end(
"io.snapshots");
High-level PISM I/O class.
unsigned int m_current_snapshot
std::set< std::string > m_snapshot_vars
std::string m_snapshots_filename
VariableMetadata run_stats() const
const Config::Ptr m_config
Configuration flags and parameters.
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
const std::shared_ptr< Context > m_ctx
Execution context.
const Logger::Ptr m_log
Logger.
void flush_timeseries()
Flush scalar time-series.
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
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.
bool m_snapshots_file_is_ready
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
@ PISM_READWRITE
open an existing file for reading and writing
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)
std::vector< std::string > split(const std::string &input, char separator)
Transform a separator-separated list (a string) into a vector of strings.