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