Compile nonbonded kernels as C++
[alexxy/gromacs.git] / src / gromacs / commandline / pargs.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5  * Copyright (c) 2001-2004, The GROMACS development team.
6  * Copyright (c) 2013,2014,2015,2017,2018, by the GROMACS development team, led by
7  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8  * and including many others, as listed in the AUTHORS file in the
9  * top-level source directory and at http://www.gromacs.org.
10  *
11  * GROMACS is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public License
13  * as published by the Free Software Foundation; either version 2.1
14  * of the License, or (at your option) any later version.
15  *
16  * GROMACS is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with GROMACS; if not, see
23  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
25  *
26  * If you want to redistribute modifications to GROMACS, please
27  * consider that scientific software is very special. Version
28  * control is crucial - bugs must be traceable. We will be happy to
29  * consider code for inclusion in the official distribution, but
30  * derived work must not be called official GROMACS. Details are found
31  * in the README & COPYING files - if they are missing, get the
32  * official version at http://www.gromacs.org.
33  *
34  * To help us fund GROMACS development, we humbly ask that you cite
35  * the research papers on the package. Check out http://www.gromacs.org.
36  */
37 /*! \file
38  * \brief
39  * Declares \c t_pargs, parse_common_args() and related methods.
40  *
41  * \inpublicapi
42  * \ingroup module_commandline
43  */
44 #ifndef GMX_COMMANDLINE_PARGS_H
45 #define GMX_COMMANDLINE_PARGS_H
46
47 #include "gromacs/commandline/filenm.h"
48 #include "gromacs/fileio/oenv.h"
49 #include "gromacs/math/vectypes.h"
50 #include "gromacs/utility/basedefinitions.h"
51 #include "gromacs/utility/real.h"
52
53 struct gmx_output_env_t;
54
55 /*! \addtogroup module_commandline
56  * \{
57  */
58
59 /** Command line argument type. */
60 enum
61 {
62     etINT, etINT64, etREAL, etTIME, etSTR, etBOOL, etRVEC, etENUM, etNR
63 };
64
65 /*! \brief
66  * Command-line argument definition for C code.
67  *
68  * \inpublicapi
69  */
70 typedef struct
71 {
72     /** Name of the argument (with leading dash included). */
73     const char *option;
74     /** Whether the argument is set (should be initialized to `FALSE`). */
75     gmx_bool    bSet;
76     /** Type of the argument (one of the enums in pargs.h). */
77     int         type;
78     /*! \brief
79      * Pointer to variable that is to receive the value.
80      *
81      * The expected type depends on the value of \a type.
82      * If an argument is not set by the user, then the pointed value is not
83      * changed.  In other words, the initial value for the variable defines the
84      * default value.
85      */
86     union
87     {
88         /*! \brief
89          * Generic pointer for operations that do not need type information.
90          *
91          * Needs to be the first member to use initialized arrays.
92          */
93         void            *v;
94         /** Integer value for etINT. */
95         int             *i;
96         /** Integer value for etINT64. */
97         int64_t         *is;
98         /** Real value for etREAL and etTIME. */
99         real            *r;
100         /*! \brief
101          * String value for etSTR and etENUM.
102          *
103          * For etSTR, this should point to a `const char *` variable, which
104          * will receive a pointer to the string value (caller should not free
105          * the string).
106          *
107          * For etENUM, this should be an array of `const char *` values, where
108          * the first and last values are `NULL`, and the other values define
109          * the allowed enum values.  The first non-NULL value is the default
110          * value.  After the arguments are parsed, the first element in the array
111          * points to the selected enum value (pointers will be equal).
112          */
113         const char     **c;
114         /** Boolean value for etBOOL. */
115         gmx_bool        *b;
116         /** Vector value for etRVEC. */
117         rvec            *rv;
118     }           u;
119     /*! \brief
120      * Description for the argument.
121      *
122      * If the string starts with `HIDDEN`, then the argument is hidden from
123      * normal help listing and shell completions.
124      */
125     const char *desc;
126 } t_pargs;
127
128 /*! \brief
129  * Returns ordinal number for an etENUM argument.
130  *
131  * \param[in] enumc  Array passed to `t_pargs` for an etENUM argument.
132  * \returns   Index of selected enum value in the array.
133  *
134  * See t_pargs::u::c for the expected format of the array, including how the
135  * first element should be initialized.
136  * Note that the return value starts at one instead of zero: if the first enum
137  * value is selected, this returns 1.
138  */
139 int nenum(const char *const enumc[]);
140
141 /*! \brief
142  * Returns value of an etINT option.
143  *
144  * \param[in] option Name of etINT argument to query.
145  * \param[in] nparg  Number of elements in \p pa.
146  * \param[in] pa     Array of arguments.
147  * \returns   Value of \p option.
148  *
149  * \p option must specify a valid argument in \p pa of the correct type.
150  */
151 int opt2parg_int(const char *option, int nparg, t_pargs pa[]);
152
153 /*! \brief
154  * Returns value of an etBOOL option.
155  *
156  * \param[in] option Name of etBOOL argument to query.
157  * \param[in] nparg  Number of elements in \p pa.
158  * \param[in] pa     Array of arguments.
159  * \returns   Value of \p option.
160  *
161  * \p option must specify a valid argument in \p pa of the correct type.
162  */
163 gmx_bool opt2parg_bool(const char *option, int nparg, t_pargs pa[]);
164
165 /*! \brief
166  * Returns value of an etREAL/etTIME option.
167  *
168  * \param[in] option Name of etREAL/etTIME argument to query.
169  * \param[in] nparg  Number of elements in \p pa.
170  * \param[in] pa     Array of arguments.
171  * \returns   Value of \p option.
172  *
173  * \p option must specify a valid argument in \p pa of the correct type.
174  */
175 real opt2parg_real(const char *option, int nparg, t_pargs pa[]);
176
177 /*! \brief
178  * Returns value of an etSTR option.
179  *
180  * \param[in] option Name of etSTR argument to query.
181  * \param[in] nparg  Number of elements in \p pa.
182  * \param[in] pa     Array of arguments.
183  * \returns   Value of \p option.
184  *
185  * \p option must specify a valid argument in \p pa of the correct type.
186  */
187 const char *opt2parg_str(const char *option, int nparg, t_pargs pa[]);
188
189 /*! \brief
190  * Returns value of an etENUM option.
191  *
192  * \param[in] option Name of etENUM argument to query.
193  * \param[in] nparg  Number of elements in \p pa.
194  * \param[in] pa     Array of arguments.
195  * \returns   Value of \p option.
196  *
197  * \p option must specify a valid argument in \p pa of the correct type.
198  */
199 const char *opt2parg_enum(const char *option, int nparg, t_pargs pa[]);
200
201 /*! \brief
202  * Returns whether an argument has been set.
203  *
204  * \param[in] option Name of argument to check.
205  * \param[in] nparg  Number of elements in \p pa.
206  * \param[in] pa     Array of arguments.
207  * \returns   `true` if \p option has been set.
208  *
209  * \p option must specify a valid argument in \p pa.
210  */
211 gmx_bool opt2parg_bSet(const char *option, int nparg, const t_pargs *pa);
212
213
214 /** Add option -w to view output files (must be implemented in program). */
215 #define PCA_CAN_VIEW       (1<<5)
216 /** Add option to set begin time for trajectory reading. */
217 #define PCA_CAN_BEGIN      (1<<6)
218 /** Add option to set end time for trajectory reading. */
219 #define PCA_CAN_END        (1<<7)
220 /** Add option to set time step for trajectory reading. */
221 #define PCA_CAN_DT         (1<<14)
222 /** Add all options for trajectory time control. */
223 #define PCA_CAN_TIME       (PCA_CAN_BEGIN | PCA_CAN_END | PCA_CAN_DT)
224 /** Add option -tu to set time unit for output. */
225 #define PCA_TIME_UNIT      (1<<15)
226 /** Add option -deffnm to set default for all file options. */
227 #define PCA_CAN_SET_DEFFNM (1<<10)
228 /** Do not raise a fatal error when invalid options are encountered. */
229 #define PCA_NOEXIT_ON_ARGS (1<<11)
230 /** Don't do any special processing for ffREAD files */
231 #define PCA_DISABLE_INPUT_FILE_CHECKING (1<<17)
232
233 /*! \brief
234  * Parse command-line arguments.
235  *
236  * Some common default arguments are also recognized in addition to those
237  * provided through \p pa.  The set of recognized default arguments is affected
238  * by \p Flags.
239  *
240  * Recognized arguments are removed from the list.
241  *
242  * For full functionality, this function needs to be used within a function
243  * that is passed to gmx_run_cmain().  It should be called as the first thing in
244  * that function.  Initialization code can be executed before it, but you need
245  * to be aware that if the program is executed with -h and MPI, the code before
246  * parse_common_args() only executes on the master node.
247  *
248  * If the return value is `FALSE`, the program should return immediately (this
249  * is necessary for -h and a few other cases).
250  *
251  * \see gmx_run_cmain().
252  */
253 gmx_bool parse_common_args(int *argc, char *argv[], unsigned long Flags,
254                            int nfile, t_filenm fnm[], int npargs, t_pargs *pa,
255                            int ndesc, const char **desc,
256                            int nbugs, const char **bugs,
257                            gmx_output_env_t **oenv);
258
259 /*! \} */
260
261 #endif