Merge release-4-6 into release-5-0
[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, 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 "../legacyheaders/types/simple.h"
48 #include "../legacyheaders/oenv.h"
49 #include "../fileio/filenm.h"
50
51 #ifdef __cplusplus
52 extern "C"
53 {
54 #endif
55
56 /*! \addtogroup module_commandline
57  * \{
58  */
59
60 /** Command line argument type. */
61 enum
62 {
63     etINT, etINT64, etREAL, etTIME, etSTR, etBOOL, etRVEC, etENUM, etNR
64 };
65
66 /*! \brief
67  * Command-line argument definition for C code.
68  *
69  * \inpublicapi
70  */
71 typedef struct
72 {
73     /** Name of the argument (with leading dash included). */
74     const char *option;
75     /** Whether the argument is set (should be initialized to `FALSE`). */
76     gmx_bool    bSet;
77     /** Type of the argument (one of the enums in pargs.h). */
78     int         type;
79     /*! \brief
80      * Pointer to variable that is to receive the value.
81      *
82      * The expected type depends on the value of \a type.
83      * If an argument is not set by the user, then the pointed value is not
84      * changed.  In other words, the initial value for the variable defines the
85      * default value.
86      */
87     union
88     {
89         /*! \brief
90          * Generic pointer for operations that do not need type information.
91          *
92          * Needs to be the first member to use initialized arrays.
93          */
94         void            *v;
95         /** Integer value for etINT. */
96         int             *i;
97         /** Integer value for etINT64. */
98         gmx_int64_t     *is;
99         /** Real value for etREAL and etTIME. */
100         real            *r;
101         /*! \brief
102          * String value for etSTR and etENUM.
103          *
104          * For etSTR, this should point to a `const char *` variable, which
105          * will receive a pointer to the string value (caller should not free
106          * the string).
107          *
108          * For etENUM, this should be an array of `const char *` values, where
109          * the first and last values are `NULL`, and the other values define
110          * the allowed enum values.  The first non-NULL value is the default
111          * value.  After the arguments are parsed, the first element in the array
112          * points to the selected enum value (pointers will be equal).
113          */
114         const char     **c;
115         /** Boolean value for etBOOL. */
116         gmx_bool        *b;
117         /** Vector value for etRVEC. */
118         rvec            *rv;
119     }           u;
120     /*! \brief
121      * Description for the argument.
122      *
123      * If the string starts with `HIDDEN`, then the argument is hidden from
124      * normal help listing and shell completions.
125      */
126     const char *desc;
127 } t_pargs;
128
129 /*! \brief
130  * Returns ordinal number for an etENUM argument.
131  *
132  * \param[in] enumc  Array passed to `t_pargs` for an etENUM argument.
133  * \returns   Index of selected enum value in the array.
134  *
135  * See t_pargs::u::c for the expected format of the array, including how the
136  * first element should be initialized.
137  * Note that the return value starts at one instead of zero: if the first enum
138  * value is selected, this returns 1.
139  */
140 int nenum(const char *const enumc[]);
141
142 /*! \brief
143  * Returns value of an etINT option.
144  *
145  * \param[in] option Name of etINT argument to query.
146  * \param[in] nparg  Number of elements in \p pa.
147  * \param[in] pa     Array of arguments.
148  * \returns   Value of \p option.
149  *
150  * \p option must specify a valid argument in \p pa of the correct type.
151  */
152 int opt2parg_int(const char *option, int nparg, t_pargs pa[]);
153
154 /*! \brief
155  * Returns value of an etBOOL option.
156  *
157  * \param[in] option Name of etBOOL argument to query.
158  * \param[in] nparg  Number of elements in \p pa.
159  * \param[in] pa     Array of arguments.
160  * \returns   Value of \p option.
161  *
162  * \p option must specify a valid argument in \p pa of the correct type.
163  */
164 gmx_bool opt2parg_bool(const char *option, int nparg, t_pargs pa[]);
165
166 /*! \brief
167  * Returns value of an etREAL/etTIME option.
168  *
169  * \param[in] option Name of etREAL/etTIME argument to query.
170  * \param[in] nparg  Number of elements in \p pa.
171  * \param[in] pa     Array of arguments.
172  * \returns   Value of \p option.
173  *
174  * \p option must specify a valid argument in \p pa of the correct type.
175  */
176 real opt2parg_real(const char *option, int nparg, t_pargs pa[]);
177
178 /*! \brief
179  * Returns value of an etSTR option.
180  *
181  * \param[in] option Name of etSTR argument to query.
182  * \param[in] nparg  Number of elements in \p pa.
183  * \param[in] pa     Array of arguments.
184  * \returns   Value of \p option.
185  *
186  * \p option must specify a valid argument in \p pa of the correct type.
187  */
188 const char *opt2parg_str(const char *option, int nparg, t_pargs pa[]);
189
190 /*! \brief
191  * Returns value of an etENUM option.
192  *
193  * \param[in] option Name of etENUM argument to query.
194  * \param[in] nparg  Number of elements in \p pa.
195  * \param[in] pa     Array of arguments.
196  * \returns   Value of \p option.
197  *
198  * \p option must specify a valid argument in \p pa of the correct type.
199  */
200 const char *opt2parg_enum(const char *option, int nparg, t_pargs pa[]);
201
202 /*! \brief
203  * Returns whether an argument has been set.
204  *
205  * \param[in] option Name of argument to check.
206  * \param[in] nparg  Number of elements in \p pa.
207  * \param[in] pa     Array of arguments.
208  * \returns   `true` if \p option has been set.
209  *
210  * \p option must specify a valid argument in \p pa.
211  */
212 gmx_bool opt2parg_bSet(const char *option, int nparg, t_pargs pa[]);
213
214
215 /** Add option -w to view output files (must be implemented in program). */
216 #define PCA_CAN_VIEW       (1<<5)
217 /** Add option to set begin time for trajectory reading. */
218 #define PCA_CAN_BEGIN      (1<<6)
219 /** Add option to set end time for trajectory reading. */
220 #define PCA_CAN_END        (1<<7)
221 /** Add option to set time step for trajectory reading. */
222 #define PCA_CAN_DT         (1<<14)
223 /** Add all options for trajectory time control. */
224 #define PCA_CAN_TIME       (PCA_CAN_BEGIN | PCA_CAN_END | PCA_CAN_DT)
225 /** Add option -tu to set time unit for output. */
226 #define PCA_TIME_UNIT      (1<<15)
227 /** Add option -deffnm to set default for all file options. */
228 #define PCA_CAN_SET_DEFFNM (1<<10)
229 /** Do not raise a fatal error when invalid options are encountered. */
230 #define PCA_NOEXIT_ON_ARGS (1<<11)
231 /** Do not print help output (used for non-master nodes). */
232 #define PCA_QUIET          (1<<12)
233 /** Default to low priority. */
234 #define PCA_BE_NICE        (1<<13)
235 /** Is this node not reading: for parallel all nodes but the master */
236 #define PCA_NOT_READ_NODE  (1<<16)
237
238 /*! \brief
239  * Parse command-line arguments.
240  *
241  * Some common default arguments are also recognized in addition to those
242  * provided through \p pa.  The set of recognized default arguments is affected
243  * by \p Flags.
244  *
245  * Recognized arguments are removed from the list.
246  */
247 gmx_bool parse_common_args(int *argc, char *argv[], unsigned long Flags,
248                            int nfile, t_filenm fnm[], int npargs, t_pargs *pa,
249                            int ndesc, const char **desc,
250                            int nbugs, const char **bugs,
251                            output_env_t *oenv);
252
253 /*! \} */
254
255 #ifdef __cplusplus
256 }
257 #endif
258
259 #endif