tTimeseries.hh - 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
---
tTimeseries.hh (3898B)
---
1 // Copyright (C) 2009, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Constantine Khroulev
2 //
3 // This file is part of PISM.
4 //
5 // PISM is free software; you can redistribute it and/or modify it under the
6 // terms of the GNU General Public License as published by the Free Software
7 // Foundation; either version 3 of the License, or (at your option) any later
8 // version.
9 //
10 // PISM is distributed in the hope that it will be useful, but WITHOUT ANY
11 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with PISM; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 #ifndef __Timeseries_hh
20 #define __Timeseries_hh
21
22 #include <deque>
23 #include <mpi.h>
24
25 #include "VariableMetadata.hh"
26
27 namespace pism {
28
29 class IceGrid;
30 class File;
31 class Time;
32 class Logger;
33
34 //! \brief A general class for reading and accessing time-series.
35 /*!
36 \section timeseries_overview Scalar time-series
37
38 This class provides random access to time-series values. It is used to
39 implement forcing with scalar time-dependent parameters (such as
40 paleo-climate forcing).
41
42 Note that every processor stores the whole time-series and calling append()
43 repeatedly will use a lot of memory.
44
45 Please use DiagnosticTimeseries to output long time-series.
46
47 \subsection timeseries_example An example
48
49 The following snippet from PAForcing::init() illustrates creating a Timeseries
50 object and reading data from a file.
51
52 \code
53 delta_T = new Timeseries(grid.com, grid.rank, "delta_T", "time");
54 ierr = delta_T->set_string("units", "Kelvin", ""); CHKERRQ(ierr);
55 ierr = delta_T->set_dimension_units("years", ""); CHKERRQ(ierr);
56 ierr = delta_T->set_attr("long_name", "near-surface air temperature offsets");
57 CHKERRQ(ierr);
58
59 ierr = delta_T->read(dT_file); CHKERRQ(ierr);
60 \endcode
61
62 Call
63 \code
64 double offset = (*delta_T)(time);
65 \endcode
66 to get the value corresponding to the time "time", in this case in years. The
67 value returned will be computed using linear interpolation.
68
69 It is also possible to get an n-th value from a time-series: just use square brackets:
70 \code
71 double offset = (*delta_T)[10];
72 \endcode
73 */
74 class Timeseries {
75 public:
76 Timeseries(const IceGrid &g, const std::string &name, const std::string &dimension_name);
77 Timeseries(MPI_Comm com, units::System::Ptr units_system,
78 const std::string &name, const std::string &dimension_name);
79
80 void read(const File &nc, const Time &time_manager, const Logger &log);
81 void write(const File &nc) const;
82 double operator()(double time) const;
83 double operator[](unsigned int j) const;
84 double average(double t, double dt, unsigned int N) const;
85 void append(double value, double a, double b);
86
87 void reset();
88
89 TimeseriesMetadata& variable();
90 TimeseriesMetadata& dimension();
91 TimeBoundsMetadata& bounds();
92
93 const TimeseriesMetadata& variable() const;
94 const TimeseriesMetadata& dimension() const;
95 const TimeBoundsMetadata& bounds() const;
96
97 const std::vector<double> ×() const;
98 const std::vector<double> &time_bounds() const;
99 const std::vector<double> &values() const;
100
101 void scale(double scaling_factor);
102
103 std::string name() const;
104
105 bool get_use_bounds() const;
106 void set_use_bounds(bool flag);
107
108 private:
109 MPI_Comm m_com;
110
111 bool m_use_bounds;
112
113 TimeseriesMetadata m_dimension;
114 TimeseriesMetadata m_variable;
115 TimeBoundsMetadata m_bounds;
116
117 std::vector<double> m_time;
118 std::vector<double> m_values;
119 std::vector<double> m_time_bounds;
120
121 void set_bounds_units();
122 void private_constructor(MPI_Comm com, const std::string &dimension_name);
123 void report_range(const Logger &log);
124 };
125
126 } // end of namespace pism
127
128 #endif // __Timeseries_hh