PISM, A Parallel Ice Sheet Model  stable v2.1-1-g6902d5502 committed by Ed Bueler on 2023-12-20 08:38:27 -0800
VecBundleWriter.cc
Go to the documentation of this file.
1 // See here for useful changes:
2 // https://github.com/pism/pism/commit/443050f30743d6c2ef431c53e87dc6eb19a73dfd
3 
4 #include "pism/icebin/VecBundleWriter.hh"
5 
6 #include "pism/util/ConfigInterface.hh"
7 #include "pism/util/Context.hh"
8 #include "pism/util/Grid.hh"
9 #include "pism/util/array/Array.hh"
10 #include "pism/util/io/File.hh"
11 #include "pism/util/io/IO_Flags.hh"
12 #include "pism/util/io/io_helpers.hh"
13 #include "pism/util/Time.hh"
14 
15 using namespace pism;
16 
17 namespace pism {
18 namespace icebin {
19 
20 VecBundleWriter::VecBundleWriter(std::shared_ptr<pism::Grid> _grid, std::string const &_fname,
21  std::vector<pism::array::Array const *> &_vecs)
22  : m_grid(_grid), fname(_fname), vecs(_vecs) {
23 }
24 
26  pism::File file(m_grid->com, fname,
27  string_to_backend(m_grid->ctx()->config()->get_string("output.format")),
29 
30  io::define_time(file, m_grid->ctx()->config()->get_string("time.dimension_name"),
31  m_grid->ctx()->time()->calendar(), m_grid->ctx()->time()->units_string(),
32  m_grid->ctx()->unit_system());
33 
34  for (const auto *vec : vecs) {
35  vec->define(file, io::PISM_DOUBLE);
36  }
37 }
38 
39 /** Dump the value of the Vectors at curent PISM simulation time. */
40 void VecBundleWriter::write(double time_s) {
41  pism::File nc(m_grid->com, fname,
42  string_to_backend(m_grid->ctx()->config()->get_string("output.format")),
43  io::PISM_READWRITE); // append to file
44 
45  io::append_time(nc, m_grid->ctx()->config()->get_string("time.dimension_name"), time_s);
46 
47  for (const auto *vec : vecs) {
48  vec->write(nc);
49  }
50 }
51 
52 } // end of namespace icebin
53 } // end of namespace pism
High-level PISM I/O class.
Definition: File.hh:56
std::shared_ptr< const pism::Grid > m_grid
VecBundleWriter(std::shared_ptr< pism::Grid > grid, std::string const &_fname, std::vector< pism::array::Array const * > &_vecs)
std::vector< pism::array::Array const * > vecs
void append_time(const File &file, const Config &config, double time_seconds)
Prepare a file for output.
Definition: io_helpers.cc:247
@ PISM_READWRITE_MOVE
create a file for writing, move foo.nc to foo.nc~ if present
Definition: IO_Flags.hh:78
@ PISM_READWRITE
open an existing file for reading and writing
Definition: IO_Flags.hh:74
@ PISM_DOUBLE
Definition: IO_Flags.hh:52
void define_time(const File &file, const Context &ctx)
Prepare a file for output.
Definition: io_helpers.cc:213
io::Backend string_to_backend(const std::string &backend)
Definition: File.cc:57