/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012,2013, by the GROMACS development team, led by
- * David van der Spoel, Berk Hess, Erik Lindahl, and including many
- * others, as listed in the AUTHORS file in the top-level source
- * directory and at http://www.gromacs.org.
+ * 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.
*
* GROMACS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* \ingroup module_analysisdata
* \author Teemu Murtola <teemu.murtola@gmail.com>
*/
-#include "gromacs/analysisdata/modules/plot.h"
+#include "gmxpre.h"
-#include <string>
-#include <vector>
+#include "plot.h"
#include <cstdio>
#include <cstring>
+#include <string>
+#include <vector>
+
#include <boost/shared_ptr.hpp>
-#include "gromacs/legacyheaders/gmxfio.h"
+#include "gromacs/analysisdata/dataframe.h"
+#include "gromacs/fileio/gmxfio.h"
+#include "gromacs/fileio/xvgr.h"
#include "gromacs/legacyheaders/oenv.h"
-#include "gromacs/legacyheaders/vec.h"
-#include "gromacs/legacyheaders/xvgr.h"
-
+#include "gromacs/math/vec.h"
#include "gromacs/options/basicoptions.h"
-#include "gromacs/analysisdata/dataframe.h"
#include "gromacs/options/options.h"
#include "gromacs/options/timeunitmanager.h"
#include "gromacs/selection/selectioncollection.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/gmxassert.h"
+#include "gromacs/utility/programcontext.h"
#include "gromacs/utility/stringutil.h"
namespace
FILE *fp_;
bool bPlain_;
- bool gOmitX_;
+ bool bOmitX_;
+ bool bErrorsAsSeparateColumn_;
std::string title_;
std::string subtitle_;
std::string xlabel_;
};
AbstractPlotModule::Impl::Impl(const AnalysisDataPlotSettings &settings)
- : settings_(settings), fp_(NULL), bPlain_(false), gOmitX_(false),
- xscale_(1.0)
+ : settings_(settings), fp_(NULL), bPlain_(false), bOmitX_(false),
+ bErrorsAsSeparateColumn_(false), xscale_(1.0)
{
strcpy(xformat_, "%11.3f");
strcpy(yformat_, " %8.3f");
}
+void
+AbstractPlotModule::setErrorsAsSeparateColumn(bool bSeparate)
+{
+ impl_->bErrorsAsSeparateColumn_ = bSeparate;
+}
+
+
void
AbstractPlotModule::setOmitX(bool bOmitX)
{
- impl_->gOmitX_ = bOmitX;
+ impl_->bOmitX_ = bOmitX;
}
}
+void
+AbstractPlotModule::appendLegend(const std::string &setname)
+{
+ impl_->legend_.push_back(setname);
+}
+
+
void
AbstractPlotModule::setXFormat(int width, int precision, char format)
{
int
AbstractPlotModule::flags() const
{
- return efAllowMulticolumn | efAllowMultipoint;
+ return efAllowMissing | efAllowMulticolumn | efAllowMultipoint
+ | efAllowMultipleDataSets;
}
void
-AbstractPlotModule::dataStarted(AbstractAnalysisData *data)
+AbstractPlotModule::dataStarted(AbstractAnalysisData * /* data */)
{
if (!impl_->filename_.empty())
{
? static_cast<xvg_format_t>(impl_->settings_.plotFormat())
: exvgNONE);
output_env_t oenv;
- output_env_init(&oenv, 0, NULL, time_unit, FALSE, xvg_format, 0, 0);
+ output_env_init(&oenv, getProgramContext(), time_unit, FALSE, xvg_format, 0);
boost::shared_ptr<output_env> oenvGuard(oenv, &output_env_done);
impl_->fp_ = xvgropen(impl_->filename_.c_str(), impl_->title_.c_str(),
impl_->xlabel_.c_str(), impl_->ylabel_.c_str(),
{
return;
}
- if (!impl_->gOmitX_)
+ if (!impl_->bOmitX_)
{
std::fprintf(impl_->fp_, impl_->xformat_, frame.x() * impl_->xscale_);
}
void
-AbstractPlotModule::writeValue(real value) const
+AbstractPlotModule::writeValue(const AnalysisDataValue &value) const
{
GMX_ASSERT(isFileOpen(), "File not opened, but write attempted");
- std::fprintf(impl_->fp_, impl_->yformat_, value);
+ const real y = value.isSet() ? value.value() : 0.0;
+ std::fprintf(impl_->fp_, impl_->yformat_, y);
+ if (impl_->bErrorsAsSeparateColumn_)
+ {
+ const real dy = value.isSet() ? value.error() : 0.0;
+ std::fprintf(impl_->fp_, impl_->yformat_, dy);
+ }
}
//! \endcond
}
for (int i = 0; i < points.columnCount(); ++i)
{
- writeValue(points.y(i));
+ writeValue(points.values()[i]);
}
}
void
AnalysisDataVectorPlotModule::pointsAdded(const AnalysisDataPointSetRef &points)
{
- if (points.firstColumn() % DIM != 0)
+ if (points.firstColumn() % DIM != 0 || points.columnCount() % DIM != 0)
{
GMX_THROW(APIError("Partial data points"));
}
{
if (bWrite_[i])
{
- writeValue(points.y(i + d));
+ writeValue(points.values()[i + d]);
}
}
if (bWrite_[DIM])
{
- rvec y = { points.y(i), points.y(i + 1), points.y(i + 2) };
- writeValue(norm(y));
+ const rvec y = { points.y(i), points.y(i + 1), points.y(i + 2) };
+ AnalysisDataValue value(norm(y));
+ writeValue(value);
}
}
}