tVecBundleWriter.cc - pism - [fork] customized build of PISM, the parallel ice sheet model (tillflux branch)
HTML git clone git://src.adamsgaard.dk/pism
DIR Log
DIR Files
DIR Refs
DIR LICENSE
---
tVecBundleWriter.cc (1745B)
---
1 // See here for useful changes:
2 // https://github.com/pism/pism/commit/443050f30743d6c2ef431c53e87dc6eb19a73dfd
3
4 #include <pism/util/Time.hh>
5 #include <pism/util/io/File.hh>
6 #include <pism/util/io/io_helpers.hh>
7 #include <pism/icebin/VecBundleWriter.hh>
8
9 using namespace pism;
10
11 namespace pism {
12 namespace icebin {
13
14 VecBundleWriter::VecBundleWriter(pism::IceGrid::Ptr _grid, std::string const &_fname,
15 std::vector<pism::IceModelVec const *> &_vecs)
16 : m_grid(_grid), fname(_fname), vecs(_vecs) {
17 }
18
19 void VecBundleWriter::init() {
20 pism::File file(m_grid->com,
21 fname,
22 string_to_backend(m_grid->ctx()->config()->get_string("output.format")),
23 PISM_READWRITE_MOVE,
24 m_grid->ctx()->pio_iosys_id());
25
26 io::define_time(file,
27 m_grid->ctx()->config()->get_string("time.dimension_name"),
28 m_grid->ctx()->time()->calendar(),
29 m_grid->ctx()->time()->CF_units_string(),
30 m_grid->ctx()->unit_system());
31
32 for (pism::IceModelVec const *vec : vecs) {
33 vec->define(file, PISM_DOUBLE);
34 }
35 }
36
37 /** Dump the value of the Vectors at curent PISM simulation time. */
38 void VecBundleWriter::write(double time_s) {
39 pism::File file(m_grid->com,
40 fname,
41 string_to_backend(m_grid->ctx()->config()->get_string("output.format")),
42 PISM_READWRITE, // append to file
43 m_grid->ctx()->pio_iosys_id());
44
45 io::append_time(file, m_grid->ctx()->config()->get_string("time.dimension_name"), time_s);
46
47 for (pism::IceModelVec const *vec : vecs) {
48 vec->write(file);
49 }
50 }
51
52 } // end of namespace icebin
53 } // end of namespace pism