Tagged files with gromacs 3.0 header and added some license info
[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 3.0
11  * 
12  * Copyright (c) 1991-2001
13  * BIOSON Research Institute, Dept. of Biophysical Chemistry
14  * University of Groningen, The Netherlands
15  * 
16  * This program is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU General Public License
18  * as published by the Free Software Foundation; either version 2
19  * of the License, or (at your option) any later version.
20  * 
21  * If you want to redistribute modifications, please consider that
22  * scientific software is very special. Version control is crucial -
23  * bugs must be traceable. We will be happy to consider code for
24  * inclusion in the official distribution, but derived work must not
25  * be called official GROMACS. Details are found in the README & COPYING
26  * files - if they are missing, get the official version at www.gromacs.org.
27  * 
28  * To help us fund GROMACS development, we humbly ask that you cite
29  * the papers on the package - you can find them in the top README file.
30  * 
31  * Do check out http://www.gromacs.org , or mail us at gromacs@gromacs.org .
32  * 
33  * And Hey:
34  * GRoups of Organic Molecules in ACtion for Science
35  */
36
37 #ifndef _readinp_h
38 #define _readinp_h
39
40 static char *SRCID_readinp_h = "$Id$";
41 #ifdef HAVE_CONFIG_H
42 #include <config.h>
43 #endif
44
45 #include "typedefs.h"
46
47 typedef struct {
48   int  count;
49   bool bSet;
50   char *name;
51   char *value;
52 } t_inpfile;
53
54 extern t_inpfile *read_inpfile(char *fn,int *ninp);
55
56 extern void write_inpfile(char *fn,int ninp,t_inpfile inp[]);
57
58 extern int get_eint(int *ninp,t_inpfile **inp,char *name,int def);
59
60 extern real get_ereal(int *ninp,t_inpfile **inp,char *name,real def);
61
62 extern char *get_estr(int *ninp,t_inpfile **inp,char *name,char *def);
63
64 extern int get_eeenum(int *ninp,t_inpfile **inp,char *name,char **defs,
65                       int *nerror,bool bPrintError);
66 /* defs must be NULL terminated, 
67  * Add errors to nerror 
68  * When bPrintError=TRUE and invalid enum: print "ERROR: ..."
69  */
70
71 extern int get_eenum(int *ninp,t_inpfile **inp,char *name,char **defs);
72 /* defs must be NULL terminated */
73
74 /* Here are some macros to extract data from the inp structures.
75  * Elements that are  removed  from the list after reading
76  */
77 #define STYPE(name,var,def)  if ((tmp=get_estr(&ninp,&inp,name,def)) != NULL) strcpy(var,tmp)
78 #define ITYPE(name,var,def)  var=get_eint(&ninp,&inp,name,def)
79 #define RTYPE(name,var,def)  var=get_ereal(&ninp,&inp,name,def)
80 #define ETYPE(name,var,defs) var=get_eenum(&ninp,&inp,name,defs)
81 #define EETYPE(name,var,defs,nerr,bErr) var=get_eeenum(&ninp,&inp,name,defs,nerr,bErr)
82 #define CCTYPE(s) STYPE("\n; "s,dummy,NULL)
83 #define CTYPE(s)  STYPE("; "s,dummy,NULL)
84 /* This last one prints a comment line where you can add some explanation */
85
86 /* This structure is used for parsing arguments off the comand line */
87 enum { 
88   etINT, etREAL, etTIME, etSTR,    etBOOL, etRVEC,   etENUM, etNR
89 };
90 /* names to print in help info */
91 static char *argtp[etNR] = {
92   "int", "real", "time", "string", "bool", "vector", "enum" 
93 };
94
95 typedef struct {
96   char *option;
97   bool bSet;
98   int  type;
99   union {
100     void *v;   /* This is a nasty workaround, to be able to use initialized */
101     int  *i;   /* arrays */
102     real *r;
103     char **c;  /* Must be pointer to string (when type == etSTR)         */
104                /* or null terminated list of enums (when type == etENUM) */
105     bool *b;
106     rvec *rv;
107   } u;
108   char *desc;
109 } t_pargs;
110
111 extern void get_pargs(int *argc,char *argv[],int nparg,t_pargs pa[],
112                       bool bKeepArgs);
113 /* Read a number of arguments from the command line. 
114  * For etINT, etREAL and etCHAR an extra argument is read (when present)
115  * for etBOOL the boolean option is changed to the negate value
116  * If !bKeepArgs, the command line arguments are removed from the command line
117  */
118
119 extern bool is_hidden(t_pargs *pa);
120 /* Return TRUE when the option is a secret one */
121
122 extern char *pa_val(t_pargs *pa);
123 /* Return a pointer to a static buffer containing the value of pa */
124
125 extern int opt2parg_int(char *option,int nparg,t_pargs pa[]);
126
127 extern bool opt2parg_bool(char *option,int nparg,t_pargs pa[]);
128
129 extern real opt2parg_real(char *option,int nparg,t_pargs pa[]);
130
131 extern char *opt2parg_str(char *option,int nparg,t_pargs pa[]);
132
133 extern char *opt2parg_enum(char *option,int nparg,t_pargs pa[]);
134
135 extern bool opt2parg_bSet(char *option,int nparg,t_pargs pa[]);
136
137 extern void print_pargs(FILE *fp, int npargs,t_pargs pa[]);
138
139 extern void pr_enums(FILE *fp, int npargs,t_pargs pa[]);
140
141 #endif