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 bool getDataWErr(int index, real *x, real *dx,
68 const real **y, const real **dy,
69 const bool **present = 0) const;
70 virtual bool requestStorage(int nframes = -1);
73 AbstractAnalysisArrayData();
76 * Returns the number of rows in the data array.
78 * This function is identical to frameCount(), except that frameCount()
79 * returns 0 before valuesReady() has been called.
81 int rowCount() const { return _nrows; }
83 * Sets the number of columns in the data array.
85 * Cannot be called after allocateValues().
87 void setColumnCount(int ncols);
89 * Sets the number of rows in the data array.
91 * Cannot be called after allocateValues().
93 void setRowCount(int nrows);
95 * Allocates memory for the values.
97 * setColumnCount() and setRowCount() must have been called.
99 void allocateValues();
100 //! Returns the x value of the first frame.
101 real xstart() const { return _xstart; }
102 //! Returns the step between frame x values.
103 real xstep() const { return _xstep; }
105 * Sets the values reported as x values for frames.
107 void setXAxis(real start, real step);
108 //! Returns a reference to a given array element.
109 real &value(int row, int col)
111 GMX_ASSERT(row >= 0 && row < _nrows, "Row index out of range");
112 GMX_ASSERT(col >= 0 && col < columnCount(), "Column index out of range");
113 GMX_ASSERT(_value != NULL, "Data array not allocated");
114 return _value[row * columnCount() + col];
116 //! Returns a given array element.
117 const real &value(int row, int col) const
119 GMX_ASSERT(row >= 0 && row < _nrows, "Row index out of range");
120 GMX_ASSERT(col >= 0 && col < columnCount(), "Column index out of range");
121 GMX_ASSERT(_value != NULL, "Data array not allocated");
122 return _value[row * columnCount() + col];
125 * Sets the value of an element in the array.
127 void setValue(int row, int col, real val)
129 value(row, col) = val;
132 * Notifies modules of the data.
134 * This function should be called once the values in the array
135 * have been initialized. The values should not be changed after this
136 * function has been called.
141 * Copies the contents into a new object.
143 * \param[in] src Object to copy data from.
144 * \param[in,out] dest Empty array data object to copy data to.
146 * \p dest should not have previous contents.
148 static void copyContents(const AbstractAnalysisArrayData *src,
149 AbstractAnalysisArrayData *dest);
158 // Copy and assign disallowed by base.
162 * Simple in-memory data array.
164 * This class simply exposes the protected functions of
165 * AbstractAnalysisArrayData to allow construction of simple in-memory data
166 * arrays for input into data modules.
169 * \ingroup module_analysisdata
171 class AnalysisArrayData : public AbstractAnalysisArrayData
174 AnalysisArrayData() {}
176 // TODO: These statements cause Doxygen to generate confusing
178 using AbstractAnalysisArrayData::rowCount;
179 using AbstractAnalysisArrayData::setColumnCount;
180 using AbstractAnalysisArrayData::setRowCount;
181 using AbstractAnalysisArrayData::allocateValues;
182 using AbstractAnalysisArrayData::xstart;
183 using AbstractAnalysisArrayData::xstep;
184 using AbstractAnalysisArrayData::setXAxis;
185 using AbstractAnalysisArrayData::value;
186 using AbstractAnalysisArrayData::setValue;
187 using AbstractAnalysisArrayData::valuesReady;
189 // Copy and assign disallowed by base.