Remove rest of OptionsGlobalProperties.
authorTeemu Murtola <teemu.murtola@gmail.com>
Fri, 10 Feb 2012 19:58:58 +0000 (21:58 +0200)
committerTeemu Murtola <teemu.murtola@gmail.com>
Mon, 20 Feb 2012 18:26:43 +0000 (20:26 +0200)
Replaced plot type handling with a separate AnalysisDataPlotSettings
class, which is now declared in the same module where the actual
plotting is implemented.

Interaction with the existing output_env_t structure (that is needed for
passing to legacy methods) could be improved, but that is internal and
local to a few classes, so it's easy to fix later.

Also fixed a MSVC-specific warning in basicoptions.cpp that for some
reason appeared, although that part of the code was not touched.

Part of issue #839.

Change-Id: I5a18f5730f915578ff4661b48ec36b07d9cee35c

20 files changed:
share/template/template.cpp
src/gromacs/analysisdata/modules/plot-impl.h
src/gromacs/analysisdata/modules/plot.cpp
src/gromacs/analysisdata/modules/plot.h
src/gromacs/options.h
src/gromacs/options/basicoptions.cpp
src/gromacs/options/globalproperties.cpp [deleted file]
src/gromacs/options/globalproperties.h [deleted file]
src/gromacs/options/options-impl.h
src/gromacs/options/options.cpp
src/gromacs/options/options.h
src/gromacs/selection/tests/selectionoption.cpp
src/gromacs/trajectoryanalysis/analysissettings-impl.h
src/gromacs/trajectoryanalysis/analysissettings.cpp
src/gromacs/trajectoryanalysis/analysissettings.h
src/gromacs/trajectoryanalysis/cmdlinerunner.cpp
src/gromacs/trajectoryanalysis/modules/angle.cpp
src/gromacs/trajectoryanalysis/modules/distance.cpp
src/gromacs/trajectoryanalysis/modules/select.cpp
src/gromacs/trajectoryanalysis/runnercommon.cpp

index 432610199339e86ce22caf96b82e9237d983db99..5a7b5c7bf41aa855379dacfc91769c7351c0bdf8 100644 (file)
@@ -159,10 +159,11 @@ AnalysisTemplate::initAnalysis(const TrajectoryAnalysisSettings &settings,
 
     if (!_fnDist.empty())
     {
-        AnalysisDataPlotModule *plotm = new AnalysisDataPlotModule(_options);
+        AnalysisDataPlotModule *plotm
+            = new AnalysisDataPlotModule(settings.plotSettings());
         plotm->setFileName(_fnDist);
         plotm->setTitle("Average distance");
-        plotm->setXLabel("Time (ps)");
+        plotm->setXAxisIsTime();
         plotm->setYLabel("Distance (nm)");
         _data.addModule(plotm);
     }
index c6068db23a04ba5319166ead5533ea794b763729..f1f39e0524cf8707344057e915c8c001cf578e3d 100644 (file)
@@ -50,18 +50,17 @@ class Options;
 class AbstractPlotModule::Impl
 {
     public:
-        explicit Impl(const Options &options);
+        explicit Impl(const AnalysisDataPlotSettings &settings);
         ~Impl();
 
         void closeFile();
 
+        AnalysisDataPlotSettings settings;
         std::string             fnm;
         FILE                   *fp;
 
         bool                    bPlain;
         bool                    bOmitX;
-        output_env_t            oenv;
-        const SelectionCollection *sel;
         std::string             title;
         std::string             subtitle;
         std::string             xlabel;
@@ -69,6 +68,7 @@ class AbstractPlotModule::Impl
         std::vector<std::string>  leg;
         char                    xfmt[15];
         char                    yfmt[15];
+        real                    xscale;
 };
 
 } // namespace gmx
index 0700e2af3e0eeefffccf10dd961481377551f21f..ba4aae5c65560596445391673e60f2452af61b83 100644 (file)
 #include <cstdio>
 #include <cstring>
 
+#include <boost/shared_ptr.hpp>
+
 #include <gmxfio.h>
+#include <smalloc.h>
 #include <statutil.h>
 #include <vec.h>
 #include <xvgr.h>
 
-#include "gromacs/options/globalproperties.h"
+#include "gromacs/options/basicoptions.h"
 #include "gromacs/options/options.h"
+#include "gromacs/options/timeunitmanager.h"
 #include "gromacs/fatalerror/exceptions.h"
 #include "gromacs/fatalerror/gmxassert.h"
 #include "gromacs/selection/selectioncollection.h"
+#include "gromacs/utility/format.h"
 
 #include "plot-impl.h"
 
+static const char *const g_plotFormats[] = {
+    "none", "xmgrace", "xmgr", NULL
+};
+
 namespace gmx
 {
 
+/********************************************************************
+ * AnalysisDataPlotSettings
+ */
+
+AnalysisDataPlotSettings::AnalysisDataPlotSettings()
+    : selections_(NULL), timeUnit_(eTimeUnit_ps), plotFormat_(1)
+{
+}
+
+void
+AnalysisDataPlotSettings::setSelectionCollection(const SelectionCollection *selections)
+{
+    selections_ = selections;
+}
+
+
+void
+AnalysisDataPlotSettings::addOptions(Options *options)
+{
+    options->addOption(StringOption("xvg").enumValue(g_plotFormats)
+                           .defaultValue("xmgrace")
+                           .storeEnumIndex(&plotFormat_)
+                           .description("Plot formatting"));
+}
+
+
 /********************************************************************
  * AbstractPlotModule::Impl
  */
 
-AbstractPlotModule::Impl::Impl(const Options &options)
-    : fp(NULL), bPlain(false), bOmitX(false),
-      oenv(options.globalProperties().output_env()),
-      sel(NULL)
+AbstractPlotModule::Impl::Impl(const AnalysisDataPlotSettings &settings)
+    : settings(settings), fp(NULL), bPlain(false), bOmitX(false), xscale(1.0)
 {
     strcpy(xfmt, "%11.3f");
     strcpy(yfmt, " %8.3f");
@@ -104,8 +137,8 @@ AbstractPlotModule::Impl::closeFile()
  * AbstractPlotModule
  */
 
-AbstractPlotModule::AbstractPlotModule(const Options &options)
-    : _impl(new Impl(options))
+AbstractPlotModule::AbstractPlotModule(const AnalysisDataPlotSettings &settings)
+    : _impl(new Impl(settings))
 {
 }
 
@@ -159,9 +192,11 @@ AbstractPlotModule::setXLabel(const char *label)
 
 
 void
-AbstractPlotModule::setXTimeLabel()
+AbstractPlotModule::setXAxisIsTime()
 {
-    _impl->xlabel = output_env_get_xvgr_tlabel(_impl->oenv);
+    TimeUnitManager manager(_impl->settings.timeUnit());
+    _impl->xlabel = formatString("Time (%s)", manager.timeUnitAsString());
+    _impl->xscale = manager.inverseTimeScaleFactor();
 }
 
 
@@ -230,29 +265,38 @@ AbstractPlotModule::dataStarted(AbstractAnalysisData *data)
         }
         else
         {
+            output_env_t oenv;
+            snew(oenv, 1);
+            output_env_init_default(oenv);
+            boost::shared_ptr<output_env> oenvGuard(oenv, &output_env_done);
+            oenv->time_unit = static_cast<time_unit_t>(_impl->settings.timeUnit() + 1);
+            oenv->xvg_format =
+                (_impl->settings.plotFormat() > 0
+                    ? static_cast<xvg_format_t>(_impl->settings.plotFormat())
+                    : exvgNONE);
             _impl->fp = xvgropen(_impl->fnm.c_str(), _impl->title.c_str(),
                                  _impl->xlabel.c_str(), _impl->ylabel.c_str(),
-                                 _impl->oenv);
-            if (_impl->sel != NULL)
+                                 oenv);
+            const SelectionCollection *selections
+                = _impl->settings.selectionCollection();
+            if (selections != NULL)
             {
-                _impl->sel->printXvgrInfo(_impl->fp, _impl->oenv);
+                selections->printXvgrInfo(_impl->fp, oenv);
             }
             if (!_impl->subtitle.empty())
             {
-                xvgr_subtitle(_impl->fp, _impl->subtitle.c_str(), _impl->oenv);
+                xvgr_subtitle(_impl->fp, _impl->subtitle.c_str(), oenv);
             }
-            if (output_env_get_print_xvgr_codes(_impl->oenv)
+            if (output_env_get_print_xvgr_codes(oenv)
                 && !_impl->leg.empty())
             {
-                const char **leg;
-
-                leg = new const char *[_impl->leg.size()];
+                std::vector<const char *> leg;
+                leg.reserve(_impl->leg.size());
                 for (size_t i = 0; i < _impl->leg.size(); ++i)
                 {
-                    leg[i] = _impl->leg[i].c_str();
+                    leg.push_back(_impl->leg[i].c_str());
                 }
-                xvgr_legend(_impl->fp, _impl->leg.size(), leg, _impl->oenv);
-                delete [] leg;
+                xvgr_legend(_impl->fp, leg.size(), &leg[0], oenv);
             }
         }
     }
@@ -268,7 +312,7 @@ AbstractPlotModule::frameStarted(real x, real dx)
     }
     if (!_impl->bOmitX)
     {
-        std::fprintf(_impl->fp, _impl->xfmt, x);
+        std::fprintf(_impl->fp, _impl->xfmt, x * _impl->xscale);
     }
 }
 
@@ -310,8 +354,9 @@ AbstractPlotModule::writeValue(real value) const
  * DataPlotModule
  */
 
-AnalysisDataPlotModule::AnalysisDataPlotModule(const Options &options)
-    : AbstractPlotModule(options)
+AnalysisDataPlotModule::AnalysisDataPlotModule(
+        const AnalysisDataPlotSettings &settings)
+    : AbstractPlotModule(settings)
 {
 }
 
@@ -336,8 +381,9 @@ AnalysisDataPlotModule::pointsAdded(real x, real dx, int firstcol, int n,
  * DataVectorPlotModule
  */
 
-AnalysisDataVectorPlotModule::AnalysisDataVectorPlotModule(const Options &options)
-    : AbstractPlotModule(options)
+AnalysisDataVectorPlotModule::AnalysisDataVectorPlotModule(
+        const AnalysisDataPlotSettings &settings)
+    : AbstractPlotModule(settings)
 {
     for (int i = 0; i < DIM; ++i)
     {
index 6145117e52f38a9baa83a0b5c42339709f4eba9c..224d876213723912a7ae1df315da8b08998f669e 100644 (file)
 #include <string>
 
 #include "../datamodule.h"
+#include "../../options/timeunitmanager.h"
 
 namespace gmx
 {
 
 class Options;
+class SelectionCollection;
+
+/*! \brief
+ * Common settings for data plots.
+ *
+ * \inpublicapi
+ * \ingroup module_analysisdata
+ */
+class AnalysisDataPlotSettings
+{
+    public:
+        //! Constructs default analysis plot settings.
+        AnalysisDataPlotSettings();
+
+        //! Returns the selection collection set with setSelectionCollection().
+        const SelectionCollection *selectionCollection() const
+        {
+            return selections_;
+        }
+        //! Returns the time unit set with setTimeUnit().
+        TimeUnit timeUnit() const { return timeUnit_; }
+        /*! \brief
+         * Returns the plot format.
+         *
+         * \todo Use a proper enum.
+         */
+        int plotFormat() const { return plotFormat_; }
+
+        /*! \brief
+         * Set selection collection to print as comments into the output.
+         *
+         * Formatted selection text from all selections in \p selections is
+         * printed as comments in the output file.
+         * If this method is not called, no selection information is written
+         * to the output.
+         */
+        void setSelectionCollection(const SelectionCollection *selections);
+        /*! \brief
+         * Sets the time unit for the plot.
+         *
+         * The value is used only if AbstractPlotModule::setXAxisIsTime() is
+         * called, in which case it is used to print the appropriate axis label
+         * and to scale the values.
+         * If not called, the default time unit is ps.
+         */
+        void setTimeUnit(TimeUnit timeUnit) { timeUnit_ = timeUnit; }
+
+
+        /*! \brief
+         * Adds common options for setting plot options.
+         *
+         * \param[in,out] options Options object to which options are added.
+         */
+        void addOptions(Options *options);
+
+    private:
+        const SelectionCollection *selections_;
+        TimeUnit                timeUnit_;
+        int                     plotFormat_;
+};
 
 /*! \brief
  * Abstract data module for writing data into a file.
@@ -106,9 +167,12 @@ class AbstractPlotModule : public AnalysisDataModuleInterface
          */
         void setXLabel(const char *label);
         /*! \brief
-         * Set X axis label for time.
+         * Treat X axis as time.
+         *
+         * Sets the label for the axis accordingly and also scales output to
+         * take into account the correct time unit.
          */
-        void setXTimeLabel();
+        void setXAxisIsTime();
         /*! \brief
          * Set Y axis label.
          */
@@ -148,7 +212,7 @@ class AbstractPlotModule : public AnalysisDataModuleInterface
 
     protected:
         /*! \cond libapi */
-        explicit AbstractPlotModule(const Options &options);
+        explicit AbstractPlotModule(const AnalysisDataPlotSettings &settings);
 
         bool isFileOpen() const;
         void writeValue(real value) const;
@@ -176,7 +240,7 @@ class AbstractPlotModule : public AnalysisDataModuleInterface
 class AnalysisDataPlotModule : public AbstractPlotModule
 {
     public:
-        explicit AnalysisDataPlotModule(const Options &options);
+        explicit AnalysisDataPlotModule(const AnalysisDataPlotSettings &settings);
 
         virtual void pointsAdded(real x, real dx, int firstcol, int n,
                                  const real *y, const real *dy,
@@ -197,7 +261,7 @@ class AnalysisDataPlotModule : public AbstractPlotModule
 class AnalysisDataVectorPlotModule : public AbstractPlotModule
 {
     public:
-        explicit AnalysisDataVectorPlotModule(const Options &options);
+        explicit AnalysisDataVectorPlotModule(const AnalysisDataPlotSettings &settings);
 
         /*! \brief
          * Set whether to write X component.
index 4efc84d49f4438d4c20b915d88fa2b6c8ebf081b..c8e913395d5672a12bafdb7eee75a11f225ab010 100644 (file)
  * the option should provide as the template argument.  After this is done, it
  * is possible to add options of this new type using Options::addOption().
  *
- * There is limited support for options that need to share information across
- * instances, e.g., to store values in a shared external data structure or to
- * provide a global option to set a common setting for all such options,
- * provided by the OptionsGlobalProperties class.  This mechanism is not
- * generic, meaning that it is required to change the options module to add
- * data to this structure.
- *
  * To implement new parsers, one can use OptionsAssigner, which provides an
  * interface to set values in an Options object.
  *
index 7e6f33d8287e298c5a24bb38fe339f75a37c3110..31d06dea2a260fe194e769c8e4706326da0f1e6d 100644 (file)
@@ -45,7 +45,6 @@
 
 #include "gromacs/fatalerror/exceptions.h"
 #include "gromacs/options/basicoptioninfo.h"
-#include "gromacs/options/globalproperties.h"
 #include "gromacs/options/options.h"
 #include "gromacs/utility/format.h"
 
@@ -368,7 +367,9 @@ void StringOptionStorage::refreshValues()
         {
             ValueList::const_iterator match =
                 std::find(_allowed.begin(), _allowed.end(), values()[i]);
-            _enumIndexStore[i] = (match - _allowed.begin());
+            GMX_ASSERT(match != _allowed.end(),
+                       "Enum value not found (internal error)");
+            _enumIndexStore[i] = static_cast<int>(match - _allowed.begin());
         }
     }
 }
@@ -420,10 +421,6 @@ FileNameOptionStorage::FileNameOptionStorage(const FileNameOption &settings, Opt
       bRead_(settings.bRead_), bWrite_(settings.bWrite_),
       bLibrary_(settings.bLibrary_)
 {
-    if (filetype_ == eftPlot)
-    {
-        options->globalProperties().request(eogpPlotFormat);
-    }
 }
 
 std::string FileNameOptionStorage::formatValue(int i) const
diff --git a/src/gromacs/options/globalproperties.cpp b/src/gromacs/options/globalproperties.cpp
deleted file mode 100644 (file)
index 6338a55..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- *
- *                This source code is part of
- *
- *                 G   R   O   M   A   C   S
- *
- *          GROningen MAchine for Chemical Simulations
- *
- * 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.
- *
- * 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.
- *
- * 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
- */
-/*! \internal \file
- * \brief
- * Implements gmx::OptionsGlobalProperties.
- *
- * \author Teemu Murtola <teemu.murtola@cbr.su.se>
- * \ingroup module_options
- */
-#include "gromacs/options/globalproperties.h"
-
-#include <cstddef>
-
-#include <smalloc.h>
-#include <statutil.h>
-
-#include "gromacs/options/basicoptions.h"
-#include "gromacs/options/options.h"
-
-namespace gmx
-{
-
-static const char *const plotFormats[] = {
-    "none", "xmgrace", "xmgr", NULL
-};
-
-
-OptionsGlobalProperties::OptionsGlobalProperties()
-    : _usedProperties(0), _plotFormat(1),
-      _oenv(NULL)
-{
-    // TODO: If/when this is refactored, exception safety should be considered
-    snew(_oenv, 1);
-    output_env_init_default(_oenv);
-}
-
-
-OptionsGlobalProperties::~OptionsGlobalProperties()
-{
-    if (_oenv != NULL)
-    {
-        output_env_done(_oenv);
-    }
-}
-
-
-void OptionsGlobalProperties::addDefaultOptions(Options *options)
-{
-    if (isPropertyUsed(eogpPlotFormat))
-    {
-        options->addOption(StringOption("xvg").enumValue(plotFormats)
-                               .defaultValue("xmgrace")
-                               .storeEnumIndex(&_plotFormat)
-                               .description("Plot formatting"));
-    }
-}
-
-
-void OptionsGlobalProperties::finish()
-{
-    if (isPropertyUsed(eogpPlotFormat))
-    {
-        if (_plotFormat == 0)
-        {
-            _oenv->xvg_format = exvgNONE;
-        }
-        else
-        {
-            _oenv->xvg_format = static_cast<xvg_format_t>(_plotFormat);
-        }
-    }
-}
-
-} // namespace gmx
diff --git a/src/gromacs/options/globalproperties.h b/src/gromacs/options/globalproperties.h
deleted file mode 100644 (file)
index ad297be..0000000
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- *
- *                This source code is part of
- *
- *                 G   R   O   M   A   C   S
- *
- *          GROningen MAchine for Chemical Simulations
- *
- * 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.
- *
- * 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.
- *
- * 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
- */
-/*! \libinternal \file
- * \brief
- * Declares gmx::OptionsGlobalProperties.
- *
- * \author Teemu Murtola <teemu.murtola@cbr.su.se>
- * \inlibraryapi
- * \ingroup module_options
- */
-#ifndef GMX_OPTIONS_GLOBALPROPERTIES_H
-#define GMX_OPTIONS_GLOBALPROPERTIES_H
-
-#include <typedefs.h>
-
-namespace gmx
-{
-
-class Options;
-
-/*! \libinternal \brief
- * ID numbers for global properties.
- */
-enum OptionGlobalPropertyId
-{
-    eogpPlotFormat,
-};
-
-/*! \libinternal \brief
- * Describes global properties of an Options collection.
- *
- * These properties are used to implement features that require all options of
- * a certain type to access some global data.
- * For example, if there are options that specify times, and in addition an
- * option that specifies the unit for these times, all the time options need to
- * know the scaling factor to get the time in internal units.
- *
- * \todo
- * There are things in this class that would be
- * better placed in the analysisdata module (for selecting plot formats).
- * It should be considered whether this should be implemented in some other way
- * (see Redmine issue #839).
- *
- * \inlibraryapi
- * \ingroup module_options
- */
-class OptionsGlobalProperties
-{
-    public:
-        ~OptionsGlobalProperties();
-
-        //! Request for a global property to be used.
-        void request(OptionGlobalPropertyId id)
-        {
-            _usedProperties |= (1<<id);
-        }
-
-        /*! \brief
-         * Returns an output environment structure for interfacing with old
-         * code.
-         *
-         * Currently, the returned structure is always filled with default
-         * values for most fields.
-         *
-         * \deprecated
-         */
-        output_env_t output_env() const
-        {
-            return _oenv;
-        }
-
-    private:
-        OptionsGlobalProperties();
-
-        //! Returns true if request() has been called for the given property.
-        bool isPropertyUsed(OptionGlobalPropertyId id) const
-        {
-            return _usedProperties & (1<<id);
-        }
-        /*! \brief
-         * Adds options for setting requested global properties.
-         *
-         * \param[in,out] options Options to which the global property options
-         *      are added.
-         *
-         * If a global property has been requested and it can be set/customized
-         * by the user, this method adds the necessary option to \p options.
-         *
-         * This method performs the real work of Options::addDefaultOptions().
-         */
-        void addDefaultOptions(Options *options);
-        /*! \brief
-         * Initializes variables dependent on global properties.
-         *
-         * This method should be called after the values for the options
-         * generated with addDefaultOptions() have been set.
-         */
-        void finish();
-
-        unsigned long           _usedProperties;
-        int                     _plotFormat;
-        output_env_t            _oenv;
-
-        friend class Options;
-
-        // Disallow copy and assign.
-        OptionsGlobalProperties(const OptionsGlobalProperties &);
-        void operator =(const OptionsGlobalProperties &);
-};
-
-} // namespace gmx
-
-#endif
index d3e12521d9d1b5ed50da9a945446f062dbb5eb86..876a80deca1ae093b44357f61d810c09f40de9be 100644 (file)
@@ -48,7 +48,6 @@ namespace gmx
 {
 
 class AbstractOptionStorage;
-class OptionsGlobalProperties;
 
 /*! \internal \brief
  * Private implementation class for Options.
@@ -119,15 +118,6 @@ class Options::Impl
         OptionList              _options;
         //! Options object that contains this object as a subsection, or NULL.
         Options                *_parent;
-        /*! \brief
-         * Object that contains global properties, or NULL if \a _parent != NULL.
-         *
-         * This object is always owned by the Options object.
-         * For subsections, the global properties are kept in the parent, and
-         * this pointer is NULL.
-         */
-        // Could be scoped_ptr
-        std::auto_ptr<OptionsGlobalProperties>  _globalProperties;
 };
 
 } // namespace gmx
index ecbddde4320fd1e3f7159f00179aa0bfbdb56f11..74f5bdecf6612d4542c68fadd6f7eafd1d971976 100644 (file)
@@ -45,7 +45,6 @@
 #include "gromacs/fatalerror/messagestringcollector.h"
 #include "gromacs/options/abstractoption.h"
 #include "gromacs/options/abstractoptionstorage.h"
-#include "gromacs/options/globalproperties.h"
 
 #include "options-impl.h"
 
@@ -79,7 +78,7 @@ static std::string composeString(const char *const *sarray)
 
 Options::Impl::Impl(const char *name, const char *title)
     : _name(name != NULL ? name : ""), _title(title != NULL ? title : ""),
-      _parent(NULL), _globalProperties(new OptionsGlobalProperties)
+      _parent(NULL)
 {
 }
 
@@ -178,10 +177,6 @@ void Options::addSubSection(Options *section)
                        "Duplicate subsection name");
     _impl->_subSections.push_back(section);
     section->_impl->_parent = this;
-
-    globalProperties()._usedProperties |=
-        section->_impl->_globalProperties->_usedProperties;
-    section->_impl->_globalProperties.reset();
 }
 
 void Options::addOption(const AbstractOption &settings)
@@ -195,11 +190,6 @@ void Options::addOption(const AbstractOption &settings)
     option.release();
 }
 
-void Options::addDefaultOptions()
-{
-    globalProperties().addDefaultOptions(this);
-}
-
 bool Options::isSet(const char *name) const
 {
     AbstractOptionStorage *option = _impl->findOption(name);
@@ -236,12 +226,6 @@ void Options::finish()
             errors.append(ex.what());
         }
     }
-    if (_impl->_parent == NULL)
-    {
-        GMX_RELEASE_ASSERT(_impl->_globalProperties.get() != NULL,
-                           "Global properties should exist for the top-level options");
-        _impl->_globalProperties->finish();
-    }
     if (!errors.isEmpty())
     {
         // TODO: This exception type may not always be appropriate.
@@ -249,16 +233,4 @@ void Options::finish()
     }
 }
 
-OptionsGlobalProperties &Options::globalProperties()
-{
-    Options *section = this;
-    while (section->_impl->_parent != NULL)
-    {
-        section = section->_impl->_parent;
-    }
-    GMX_RELEASE_ASSERT(section->_impl->_globalProperties.get() != NULL,
-                       "Global properties should exist for the top-level options");
-    return *section->_impl->_globalProperties;
-}
-
 } // namespace gmx
index f82096ed964e7342c6d808157248689c298dd827..299e365deda78c345e174eff96d9a5c3d91eb6b0 100644 (file)
@@ -48,7 +48,6 @@ namespace gmx
 {
 
 class AbstractOption;
-class OptionsGlobalProperties;
 class OptionsAssigner;
 class OptionsIterator;
 
@@ -151,17 +150,6 @@ class Options
          * See \link Options class documentation \endlink for example usage.
          */
         void addOption(const AbstractOption &settings);
-        /*! \brief
-         * Adds default options to this collection.
-         *
-         * Adds default options for altering global properties such as the time
-         * unit into this collection.
-         *
-         * It is possible to call this method on a subsection of a collection.
-         * Even in that case, the generated options set the properties for the
-         * parent collection.
-         */
-        void addDefaultOptions();
 
         //! Returns true if option \p name is set.
         bool isSet(const char *name) const;
@@ -181,23 +169,6 @@ class Options
          */
         void finish();
 
-        /*! \brief
-         * Returns the global property object for this collection.
-         *
-         * The caller should not store pointers or references to the object;
-         * it can change if this object is added as a subsection into
-         * another collection.
-         *
-         * The global property object is shared by all Options objects that
-         * are part of the same section/subsection hierarchy.
-         *
-         * \see OptionsGlobalProperties
-         */
-        OptionsGlobalProperties &globalProperties();
-        //! \copydoc globalProperties()
-        const OptionsGlobalProperties &globalProperties() const
-        { return const_cast<Options *>(this)->globalProperties(); }
-
     private:
         class Impl;
 
index 3fc512c94837d0513d3f1abc30a72a354428bdf7..22e5f7aeb7c6cd0d793b958d7c39236cac2b49e9 100644 (file)
@@ -40,7 +40,6 @@
 #include <gtest/gtest.h>
 
 #include "gromacs/fatalerror/exceptions.h"
-#include "gromacs/options/globalproperties.h"
 #include "gromacs/options/options.h"
 #include "gromacs/options/optionsassigner.h"
 #include "gromacs/selection/selection.h"
index c9eaece10d8d610b34e39e5a6900a54dc491496a..1ff47e511ba877c367232c9f5eb7731ab97fe6fe 100644 (file)
@@ -40,6 +40,7 @@
 
 #include "analysissettings.h"
 
+#include "../analysisdata/modules/plot.h"
 #include "../options/timeunitmanager.h"
 
 namespace gmx
@@ -57,6 +58,7 @@ class TrajectoryAnalysisSettings::Impl
         Impl() : flags(0), frflags(0), bRmPBC(true), bPBC(true) {}
 
         TimeUnitManager      timeUnitManager;
+        AnalysisDataPlotSettings plotSettings;
         unsigned long        flags;
         int                  frflags;
 
index 3b0866ce569f945cf92332ffe22124d425e5795c..59f37345dcd98a10effe0532dbb2a0736f9567df 100644 (file)
@@ -69,6 +69,20 @@ TrajectoryAnalysisSettings::~TrajectoryAnalysisSettings()
 }
 
 
+const TimeUnitManager &
+TrajectoryAnalysisSettings::timeUnitManager() const
+{
+    return _impl->timeUnitManager;
+}
+
+
+const AnalysisDataPlotSettings &
+TrajectoryAnalysisSettings::plotSettings() const
+{
+    return _impl->plotSettings;
+}
+
+
 unsigned long
 TrajectoryAnalysisSettings::flags() const
 {
index d49d913f630607fde876a5b197fc460a99061ba8..47a322fc000ff7991ee3de85497c6f8fc1c88f74 100644 (file)
 
 #include "../legacyheaders/typedefs.h"
 
+#include "../options/timeunitmanager.h"
+
 namespace gmx
 {
 
+class AnalysisDataPlotSettings;
 class Options;
 class TrajectoryAnalysisRunnerCommon;
 
@@ -113,6 +116,13 @@ class TrajectoryAnalysisSettings
         TrajectoryAnalysisSettings();
         ~TrajectoryAnalysisSettings();
 
+        //! Returns the time unit manager with time unit timeUnit().
+        const TimeUnitManager &timeUnitManager() const;
+        //! Returns the time unit the user has requested.
+        TimeUnit timeUnit() { return timeUnitManager().timeUnit(); }
+        //! Returns common settings for analysis data plot modules.
+        const AnalysisDataPlotSettings &plotSettings() const;
+
         //! Returns the currently set flags.
         unsigned long flags() const;
         //! Tests whether a flag has been set.
index a87c335ce646733f0cdf7d6ec14055924fab636d..234001d0137d2fb0b7ddaefbce5a273427344d7a 100644 (file)
@@ -50,7 +50,6 @@
 #include "gromacs/fatalerror/gmxassert.h"
 #include "gromacs/options/asciihelpwriter.h"
 #include "gromacs/options/cmdlineparser.h"
-#include "gromacs/options/globalproperties.h"
 #include "gromacs/options/options.h"
 #include "gromacs/selection/selectioncollection.h"
 #include "gromacs/selection/selectionoptioninfo.h"
@@ -130,7 +129,6 @@ TrajectoryAnalysisCommandLineRunner::Impl::parseOptions(
     options->addSubSection(selectionOptions);
     options->addSubSection(moduleOptions);
 
-    commonOptions->addDefaultOptions();
     setSelectionCollectionForOptions(options, selections);
 
     {
index f57f341ebfb39eb567cf1a3b31e8d6a76906c65f..c339d253db1adc05ceb360993ae5d2b57f4e80a8 100644 (file)
@@ -52,6 +52,7 @@
 #include "gromacs/selection/selection.h"
 #include "gromacs/selection/selectionoption.h"
 #include "gromacs/selection/selectionoptioninfo.h"
+#include "gromacs/trajectoryanalysis/analysissettings.h"
 #include "gromacs/utility/format.h"
 
 namespace gmx
@@ -356,11 +357,12 @@ Angle::initAnalysis(const TrajectoryAnalysisSettings &settings,
 
     registerAnalysisDataset(&_data, "angle");
 
-    AnalysisDataPlotModule *plotm = new AnalysisDataPlotModule(_options);
+    AnalysisDataPlotModule *plotm
+        = new AnalysisDataPlotModule(settings.plotSettings());
     plotm->setFileName(_fnAngle);
     plotm->setTitle("Angle");
-    plotm->setXTimeLabel();
-    plotm->setYLabel("Angle [degrees]");
+    plotm->setXAxisIsTime();
+    plotm->setYLabel("Angle (degrees)");
     _data.addModule(plotm);
 }
 
index 2f230916b769583375ee3782783185281fdce918..b0884e66a1354c90e59fdaf820718a9b77356c20 100644 (file)
@@ -52,6 +52,7 @@
 #include "gromacs/options/options.h"
 #include "gromacs/selection/selection.h"
 #include "gromacs/selection/selectionoption.h"
+#include "gromacs/trajectoryanalysis/analysissettings.h"
 
 namespace gmx
 {
@@ -109,11 +110,11 @@ Distance::initAnalysis(const TrajectoryAnalysisSettings &settings,
     _avem = new AnalysisDataAverageModule();
     _data.addModule(_avem);
 
-    _plotm = new AnalysisDataPlotModule(_options);
+    _plotm = new AnalysisDataPlotModule(settings.plotSettings());
     _plotm->setFileName(_fnDist);
     _plotm->setTitle("Distance");
-    _plotm->setXLabel("Time [ps]");
-    _plotm->setYLabel("Distance [nm]");
+    _plotm->setXAxisIsTime();
+    _plotm->setYLabel("Distance (nm)");
     _data.addModule(_plotm);
 }
 
index cf2f44e77d8e7722edb8be4004936683b7803ab6..ed8f48c02a5ce13e1704b97fa9cc0c8934b8362c 100644 (file)
@@ -387,10 +387,11 @@ Select::initAnalysis(const TrajectoryAnalysisSettings &settings,
     }
     if (!_fnSize.empty())
     {
-        AnalysisDataPlotModule *plot = new AnalysisDataPlotModule(_options);
+        AnalysisDataPlotModule *plot
+            = new AnalysisDataPlotModule(settings.plotSettings());
         plot->setFileName(_fnSize);
         plot->setTitle("Selection size");
-        plot->setXLabel("Time [ps]");
+        plot->setXAxisIsTime();
         plot->setYLabel("Number");
         _sdata.addModule(plot);
     }
@@ -399,10 +400,11 @@ Select::initAnalysis(const TrajectoryAnalysisSettings &settings,
     registerAnalysisDataset(&_cdata, "cfrac");
     if (!_fnFrac.empty())
     {
-        AnalysisDataPlotModule *plot = new AnalysisDataPlotModule(_options);
+        AnalysisDataPlotModule *plot
+            = new AnalysisDataPlotModule(settings.plotSettings());
         plot->setFileName(_fnFrac);
         plot->setTitle("Covered fraction");
-        plot->setXLabel("Time [ps]");
+        plot->setXAxisIsTime();
         plot->setYLabel("Fraction");
         plot->setYFormat(6, 4);
         _cdata.addModule(plot);
@@ -413,7 +415,8 @@ Select::initAnalysis(const TrajectoryAnalysisSettings &settings,
     registerAnalysisDataset(&_idata, "index");
     if (!_fnIndex.empty())
     {
-        AnalysisDataPlotModule *plot = new AnalysisDataPlotModule(_options);
+        AnalysisDataPlotModule *plot
+            = new AnalysisDataPlotModule(settings.plotSettings());
         plot->setFileName(_fnIndex);
         plot->setPlainOutput(true);
         plot->setYFormat(4, 0);
@@ -452,12 +455,13 @@ Select::initAnalysis(const TrajectoryAnalysisSettings &settings,
         }
         else
         {
-            AnalysisDataPlotModule *plot = new AnalysisDataPlotModule(_options);
+            AnalysisDataPlotModule *plot
+                = new AnalysisDataPlotModule(settings.plotSettings());
             plot->setFileName(_fnMask);
             plot->setPlainOutput(_bDump);
             plot->setOmitX(_bDump);
             plot->setTitle("Selection mask");
-            plot->setXLabel("Time [ps]");
+            plot->setXAxisIsTime();
             plot->setYLabel("Occupancy");
             plot->setYFormat(1, 0);
             _mdata.addModule(plot);
index e30135bb3b9b5dc9567d3bd3b78927c921f573b8..df609b44597086f10aff8dbf624e5918986c12ab 100644 (file)
@@ -50,7 +50,6 @@
 #include "gromacs/fatalerror/exceptions.h"
 #include "gromacs/fatalerror/gmxassert.h"
 #include "gromacs/options/basicoptions.h"
-#include "gromacs/options/globalproperties.h"
 #include "gromacs/options/options.h"
 #include "gromacs/selection/indexutil.h"
 #include "gromacs/selection/selectioncollection.h"
@@ -124,6 +123,10 @@ TrajectoryAnalysisRunnerCommon::Impl::~Impl()
         sfree(fr->f);
         sfree(fr);
     }
+    if (_oenv != NULL)
+    {
+        output_env_done(_oenv);
+    }
 }
 
 
@@ -200,6 +203,9 @@ TrajectoryAnalysisRunnerCommon::initOptions()
     // Add time unit option.
     settings._impl->timeUnitManager.addTimeUnitOption(&options, "tu");
 
+    // Add plot options.
+    settings._impl->plotSettings.addOptions(&options);
+
     // Add common options for trajectory processing.
     if (!settings.hasFlag(TrajectoryAnalysisSettings::efNoUserRmPBC))
     {
@@ -231,6 +237,9 @@ TrajectoryAnalysisRunnerCommon::initOptionsDone()
         return false;
     }
 
+    _impl->_settings._impl->plotSettings.setTimeUnit(
+            _impl->_settings._impl->timeUnitManager.timeUnit());
+
     if (_impl->_trjfile.empty() && _impl->_topfile.empty())
     {
         GMX_THROW(InconsistentInputError("No trajectory or topology provided, nothing to do!"));
@@ -332,7 +341,10 @@ TrajectoryAnalysisRunnerCommon::initFirstFrame()
     {
         return;
     }
-    _impl->_oenv = _impl->_options.globalProperties().output_env();
+    snew(_impl->_oenv, 1);
+    output_env_init_default(_impl->_oenv);
+    _impl->_oenv->time_unit
+        = static_cast<time_unit_t>(_impl->_settings.timeUnit() + 1);
 
     int frflags = _impl->_settings.frflags();
     frflags |= TRX_NEED_X;