Add conserved quantity for Berendsen P-couple
[gromacs.git] / src / gromacs / commandline / cmdlineinit.h
blob44d9c3e1bdd4e5b6f6b17df3a6b47a02ac9efbdd
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
35 /*! \file
36 * \brief
37 * Declares functions for initializing the \Gromacs library for command line use.
39 * \author Teemu Murtola <teemu.murtola@gmail.com>
40 * \inpublicapi
41 * \ingroup module_commandline
43 #ifndef GMX_COMMANDLINE_CMDLINEINIT_H
44 #define GMX_COMMANDLINE_CMDLINEINIT_H
46 #ifdef __cplusplus
48 #include <functional>
49 #include <memory>
51 // Forward declaration of class CommandLineProgramContext is not sufficient for
52 // MSVC if the return value of initForCommandLine() is ignored(!)
53 #include "gromacs/commandline/cmdlineprogramcontext.h"
55 namespace gmx
58 class ICommandLineModule;
59 class ICommandLineOptionsModule;
61 /*! \brief
62 * Initializes the \Gromacs library for command-line use.
64 * \param[in] argc argc value passed to main().
65 * \param[in] argv argv array passed to main().
66 * \returns Reference to initialized program context object.
68 * This function is tailored for use in command line applications.
69 * For other usage, combination of gmx::init() and gmx::setProgramContext()
70 * provides more flexible initialization alternatives.
71 * Unlike gmx::init(), calls to this method cannot be nested.
73 * The command line arguments are communicated so that they can be
74 * parsed on each processor.
75 * \p argc and \p argv are passed to gmx::init(); see there for additional
76 * discussion. This method does not place any additional limitations, but
77 * generally there should be no need to pass NULL values.
79 * Does not throw. Terminates the program on out-of-memory error.
81 * This method is not thread-safe, since it is intended to be the first method
82 * called. See setProgramContext() for additional discussion.
84 * \see gmx::init()
85 * \see setProgramContext()
86 * \ingroup module_commandline
88 CommandLineProgramContext &initForCommandLine(int *argc, char ***argv);
89 /*! \brief
90 * Deinitializes the \Gromacs library after initForCommandLine().
92 * Calls gmx::finalize() and additionally undoes the work done by
93 * initForCommandLine().
95 * \see gmx::finalize()
96 * \ingroup module_commandline
98 void finalizeForCommandLine();
99 /*! \brief
100 * Handles an exception and deinitializes after initForCommandLine.
102 * \param[in] ex Exception that is the cause for terminating the program.
103 * \returns Return code to return from main().
105 * This method should be called as the last thing before terminating the
106 * program because of an exception. See processExceptionAtExit() for details.
107 * Additionally this method undoes the work done by initForCommandLine.
109 * Does not throw.
111 int processExceptionAtExitForCommandLine(const std::exception &ex);
112 /*! \brief
113 * Implements a main() method that runs a single module.
115 * \param argc \c argc passed to main().
116 * \param argv \c argv passed to main().
117 * \param module Module to run.
119 * This method allows for uniform behavior for binaries that only
120 * contain a single module without duplicating any of the
121 * implementation from CommandLineModuleManager (startup headers,
122 * common options etc.).
124 * The signature assumes that \p module construction does not throw
125 * (because otherwise the caller would need to duplicate all the
126 * exception handling code). It is possible to move the construction
127 * inside the try/catch in this method using an indirection similar to
128 * TrajectoryAnalysisCommandLineRunner::runAsMain(), but until that is
129 * necessary, the current approach leads to simpler code.
131 * Usage:
132 * \code
133 int main(int argc, char *argv[])
135 CustomCommandLineModule module;
136 return gmx::runCommandLineModule(argc, argv, &module);
138 \endcode
140 * Does not throw. All exceptions are caught and handled internally.
142 int runCommandLineModule(int argc, char *argv[],
143 ICommandLineModule *module);
144 /*! \brief
145 * Implements a main() method that runs a single module.
147 * \param argc \c argc passed to main().
148 * \param argv \c argv passed to main().
149 * \param[in] name Name for the module.
150 * \param[in] description Short description for the module.
151 * \param factory Factory method that creates the module to run.
153 * This method allows for uniform behavior for binaries that only
154 * contain a single module without duplicating any of the
155 * implementation from CommandLineModuleManager (startup headers,
156 * common options etc.).
158 * Usage:
159 * \code
160 class CustomCommandLineOptionsModule : public ICommandLineOptionsModule
162 // <...>
165 static ICommandLineOptionsModule *create()
167 return new CustomCommandLineOptionsModule();
170 int main(int argc, char *argv[])
172 return gmx::runCommandLineModule(
173 argc, argv, "mymodule", "short description", &create);
175 \endcode
177 * Does not throw. All exceptions are caught and handled internally.
179 int runCommandLineModule(int argc, char *argv[],
180 const char *name, const char *description,
181 std::function<std::unique_ptr<ICommandLineOptionsModule>()> factory);
183 } // namespace gmx
185 extern "C"
187 #endif
189 /*! \brief
190 * Implements a main() method that runs a given C main function.
192 * \param argc \c argc passed to main().
193 * \param argv \c argv passed to main().
194 * \param mainFunction The main()-like method to wrap.
196 * This method creates a dummy command line module that does its
197 * processing by calling \p mainFunction. It then runs this module as with
198 * gmx::runCommandLineModule().
199 * This allows the resulting executable to handle common options and do
200 * other common actions (e.g., startup headers) without duplicate code
201 * in the main methods.
203 * \p mainFunction should call parse_common_args() to process its command-line
204 * arguments.
206 * Usage:
207 * \code
208 int my_main(int argc, char *argv[])
210 // <...>
213 int main(int argc, char *argv[])
215 return gmx_run_cmain(argc, argv, &my_main);
217 \endcode
219 * Does not throw. All exceptions are caught and handled internally.
221 int gmx_run_cmain(int argc, char *argv[], int (*mainFunction)(int, char *[]));
223 #ifdef __cplusplus
225 #endif
227 #endif