Sort all includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / analysisdata / arraydata.h
index cc336b2031cef0002c1bd012afeebf6b5f6aa170..f255ae70f612e34f2e1dd7829fbccbdcb97854c0 100644 (file)
@@ -1,38 +1,42 @@
 /*
+ * This file is part of the GROMACS molecular simulation package.
  *
- *                This source code is part of
+ * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
  *
- *                 G   R   O   M   A   C   S
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
  *
- *          GROningen MAchine for Chemical Simulations
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
  *
- * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2009, The GROMACS development team,
- * check out http://www.gromacs.org for more information.
-
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
  *
- * If you want to redistribute modifications, please consider that
- * scientific software is very special. Version control is crucial -
- * bugs must be traceable. We will be happy to consider code for
- * inclusion in the official distribution, but derived work must not
- * be called official GROMACS. Details are found in the README & COPYING
- * files - if they are missing, get the official version at www.gromacs.org.
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
  *
  * To help us fund GROMACS development, we humbly ask that you cite
- * the papers on the package - you can find them in the top README file.
- *
- * For more info, check our website at http://www.gromacs.org
+ * the research papers on the package. Check out http://www.gromacs.org.
  */
 /*! \file
  * \brief
  * Declares gmx::AbstractAnalysisArrayData and gmx::AnalysisArrayData.
  *
- * \author Teemu Murtola <teemu.murtola@cbr.su.se>
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
  * \inpublicapi
  * \ingroup module_analysisdata
  */
 
 #include <vector>
 
-#include "../utility/gmxassert.h"
-
-#include "abstractdata.h"
-#include "dataframe.h"
+#include "gromacs/analysisdata/abstractdata.h"
+#include "gromacs/analysisdata/dataframe.h"
+#include "gromacs/utility/gmxassert.h"
 
 namespace gmx
 {
@@ -62,7 +65,7 @@ namespace gmx
  * accessed before it is available.
  *
  * \todo
- * Add methods to take full advantage of AnalysisDataValue features.
+ * Add support for multiple data sets.
  *
  * \inlibraryapi
  * \ingroup module_analysisdata
@@ -72,32 +75,41 @@ class AbstractAnalysisArrayData : public AbstractAnalysisData
     public:
         virtual ~AbstractAnalysisArrayData();
 
+        virtual int frameCount() const
+        {
+            return bReady_ ? rowCount_ : 0;
+        }
+
         /*! \brief
          * Returns the number of rows in the data array.
          *
          * This function is identical to frameCount(), except that frameCount()
          * returns 0 before valuesReady() has been called.
          */
-        int rowCount() const { return _nrows; }
+        int rowCount() const { return rowCount_; }
         //! Returns true if values have been allocated.
-        bool isAllocated() const { return !_value.empty(); }
+        bool isAllocated() const { return !value_.empty(); }
         //! Returns the x value of the first frame.
-        real xstart() const { return _xstart; }
+        real xstart() const { return xvalue_[0]; }
         //! Returns the step between frame x values.
-        real xstep() const { return _xstep; }
+        real xstep() const
+        {
+            GMX_ASSERT(bUniformX_, "Accessing x step for non-uniform data");
+            return xstep_;
+        }
         //! Returns the x value of a row.
         real xvalue(int row) const
         {
             GMX_ASSERT(row >= 0 && row < rowCount(), "Row index out of range");
-            return xstart() + row * xstep();
+            return xvalue_[row];
         }
         //! Returns a given array element.
-        real value(int row, int col) const
+        const AnalysisDataValue &value(int row, int col) const
         {
             GMX_ASSERT(row >= 0 && row < rowCount(), "Row index out of range");
             GMX_ASSERT(col >= 0 && col < columnCount(), "Column index out of range");
             GMX_ASSERT(isAllocated(), "Data array not allocated");
-            return _value[row * columnCount() + col].value();
+            return value_[row * columnCount() + col];
         }
 
     protected:
@@ -121,13 +133,13 @@ class AbstractAnalysisArrayData : public AbstractAnalysisData
         /*! \brief
          * Sets the number of rows in the data array.
          *
-         * \param[in] nrows  Number of rows in the data.
+         * \param[in] rowCount  Number of rows in the data.
          *
          * Cannot be called after allocateValues().
          *
          * Does not throw.
          */
-        void setRowCount(int nrows);
+        void setRowCount(int rowCount);
         /*! \brief
          * Allocates memory for the values.
          *
@@ -145,30 +157,29 @@ class AbstractAnalysisArrayData : public AbstractAnalysisData
          * \param[in] step   Step between x values of successive frames.
          *
          * Must not be called after valuesReady().
+         * Any values set with setXAxisValue() are overwritten.
          *
          * Does not throw.
          */
         void setXAxis(real start, real step);
-        //! Returns a reference to a given array element.
-        real &value(int row, int col)
-        {
-            GMX_ASSERT(row >= 0 && row < rowCount(), "Row index out of range");
-            GMX_ASSERT(col >= 0 && col < columnCount(), "Column index out of range");
-            GMX_ASSERT(isAllocated(), "Data array not allocated");
-            return _value[row * columnCount() + col].value();
-        }
         /*! \brief
-         * Sets the value of an element in the array.
+         * Sets a single value reported as x value for frames.
+         *
+         * \param[in] row    Row/frame for which to set the value.
+         * \param[in] value  x value for the frame specified by \p row.
          *
-         * \param[in] row  Zero-based row index for the value.
-         * \param[in] col  Zero-based column index for the value.
-         * \param[in] val  Value to set in the given location.
+         * Must not be called after valuesReady().
          *
          * Does not throw.
          */
-        void setValue(int row, int col, real val)
+        void setXAxisValue(int row, real value);
+        //! Returns a reference to a given array element.
+        AnalysisDataValue &value(int row, int col)
         {
-            value(row, col) = val;
+            GMX_ASSERT(row >= 0 && row < rowCount(), "Row index out of range");
+            GMX_ASSERT(col >= 0 && col < columnCount(), "Column index out of range");
+            GMX_ASSERT(isAllocated(), "Data array not allocated");
+            return value_[row * columnCount() + col];
         }
         /*! \brief
          * Notifies modules of the data.
@@ -192,17 +203,19 @@ class AbstractAnalysisArrayData : public AbstractAnalysisData
          * \p dest should not have previous contents.
          */
         static void copyContents(const AbstractAnalysisArrayData *src,
-                                 AbstractAnalysisArrayData *dest);
+                                 AbstractAnalysisArrayData       *dest);
 
     private:
         virtual AnalysisDataFrameRef tryGetDataFrameInternal(int index) const;
         virtual bool requestStorageInternal(int nframes);
 
-        int                  _nrows;
-        std::vector<AnalysisDataValue> _value;
-        real                 _xstart;
-        real                 _xstep;
-        bool                 _bReady;
+        int                            rowCount_;
+        AnalysisDataPointSetInfo       pointSetInfo_;
+        std::vector<AnalysisDataValue> value_;
+        std::vector<real>              xvalue_;
+        real                           xstep_;
+        bool                           bUniformX_;
+        bool                           bReady_;
 
         // Copy and assign disallowed by base.
 };
@@ -240,8 +253,8 @@ class AnalysisArrayData : public AbstractAnalysisArrayData
         using AbstractAnalysisArrayData::setRowCount;
         using AbstractAnalysisArrayData::allocateValues;
         using AbstractAnalysisArrayData::setXAxis;
+        using AbstractAnalysisArrayData::setXAxisValue;
         using AbstractAnalysisArrayData::value;
-        using AbstractAnalysisArrayData::setValue;
         using AbstractAnalysisArrayData::valuesReady;
 
         // Copy and assign disallowed by base.