Sort all includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / analysisdata / arraydata.cpp
index edf0e4b28248de3b37c63bfc7bcb9a69dda2642e..60d4c89cfd906f28eed43237355de96d97c0ca90 100644 (file)
@@ -1,45 +1,52 @@
 /*
+ * 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.
  */
 /*! \internal \file
  * \brief
  * Implements classes in arraydata.h.
  *
- * \author Teemu Murtola <teemu.murtola@cbr.su.se>
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
  * \ingroup module_analysisdata
  */
-#include "gromacs/analysisdata/arraydata.h"
+#include "gmxpre.h"
+
+#include "arraydata.h"
 
 #include <algorithm>
 
 #include "gromacs/analysisdata/dataframe.h"
+#include "gromacs/analysisdata/datamodulemanager.h"
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/gmxassert.h"
 
@@ -47,8 +54,10 @@ namespace gmx
 {
 
 AbstractAnalysisArrayData::AbstractAnalysisArrayData()
-    : rowCount_(0), xstart_(0.0), xstep_(1.0), bReady_(false)
+    : rowCount_(0), pointSetInfo_(0, 0, 0, 0), xstep_(1.0),
+      bUniformX_(true), bReady_(false)
 {
+    xvalue_.push_back(0);
 }
 
 AbstractAnalysisArrayData::~AbstractAnalysisArrayData()
@@ -66,8 +75,9 @@ AbstractAnalysisArrayData::tryGetDataFrameInternal(int index) const
     std::vector<AnalysisDataValue>::const_iterator begin
         = value_.begin() + index * columnCount();
     return AnalysisDataFrameRef(
-                AnalysisDataFrameHeader(index, xvalue(index), 0.0),
-                AnalysisDataValuesRef(begin, begin + columnCount()));
+            AnalysisDataFrameHeader(index, xvalue(index), 0.0),
+            constArrayRefFromVector<AnalysisDataValue>(begin, begin + columnCount()),
+            constArrayRefFromArray(&pointSetInfo_, 1));
 }
 
 
@@ -83,7 +93,8 @@ AbstractAnalysisArrayData::setColumnCount(int ncols)
 {
     GMX_RELEASE_ASSERT(!isAllocated(),
                        "Cannot change column count after data has been allocated");
-    AbstractAnalysisData::setColumnCount(ncols);
+    AbstractAnalysisData::setColumnCount(0, ncols);
+    pointSetInfo_ = AnalysisDataPointSetInfo(0, ncols, 0, 0);
 }
 
 
@@ -93,6 +104,17 @@ AbstractAnalysisArrayData::setRowCount(int rowCount)
     GMX_RELEASE_ASSERT(rowCount > 0, "Invalid number of rows");
     GMX_RELEASE_ASSERT(!isAllocated(),
                        "Cannot change row count after data has been allocated");
+    GMX_RELEASE_ASSERT(bUniformX_ || rowCount_ == 0
+                       || rowCount == static_cast<int>(xvalue_.size()),
+                       "X axis set with setXAxisValue() does not match the row count");
+    xvalue_.resize(rowCount);
+    if (bUniformX_ && rowCount > rowCount_)
+    {
+        for (int i = rowCount_; i < rowCount; ++i)
+        {
+            xvalue_[i] = xvalue_[0] + i * xstep_;
+        }
+    }
     rowCount_ = rowCount;
 }
 
@@ -116,8 +138,31 @@ void
 AbstractAnalysisArrayData::setXAxis(real start, real step)
 {
     GMX_RELEASE_ASSERT(!bReady_, "X axis cannot be set after data is finished");
-    xstart_ = start;
-    xstep_ = step;
+    xvalue_[0] = start;
+    xstep_     = step;
+    bUniformX_ = true;
+    for (int i = 0; i < rowCount_; ++i)
+    {
+        xvalue_[i] = start + i * xstep_;
+    }
+}
+
+
+void
+AbstractAnalysisArrayData::setXAxisValue(int row, real value)
+{
+    GMX_RELEASE_ASSERT(!bReady_, "X axis cannot be set after data is finished");
+    if (rowCount_ > 0)
+    {
+        GMX_RELEASE_ASSERT(row >= 0 && row < rowCount(), "Row index out of range");
+    }
+    else if (row >= static_cast<int>(xvalue_.size()))
+    {
+        xvalue_.resize(row + 1);
+    }
+    bUniformX_   = false;
+    xstep_       = 0.0;
+    xvalue_[row] = value;
 }
 
 
@@ -132,23 +177,26 @@ AbstractAnalysisArrayData::valuesReady()
     bReady_ = true;
 
     std::vector<AnalysisDataValue>::const_iterator valueIter = value_.begin();
-    notifyDataStart();
+    AnalysisDataModuleManager                     &modules   = moduleManager();
+    modules.notifyDataStart(this);
     for (int i = 0; i < rowCount(); ++i, valueIter += columnCount())
     {
         AnalysisDataFrameHeader header(i, xvalue(i), 0);
-        notifyFrameStart(header);
-        notifyPointsAdd(AnalysisDataPointSetRef(header, 0,
-                            AnalysisDataValuesRef(valueIter,
-                                                  valueIter + columnCount())));
-        notifyFrameFinish(header);
+        modules.notifyFrameStart(header);
+        modules.notifyPointsAdd(
+                AnalysisDataPointSetRef(
+                        header, pointSetInfo_,
+                        constArrayRefFromVector<AnalysisDataValue>(valueIter,
+                                                                   valueIter + columnCount())));
+        modules.notifyFrameFinish(header);
     }
-    notifyDataFinish();
+    modules.notifyDataFinish();
 }
 
 
 void
 AbstractAnalysisArrayData::copyContents(const AbstractAnalysisArrayData *src,
-                                        AbstractAnalysisArrayData *dest)
+                                        AbstractAnalysisArrayData       *dest)
 {
     GMX_RELEASE_ASSERT(src->isAllocated(), "Source data must not be empty");
     GMX_RELEASE_ASSERT(!dest->isAllocated(),
@@ -156,7 +204,9 @@ AbstractAnalysisArrayData::copyContents(const AbstractAnalysisArrayData *src,
     dest->setColumnCount(src->columnCount());
     dest->setRowCount(src->rowCount());
     dest->allocateValues();
-    dest->setXAxis(src->xstart(), src->xstep());
+    dest->xstep_     = src->xstep_;
+    dest->bUniformX_ = src->bUniformX_;
+    std::copy(src->xvalue_.begin(), src->xvalue_.end(), dest->xvalue_.begin());
     std::copy(src->value_.begin(), src->value_.end(), dest->value_.begin());
 }