Upped the version to 3.2.0
[gromacs.git] / include / readinp.h
blob4a4919a4b1c401d917caddca216fbd0b1319c67d
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.2.0
11 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
12 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
13 * Copyright (c) 2001-2004, The GROMACS development team,
14 * check out http://www.gromacs.org for more information.
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.
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.
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.
31 * For more info, check our website at http://www.gromacs.org
33 * And Hey:
34 * Gromacs Runs On Most of All Computer Systems
37 #ifndef _readinp_h
38 #define _readinp_h
40 #ifdef HAVE_CONFIG_H
41 #include <config.h>
42 #endif
44 #include "typedefs.h"
46 typedef struct {
47 int count;
48 bool bSet;
49 char *name;
50 char *value;
51 } t_inpfile;
53 extern t_inpfile *read_inpfile(char *fn,int *ninp);
55 extern void write_inpfile(char *fn,int ninp,t_inpfile inp[]);
57 extern int get_eint(int *ninp,t_inpfile **inp,const char *name,int def);
59 extern real get_ereal(int *ninp,t_inpfile **inp,const char *name,real def);
61 extern char *get_estr(int *ninp,t_inpfile **inp,const char *name,char *def);
63 extern int get_eeenum(int *ninp,t_inpfile **inp,const char *name,const char **defs,
64 int *nerror,bool bPrintError);
65 /* defs must be NULL terminated,
66 * Add errors to nerror
67 * When bPrintError=TRUE and invalid enum: print "ERROR: ..."
70 extern int get_eenum(int *ninp,t_inpfile **inp,const char *name,const char **defs);
71 /* defs must be NULL terminated */
73 /* Here are some macros to extract data from the inp structures.
74 * Elements that are removed from the list after reading
76 #define STYPE(name,var,def) if ((tmp=get_estr(&ninp,&inp,name,def)) != NULL) strcpy(var,tmp)
77 #define ITYPE(name,var,def) var=get_eint(&ninp,&inp,name,def)
78 #define RTYPE(name,var,def) var=get_ereal(&ninp,&inp,name,def)
79 #define ETYPE(name,var,defs) var=get_eenum(&ninp,&inp,name,defs)
80 #define EETYPE(name,var,defs,nerr,bErr) var=get_eeenum(&ninp,&inp,name,defs,nerr,bErr)
81 #define CCTYPE(s) STYPE("\n; "s,dummy,NULL)
82 #define CTYPE(s) STYPE("; "s,dummy,NULL)
83 /* This last one prints a comment line where you can add some explanation */
85 /* This structure is used for parsing arguments off the comand line */
86 enum {
87 etINT, etREAL, etTIME, etSTR, etBOOL, etRVEC, etENUM, etNR
89 /* names to print in help info */
90 static char *argtp[etNR] = {
91 "int", "real", "time", "string", "bool", "vector", "enum"
94 typedef struct {
95 char *option;
96 bool bSet;
97 int type;
98 union {
99 void *v; /* This is a nasty workaround, to be able to use initialized */
100 int *i; /* arrays */
101 real *r;
102 char **c; /* Must be pointer to string (when type == etSTR) */
103 /* or null terminated list of enums (when type == etENUM) */
104 bool *b;
105 rvec *rv;
106 } u;
107 char *desc;
108 } t_pargs;
110 extern void get_pargs(int *argc,char *argv[],int nparg,t_pargs pa[],
111 bool bKeepArgs);
112 /* Read a number of arguments from the command line.
113 * For etINT, etREAL and etCHAR an extra argument is read (when present)
114 * for etBOOL the boolean option is changed to the negate value
115 * If !bKeepArgs, the command line arguments are removed from the command line
118 extern bool is_hidden(t_pargs *pa);
119 /* Return TRUE when the option is a secret one */
121 extern char *pa_val(t_pargs *pa,char *buf, int sz);
122 /* Return the value of pa in the provided buffer buf, of size sz.
123 * The return value is also a pointer to buf.
126 extern int opt2parg_int(char *option,int nparg,t_pargs pa[]);
128 extern bool opt2parg_bool(char *option,int nparg,t_pargs pa[]);
130 extern real opt2parg_real(char *option,int nparg,t_pargs pa[]);
132 extern char *opt2parg_str(char *option,int nparg,t_pargs pa[]);
134 extern char *opt2parg_enum(char *option,int nparg,t_pargs pa[]);
136 extern bool opt2parg_bSet(char *option,int nparg,t_pargs pa[]);
138 extern void print_pargs(FILE *fp, int npargs,t_pargs pa[]);
140 extern void pr_enums(FILE *fp, int npargs,t_pargs pa[],int shell);
142 #endif