19 #include <gsl/gsl_interp.h>
24 #include "pism/icemodel/IceModel.hh"
26 #include "pism/util/Grid.hh"
27 #include "pism/util/ConfigInterface.hh"
28 #include "pism/util/Diagnostic.hh"
29 #include "pism/util/Time.hh"
30 #include "pism/util/io/File.hh"
32 #include "pism/util/io/io_helpers.hh"
33 #include "pism/util/Profiling.hh"
34 #include "pism/util/pism_utilities.hh"
35 #include "pism/util/projection.hh"
36 #include "pism/util/Component.hh"
43 const std::string &description) {
45 const size_t N = times.size();
46 if (t >= times.back()) {
55 j = gsl_interp_bsearch(times.data(), t, 0, N - 1);
58 dt = times[j + 1] - t;
62 if (dt < resolution) {
86 tmp[
"history"] = std::string(tmp[
"history"]) + old_history;
103 "PISM done. Performance stats: %.4f wall clock hours, %.4f proc.-hours, %.4f model years per proc.-hour.",
104 (
double)stats[
"wall_clock_hours"],
105 (
double)stats[
"processor_hours"],
106 (
double)stats[
"model_years_per_processor_hour"]);
111 std::string filename =
m_config->get_string(
"output.file");
113 if (filename.empty()) {
114 m_log->message(2,
"WARNING: output.file is empty. Using unnamed.nc instead.\n");
115 filename =
"unnamed.nc";
120 "PISM WARNING: output file name does not have the '.nc' suffix!\n");
125 profiling.
begin(
"io.model_state");
126 if (
m_config->get_string(
"output.size") !=
"none") {
127 m_log->message(2,
"Writing model state to file `%s'...\n", filename.c_str());
132 m_ctx->pio_iosys_id());
141 profiling.
end(
"io.model_state");
146 const auto &mapping = info.
mapping;
147 std::string name = mapping.
get_name();
148 if (mapping.has_attributes()) {
155 std::string proj = info.
proj;
156 if (not proj.empty()) {
171 const std::set<std::string> &variables,
173 io::Type default_diagnostics_type)
const {
184 m_config->get_string(
"time.dimension_name"),
207 std::set<std::string> var_names;
209 for (
unsigned int k = 0;
k < n_vars; ++
k) {
214 if (
member(
"lat", var_names) and
member(
"lon", var_names)) {
217 for (
const auto& v : var_names) {
218 std::set<std::string> dims;
223 if (not
member(v, {
"lat",
"lon",
"lat_bnds",
"lon_bnds"}) and
231 if (
member(
"lat_bnds", var_names) and
member(
"lon_bnds", var_names)) {
246 size_t start = time_length > 0 ?
static_cast<size_t>(time_length - 1) : 0;
254 for (
const auto& variable : variables) {
258 diag->second->define(file, default_type);
266 for (
const auto& variable : variables) {
270 diag->second->compute()->write(file);
281 m.second->define_model_state(file);
285 d.second->define_state(file);
295 m.second->write_model_state(file);
299 d.second->write_state(file);
unsigned int nvariables() const
void set_compression_level(int level) const
VariableLookupData find_variable(const std::string &short_name, const std::string &std_name) const
Find a variable using its standard name and/or short name.
std::string variable_name(unsigned int id) const
void define_variable(const std::string &name, io::Type nctype, const std::vector< std::string > &dims) const
Define a variable.
void write_attribute(const std::string &var_name, const std::string &att_name, io::Type nctype, const std::vector< double > &values) const
Write a multiple-valued double attribute.
unsigned int dimension_length(const std::string &name) const
Get the length of a dimension.
std::vector< std::string > dimensions(const std::string &variable_name) const
std::string read_text_attribute(const std::string &var_name, const std::string &att_name) const
Get a text attribute.
High-level PISM I/O class.
std::map< std::string, const Component * > m_submodels
the list of sub-models, for writing model states and obtaining diagnostics
virtual void define_diagnostics(const File &file, const std::set< std::string > &variables, io::Type default_type) const
VariableMetadata m_timestamp
VariableMetadata run_stats() const
const Config::Ptr m_config
Configuration flags and parameters.
const Time::Ptr m_time
Time manager.
const std::shared_ptr< Context > m_ctx
Execution context.
virtual void save_results()
Save model state in NetCDF format.
const Logger::Ptr m_log
Logger.
VariableMetadata m_output_global_attributes
stores global attributes saved in a PISM output file
virtual void prepend_history(const std::string &string)
Get time and user/host name and add it to the given string.
virtual void write_model_state(const File &file) const
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 void define_model_state(const File &file) const
std::set< array::Array * > m_model_state
virtual void write_diagnostics(const File &file, const std::set< std::string > &variables) const
Writes variables listed in vars to filename, using nctype to write fields stored in dedicated Arrays.
std::map< std::string, Diagnostic::Ptr > m_diagnostics
Requested spatially-variable diagnostics.
virtual void write_metadata(const File &file, MappingTreatment mapping_flag, HistoryTreatment history_flag) const
Write time-independent metadata to a file.
std::set< std::string > m_output_vars
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 append_time(const File &file, const Config &config, double time_seconds)
Prepare a file for output.
@ PISM_READWRITE_MOVE
create a file for writing, move foo.nc to foo.nc~ if present
void write_attributes(const File &file, const VariableMetadata &variable, io::Type nctype)
Write variable attributes to a NetCDF file.
void write_timeseries(const File &file, const VariableMetadata &metadata, size_t t_start, const std::vector< double > &data)
Write a time-series data to a file.
void define_time(const File &file, const Context &ctx)
Prepare a file for output.
void define_timeseries(const VariableMetadata &var, const std::string &dimension_name, const File &file, io::Type nctype)
Define a NetCDF variable corresponding to a time-series.
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)
void write_mapping(const File &file, const pism::MappingInfo &info)
double wall_clock_hours(MPI_Comm com, double start_time)
Return time since the beginning of the run, in hours.
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,...)
bool member(const std::string &string, const std::set< std::string > &set)
void write_run_stats(const File &file, const pism::VariableMetadata &stats)