3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
9 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
10 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
11 * Copyright (c) 2001-2009, The GROMACS development team,
12 * check out http://www.gromacs.org for more information.
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * If you want to redistribute modifications, please consider that
20 * scientific software is very special. Version control is crucial -
21 * bugs must be traceable. We will be happy to consider code for
22 * inclusion in the official distribution, but derived work must not
23 * be called official GROMACS. Details are found in the README & COPYING
24 * files - if they are missing, get the official version at www.gromacs.org.
26 * To help us fund GROMACS development, we humbly ask that you cite
27 * the papers on the package - you can find them in the top README file.
29 * For more info, check our website at http://www.gromacs.org
33 * Declares gmx::AbstractAnalysisArrayData and gmx::AnalysisArrayData.
35 * \author Teemu Murtola <teemu.murtola@cbr.su.se>
37 * \ingroup module_analysisdata
39 #ifndef GMX_ANALYSISDATA_ARRAYDATA_H
40 #define GMX_ANALYSISDATA_ARRAYDATA_H
44 #include "../fatalerror/gmxassert.h"
46 #include "abstractdata.h"
52 * Abstract base class for data objects that present in-memory data.
54 * This class implements a subclass of AbstractAnalysisData that presents an
55 * in-memory array through the AbstractAnalysisData interface. Subclasses
56 * should initialize the in-memory array through the provided protected member
60 * \ingroup module_analysisdata
62 class AbstractAnalysisArrayData : public AbstractAnalysisData
65 virtual ~AbstractAnalysisArrayData();
67 virtual int frameCount() const;
68 virtual bool getDataWErr(int index, real *x, real *dx,
69 const real **y, const real **dy,
70 const bool **present = 0) const;
71 virtual bool requestStorage(int nframes = -1);
74 AbstractAnalysisArrayData();
77 * Returns the number of rows in the data array.
79 * This function is identical to frameCount(), except that frameCount()
80 * returns 0 before valuesReady() has been called.
82 int rowCount() const { return _nrows; }
84 * Sets the number of columns in the data array.
86 void setColumnCount(int ncols);
88 * Sets the number of rows in the data array.
90 void setRowCount(int nrows);
91 //! Returns the x value of the first frame.
92 real xstart() const { return _xstart; }
93 //! Returns the step between frame x values.
94 real xstep() const { return _xstep; }
96 * Sets the values reported as x values for frames.
98 void setXAxis(real start, real step);
99 //! Returns a reference to a given array element.
100 real &value(int row, int col)
102 GMX_ASSERT(row >= 0 && row < _nrows, "Row index out of range");
103 GMX_ASSERT(col >= 0 && col < columnCount(), "Column index out of range");
104 GMX_ASSERT(_value != NULL, "Data array not allocated");
105 return _value[row * columnCount() + col];
107 //! Returns a given array element.
108 const real &value(int row, int col) const
110 GMX_ASSERT(row >= 0 && row < _nrows, "Row index out of range");
111 GMX_ASSERT(col >= 0 && col < columnCount(), "Column index out of range");
112 GMX_ASSERT(_value != NULL, "Data array not allocated");
113 return _value[row * columnCount() + col];
116 * Sets the value of an element in the array.
118 void setValue(int row, int col, real val)
120 value(row, col) = val;
123 * Notifies modules of the data.
125 * This function should be called once the values in the array
126 * have been initialized. The values should not be changed after this
127 * function has been called.
132 * Copies the contents into a new object.
134 * \param[in] src Object to copy data from.
135 * \param[in,out] dest Empty array data object to copy data to.
137 * \p dest should not have previous contents.
139 static void copyContents(const AbstractAnalysisArrayData *src,
140 AbstractAnalysisArrayData *dest);
149 // Copy and assign disallowed by base.
153 * Simple in-memory data array.
155 * This class simply exposes the protected functions of
156 * AbstractAnalysisArrayData to allow construction of simple in-memory data
157 * arrays for input into data modules.
160 * \ingroup module_analysisdata
162 class AnalysisArrayData : public AbstractAnalysisArrayData
165 AnalysisArrayData() {}
167 // TODO: These statements cause Doxygen to generate confusing
169 using AbstractAnalysisArrayData::rowCount;
170 using AbstractAnalysisArrayData::setColumnCount;
171 using AbstractAnalysisArrayData::setRowCount;
172 using AbstractAnalysisArrayData::xstart;
173 using AbstractAnalysisArrayData::xstep;
174 using AbstractAnalysisArrayData::setXAxis;
175 using AbstractAnalysisArrayData::value;
176 using AbstractAnalysisArrayData::setValue;
177 using AbstractAnalysisArrayData::valuesReady;
179 // Copy and assign disallowed by base.