A class for storing and writing diagnostic time-series. More...
#include <Timeseries.hh>

Public Member Functions | |
| DiagnosticTimeseries (IceGrid *g, string name, string dimension_name) | |
| DiagnosticTimeseries (MPI_Comm com, PetscMPIInt rank, string name, string dimension_name) | |
| ~DiagnosticTimeseries () | |
| Destructor; makes sure that everything is written to a file. | |
| PetscErrorCode | append (double T, double V) |
| Adds the (t,v) pair to the interpolation buffer. | |
| PetscErrorCode | interp (double time) |
Use linear interpolation to find the value of a scalar diagnostic quantity at time T and store the obtained pair (T, value). | |
| PetscErrorCode | flush () |
| Writes data to a file. | |
Public Attributes | |
| size_t | buffer_size |
| string | output_filename |
Protected Attributes | |
| size_t | start |
| deque< double > | t |
| deque< double > | v |
A class for storing and writing diagnostic time-series.
This version of Timeseries only holds buffer_size entries in memory and writes to a file every time this limit is exceeded.
Here is a usage example:
First, prepare a file for writing:
char seriesname[] = "ser_delta_T.nc"; NCTool nc(grid.com, grid.rank); nc.open_for_writing(seriesname, true, false); nc.close();
Next, create the DiagnosticTimeseries object and set metadata. This will prepare the offsets object to write delta_T(t) time-series to file ser_delta_T.nc, converting from degrees Celsius (internal units) to degrees Kelvin ("glaciological" units). Time will be written in years (i.e. there is no unit conversion there).
offsets = new DiagnosticTimeseries(g, "delta_T", "t"); offsets->set_units("Kelvin", "Celsius"); offsets->set_dimension_units("years", ""); offsets->buffer_size = 100; // only store 100 entries; default is 10000 offsets->output_filename = seriesname; offsets->set_attr("long_name", "temperature offsets from some value");
Once this is set up, one can add calls like
offsets->append(t_years, TsOffset); offsets->interp(time);
to the code. The first call will store the (t_years, TsOffset). The second call will use linear interpolation to find the value at time years. Note that the first call adds to a buffer but does not yield any output without the second call. Therefore, even if interpolation is not really needed because time==t_years, the call to interp() should still occur.
Finally, the destructor of DiagnosticTimeseries will flush(), which writes out the buffered values:
delete offsets;
Note that every time you exceed the buffer_size limit, all the entries are written to a file by flush() and removed from memory. One may also explicitly call flush().
Definition at line 122 of file Timeseries.hh.
| DiagnosticTimeseries | ( | IceGrid * | g, | |
| string | name, | |||
| string | dimension_name | |||
| ) |
Definition at line 173 of file Timeseries.cc.
References buffer_size, and start.
| DiagnosticTimeseries | ( | MPI_Comm | com, | |
| PetscMPIInt | rank, | |||
| string | name, | |||
| string | dimension_name | |||
| ) |
Definition at line 180 of file Timeseries.cc.
References buffer_size, and start.
| ~DiagnosticTimeseries | ( | ) |
Destructor; makes sure that everything is written to a file.
Definition at line 188 of file Timeseries.cc.
References flush().
Adds the (t,v) pair to the interpolation buffer.
The interpolation buffer holds 2 values only (for linear interpolation).
Reimplemented from Timeseries.
Definition at line 195 of file Timeseries.cc.
Referenced by IcePSTexModel.additionalAtEndTimestep(), POForcing.write_diagnostic_fields(), PAForcing.write_diagnostic_fields(), and PAForcing.write_fields().
| PetscErrorCode flush | ( | ) |
Writes data to a file.
Definition at line 245 of file Timeseries.cc.
References NCTool.close(), Timeseries.com, Timeseries.dimension, NCTool.get_dim_length(), vnreport.nc, NCTool.open_for_reading(), output_filename, Timeseries.rank, NCVariable.short_name, start, Timeseries.time, Timeseries.values, Timeseries.var, and NCTimeseries.write().
Referenced by interp(), POForcing.write_diagnostic_fields(), PAForcing.write_diagnostic_fields(), PAForcing.write_fields(), and ~DiagnosticTimeseries().
| PetscErrorCode interp | ( | double | time | ) |
Use linear interpolation to find the value of a scalar diagnostic quantity at time T and store the obtained pair (T, value).
Definition at line 210 of file Timeseries.cc.
References buffer_size, e, flush(), t, Timeseries.time, v, and Timeseries.values.
Referenced by IcePSTexModel.additionalAtEndTimestep(), POForcing.write_diagnostic_fields(), PAForcing.write_diagnostic_fields(), and PAForcing.write_fields().
| size_t buffer_size |
Definition at line 132 of file Timeseries.hh.
Referenced by DiagnosticTimeseries(), and interp().
| string output_filename |
Definition at line 133 of file Timeseries.hh.
Referenced by IceModel.create_timeseries(), flush(), IcePSTexModel.prepare_series(), POForcing.write_diagnostic_fields(), PAForcing.write_diagnostic_fields(), and PAForcing.write_fields().
size_t start [protected] |
Definition at line 136 of file Timeseries.hh.
Referenced by DiagnosticTimeseries(), and flush().
Definition at line 137 of file Timeseries.hh.
Definition at line 137 of file Timeseries.hh.
1.6.2-20100124