DiagnosticTimeseries Class Reference

A class for storing and writing diagnostic time-series. More...

#include <Timeseries.hh>

Inheritance diagram for DiagnosticTimeseries:
Inheritance graph
[legend]

List of all members.

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< doublet
deque< doublev

Detailed Description

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.


Constructor & Destructor Documentation

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.

Destructor; makes sure that everything is written to a file.

Definition at line 188 of file Timeseries.cc.

References flush().


Member Function Documentation

PetscErrorCode append ( double  T,
double  V 
)

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.

References t, and v.

Referenced by IcePSTexModel.additionalAtEndTimestep(), POForcing.write_diagnostic_fields(), PAForcing.write_diagnostic_fields(), and PAForcing.write_fields().

PetscErrorCode flush (  ) 
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().


Member Data Documentation

size_t buffer_size

Definition at line 132 of file Timeseries.hh.

Referenced by DiagnosticTimeseries(), and interp().

size_t start [protected]

Definition at line 136 of file Timeseries.hh.

Referenced by DiagnosticTimeseries(), and flush().

deque<double> t [protected]

Definition at line 137 of file Timeseries.hh.

Referenced by append(), and interp().

deque<double> v [protected]

Definition at line 137 of file Timeseries.hh.

Referenced by append(), and interp().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Defines
Generated by  doxygen 1.6.2-20100124