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 * Implements classes in arraydata.h.
35 * \author Teemu Murtola <teemu.murtola@cbr.su.se>
36 * \ingroup module_analysisdata
38 #include "gromacs/analysisdata/arraydata.h"
43 #include "gromacs/fatalerror/exceptions.h"
44 #include "gromacs/fatalerror/gmxassert.h"
49 AbstractAnalysisArrayData::AbstractAnalysisArrayData()
50 : _nrows(0), _value(NULL), _xstart(0.0), _xstep(1.0), _bReady(false)
54 AbstractAnalysisArrayData::~AbstractAnalysisArrayData()
61 AbstractAnalysisArrayData::getDataWErr(int index, real *x, real *dx,
62 const real **y, const real **dy,
63 const bool **present) const
73 if (index >= frameCount())
79 *x = _xstart + index * _xstep;
87 *y = _value + (index * columnCount());
104 AbstractAnalysisArrayData::requestStorage(int /*nframes*/)
111 AbstractAnalysisArrayData::setColumnCount(int ncols)
113 GMX_RELEASE_ASSERT(!_value,
114 "Cannot change column count after data has been allocated");
115 AbstractAnalysisData::setColumnCount(ncols);
120 AbstractAnalysisArrayData::setRowCount(int nrows)
122 GMX_RELEASE_ASSERT(nrows > 0, "Invalid number of rows");
123 GMX_RELEASE_ASSERT(!_value,
124 "Cannot change row count after data has been allocated");
130 AbstractAnalysisArrayData::allocateValues()
132 GMX_RELEASE_ASSERT(_value == NULL, "Can only allocate values once");
133 GMX_RELEASE_ASSERT(rowCount() > 0 && columnCount() > 0,
134 "Row and column counts must be set before allocating values");
135 snew(_value, rowCount() * columnCount());
140 AbstractAnalysisArrayData::setXAxis(real start, real step)
142 GMX_RELEASE_ASSERT(!_bReady, "X axis cannot be set after data is finished");
149 AbstractAnalysisArrayData::valuesReady()
151 GMX_RELEASE_ASSERT(columnCount() > 0 && _nrows > 0 && _value,
152 "There must be some data");
160 for (int i = 0; i < _nrows; ++i)
162 notifyFrameStart(_xstart + i * _xstep, 0);
163 notifyPointsAdd(0, columnCount(), _value + (i * columnCount()),
172 AbstractAnalysisArrayData::copyContents(const AbstractAnalysisArrayData *src,
173 AbstractAnalysisArrayData *dest)
175 GMX_RELEASE_ASSERT(src->columnCount() > 0 && src->_nrows > 0 && src->_value,
176 "Source data must not be empty");
177 GMX_RELEASE_ASSERT(!dest->_value, "Destination data must not be allocated");
178 dest->setColumnCount(src->columnCount());
179 dest->setRowCount(src->_nrows);
180 dest->allocateValues();
181 dest->setXAxis(src->_xstart, src->_xstep);
182 for (int i = 0; i < src->_nrows * src->columnCount(); ++i)
184 dest->_value[i] = src->_value[i];