1a223d75c7fa99c344a7037641967268a272d403
[alexxy/gromacs.git] / include / readinp.h
1 /*
2  * $Id$
3  * 
4  *       This source code is part of
5  * 
6  *        G   R   O   M   A   C   S
7  * 
8  * GROningen MAchine for Chemical Simulations
9  * 
10  *               VERSION 2.0
11  * 
12  * Copyright (c) 1991-1999
13  * BIOSON Research Institute, Dept. of Biophysical Chemistry
14  * University of Groningen, The Netherlands
15  * 
16  * Please refer to:
17  * GROMACS: A message-passing parallel molecular dynamics implementation
18  * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
19  * Comp. Phys. Comm. 91, 43-56 (1995)
20  * 
21  * Also check out our WWW page:
22  * http://md.chem.rug.nl/~gmx
23  * or e-mail to:
24  * gromacs@chem.rug.nl
25  * 
26  * And Hey:
27  * Green Red Orange Magenta Azure Cyan Skyblue
28  */
29
30 #ifndef _readinp_h
31 #define _readinp_h
32
33 static char *SRCID_readinp_h = "$Id$";
34
35 #ifdef HAVE_CONFIG_H
36 #include <config.h>
37 #endif
38
39 #include "typedefs.h"
40
41 typedef struct {
42   int  count;
43   bool bSet;
44   char *name;
45   char *value;
46 } t_inpfile;
47
48 extern t_inpfile *read_inpfile(char *fn,int *ninp);
49
50 extern void write_inpfile(char *fn,int ninp,t_inpfile inp[]);
51
52 extern int get_eint(int *ninp,t_inpfile **inp,char *name,int def);
53
54 extern real get_ereal(int *ninp,t_inpfile **inp,char *name,real def);
55
56 extern char *get_estr(int *ninp,t_inpfile **inp,char *name,char *def);
57
58 extern int get_eeenum(int *ninp,t_inpfile **inp,char *name,char **defs,
59                       int *nerror,bool bPrintError);
60 /* defs must be NULL terminated, 
61  * Add errors to nerror 
62  * When bPrintError=TRUE and invalid enum: print "ERROR: ..."
63  */
64
65 extern int get_eenum(int *ninp,t_inpfile **inp,char *name,char **defs);
66 /* defs must be NULL terminated */
67
68 /* Here are some macros to extract data from the inp structures.
69  * Elements that are  removed  from the list after reading
70  */
71 #define STYPE(name,var,def)  if ((tmp=get_estr(&ninp,&inp,name,def)) != NULL) strcpy(var,tmp)
72 #define ITYPE(name,var,def)  var=get_eint(&ninp,&inp,name,def)
73 #define RTYPE(name,var,def)  var=get_ereal(&ninp,&inp,name,def)
74 #define ETYPE(name,var,defs) var=get_eenum(&ninp,&inp,name,defs)
75 #define EETYPE(name,var,defs,nerr,bErr) var=get_eeenum(&ninp,&inp,name,defs,nerr,bErr)
76 #define CCTYPE(s) STYPE("\n; "s,dummy,NULL)
77 #define CTYPE(s)  STYPE("; "s,dummy,NULL)
78 /* This last one prints a comment line where you can add some explanation */
79
80 /* This structure is used for parsing arguments off the comand line */
81 enum { 
82   etINT, etREAL, etTIME, etSTR,    etBOOL, etRVEC,   etENUM, etNR
83 };
84 /* names to print in help info */
85 static char *argtp[etNR] = {
86   "int", "real", "time", "string", "bool", "vector", "enum" 
87 };
88
89 typedef struct {
90   char *option;
91   bool bSet;
92   int  type;
93   union {
94     void *v;   /* This is a nasty workaround, to be able to use initialized */
95     int  *i;   /* arrays */
96     real *r;
97     char **c;  /* Must be pointer to string (when type == etSTR)         */
98                /* or null terminated list of enums (when type == etENUM) */
99     bool *b;
100     rvec *rv;
101   } u;
102   char *desc;
103 } t_pargs;
104
105 extern void get_pargs(int *argc,char *argv[],int nparg,t_pargs pa[],
106                       bool bKeepArgs);
107 /* Read a number of arguments from the command line. 
108  * For etINT, etREAL and etCHAR an extra argument is read (when present)
109  * for etBOOL the boolean option is changed to the negate value
110  * If !bKeepArgs, the command line arguments are removed from the command line
111  */
112
113 extern bool is_hidden(t_pargs *pa);
114 /* Return TRUE when the option is a secret one */
115
116 extern char *pa_val(t_pargs *pa);
117 /* Return a pointer to a static buffer containing the value of pa */
118
119 extern int opt2parg_int(char *option,int nparg,t_pargs pa[]);
120
121 extern bool opt2parg_bool(char *option,int nparg,t_pargs pa[]);
122
123 extern real opt2parg_real(char *option,int nparg,t_pargs pa[]);
124
125 extern char *opt2parg_str(char *option,int nparg,t_pargs pa[]);
126
127 extern char *opt2parg_enum(char *option,int nparg,t_pargs pa[]);
128
129 extern bool opt2parg_bSet(char *option,int nparg,t_pargs pa[]);
130
131 extern void print_pargs(FILE *fp, int npargs,t_pargs pa[]);
132
133 extern void pr_enums(FILE *fp, int npargs,t_pargs pa[]);
134
135 #endif