Fix malformed CUDA version macro check
[alexxy/gromacs.git] / include / readinp.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  * check out http://www.gromacs.org for more information.
7  * Copyright (c) 2012,2013, by the GROMACS development team, led by
8  * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9  * others, as listed in the AUTHORS file in the top-level source
10  * directory and at http://www.gromacs.org.
11  *
12  * GROMACS is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public License
14  * as published by the Free Software Foundation; either version 2.1
15  * of the License, or (at your option) any later version.
16  *
17  * GROMACS is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with GROMACS; if not, see
24  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
26  *
27  * If you want to redistribute modifications to GROMACS, please
28  * consider that scientific software is very special. Version
29  * control is crucial - bugs must be traceable. We will be happy to
30  * consider code for inclusion in the official distribution, but
31  * derived work must not be called official GROMACS. Details are found
32  * in the README & COPYING files - if they are missing, get the
33  * official version at http://www.gromacs.org.
34  *
35  * To help us fund GROMACS development, we humbly ask that you cite
36  * the research papers on the package. Check out http://www.gromacs.org.
37  */
38
39 #ifndef _readinp_h
40 #define _readinp_h
41 #include "visibility.h"
42 #include "typedefs.h"
43 #include "warninp.h"
44
45
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49
50 typedef struct {
51     int      count;     /* sort order for output  */
52     gmx_bool bObsolete; /* whether it is an obsolete param value */
53     gmx_bool bSet;      /* whether it it has been read out */
54     char    *name;      /* name of the parameter */
55     char    *value;     /* parameter value string */
56     int      inp_count; /* number of einps read. Only valid for the first item
57                                                  in the inpfile list. */
58 } t_inpfile;
59 /* entry in input files (like .mdp files).
60    Initally read in with read_inpfile, then filled in with missing values
61    through get_eint, get_ereal, etc. */
62
63
64
65 GMX_LIBGMX_EXPORT
66 t_inpfile *read_inpfile(const char *fn, int *ninp,
67                         char **cppopts,
68                         warninp_t wi);
69 /* Create & populate a t_inpfile struct from values in file fn.
70    fn = the file name
71    ninp = the number of read parameters
72    cppopts = the cpp-style options for #include paths and #defines */
73
74 GMX_LIBGMX_EXPORT
75 void write_inpfile(const char *fn, int ninp, t_inpfile inp[],
76                    gmx_bool bHaltOnUnknown,
77                    warninp_t wi);
78
79 GMX_LIBGMX_EXPORT
80 void replace_inp_entry(int ninp, t_inpfile *inp,
81                        const char *old_entry, const char *new_entry);
82
83 GMX_LIBGMX_EXPORT
84 int get_eint(int *ninp, t_inpfile **inp, const char *name, int def,
85              warninp_t wi);
86
87 GMX_LIBGMX_EXPORT
88 gmx_large_int_t get_egmx_large_int(int *ninp, t_inpfile **inp,
89                                    const char *name, gmx_large_int_t def,
90                                    warninp_t);
91
92 GMX_LIBGMX_EXPORT
93 double get_ereal(int *ninp, t_inpfile **inp, const char *name, double def,
94                  warninp_t wi);
95
96 GMX_LIBGMX_EXPORT
97 const char *get_estr(int *ninp, t_inpfile **inp, const char *name, const char *def);
98
99 GMX_LIBGMX_EXPORT
100 int get_eeenum(int *ninp, t_inpfile **inp, const char *name, const char **defs,
101                warninp_t wi);
102 /* defs must be NULL terminated */
103
104 GMX_LIBGMX_EXPORT
105 int get_eenum(int *ninp, t_inpfile **inp, const char *name, const char **defs);
106 /* defs must be NULL terminated */
107
108 /* Here are some dirty macros to extract data from the inp structures.
109  * Most macros assume the variables ninp, inp and wi are present.
110  * Elements are removed from the list after reading.
111  */
112 #define REM_TYPE(name)       replace_inp_entry(ninp, inp, name, NULL)
113 #define REPL_TYPE(old, new)   replace_inp_entry(ninp, inp, old, new)
114 #define STYPE(name, var, def)  if ((tmp = get_estr(&ninp, &inp, name, def)) != NULL) strcpy(var, tmp)
115 #define STYPENC(name, def) get_estr(&ninp, &inp, name, def)
116 #define ITYPE(name, var, def)  var    = get_eint(&ninp, &inp, name, def, wi)
117 #define STEPTYPE(name, var, def)  var = get_egmx_large_int(&ninp, &inp, name, def, wi)
118 #define RTYPE(name, var, def)  var    = get_ereal(&ninp, &inp, name, def, wi)
119 #define ETYPE(name, var, defs) var    = get_eenum(&ninp, &inp, name, defs)
120 #define EETYPE(name, var, defs) var   = get_eeenum(&ninp, &inp, name, defs, wi)
121 #define CCTYPE(s) STYPENC("\n; "s, NULL)
122 #define CTYPE(s)  STYPENC("; "s, NULL)
123 /* This last one prints a comment line where you can add some explanation */
124
125 /* This structure is used for parsing arguments off the comand line */
126 enum {
127     etINT, etGMX_LARGE_INT, etREAL, etTIME, etSTR,    etBOOL, etRVEC,   etENUM, etNR
128 };
129
130 /* names to print in help info */
131 static const char *argtp[etNR] = {
132     "int", "step", "real", "time", "string", "bool", "vector", "enum"
133 };
134
135 typedef struct {
136     const char *option;
137     gmx_bool    bSet;
138     int         type;
139     union {
140         void            *v; /* This is a nasty workaround, to be able to use initialized */
141         int             *i; /* arrays */
142         gmx_large_int_t *is;
143         real            *r;
144         const char     **c; /* Must be pointer to string (when type == etSTR)         */
145         /* or null terminated list of enums (when type == etENUM) */
146         gmx_bool        *b;
147         rvec            *rv;
148     } u;
149     const char *desc;
150 } t_pargs;
151
152 void get_pargs(int *argc, char *argv[], int nparg, t_pargs pa[],
153                gmx_bool bKeepArgs);
154 /* Read a number of arguments from the command line.
155  * For etINT, etREAL and etCHAR an extra argument is read (when present)
156  * for etBOOL the gmx_boolean option is changed to the negate value
157  * If !bKeepArgs, the command line arguments are removed from the command line
158  */
159
160 gmx_bool is_hidden(t_pargs *pa);
161 /* Return TRUE when the option is a secret one */
162
163 char *pa_val(t_pargs *pa, char *buf, int sz);
164 /* Return the value of pa in the provided buffer buf, of size sz.
165  * The return value is also a pointer to buf.
166  */
167
168 int opt2parg_int(const char *option, int nparg, t_pargs pa[]);
169
170 gmx_bool opt2parg_gmx_bool(const char *option, int nparg, t_pargs pa[]);
171
172 GMX_LIBGMX_EXPORT
173 real opt2parg_real(const char *option, int nparg, t_pargs pa[]);
174
175 GMX_LIBGMX_EXPORT
176 const char *opt2parg_str(const char *option, int nparg, t_pargs pa[]);
177
178 const char *opt2parg_enum(const char *option, int nparg, t_pargs pa[]);
179
180 GMX_LIBGMX_EXPORT
181 gmx_bool opt2parg_bSet(const char *option, int nparg, t_pargs pa[]);
182
183 void print_pargs(FILE *fp, int npargs, t_pargs pa[], gmx_bool bLeadingSpace);
184
185 char *pargs_print_line(t_pargs *pa, gmx_bool bLeadingSpace);
186
187 void pr_enums(FILE *fp, int npargs, t_pargs pa[], int shell);
188
189 #ifdef __cplusplus
190 }
191 #endif
192
193 #endif