c97f6e1265825c78cd01adc416d184c4eb65ee2a
[alexxy/gromacs.git] / include / statutil.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 _statutil_h
31 #define _statutil_h
32
33 static char *SRCID_statutil_h = "$Id$";
34
35 #ifdef HAVE_CONFIG_H
36 #include <config.h>
37 #endif
38
39 #ifdef CPLUSPLUS
40 extern "C" {
41 #endif
42
43 #include <stdio.h>
44 #include "typedefs.h"
45 #include "filenm.h"
46 #include "readinp.h"
47 #include "wman.h"
48   
49 typedef int t_first_x(int *status,char *fn,real *t,rvec **x,matrix box);
50 typedef bool t_next_x(int status,real *t,int natoms,rvec x[],matrix box);
51
52 /* I/O function types */
53
54 extern char *Program(void);
55 /* Return the name of the program */
56 extern char *ShortProgram(void);
57 /* Id. without leading directory */
58
59 /************************************************
60  *             Trajectory functions
61  ************************************************/
62
63 extern int prec2ndec(real prec);
64 /* Convert precision in 1/(nm) to number of decimal places */
65
66 extern void clear_trxframe(t_trxframe *fr,bool bFirst);
67 /* Set all content booleans to FALSE.
68  * When bFirst = TRUE, set natoms=-1, all pointers to NULL
69  *                     and all data to zero.
70  */
71
72 extern int nframes_read(void);
73 /* Returns the number of frames read from the trajectory */
74
75 int write_trxframe_indexed(int status,t_trxframe *fr,int nind,atom_id *ind);
76 /* Write an indexed frame to a TRX file, see write_trxframe */
77
78 int write_trxframe(int status,t_trxframe *fr);
79 /* Write a frame to a TRX file. 
80  * Only entries for which the boolean is TRUE will be written,
81  * except for step, time, lambda and/or box, which may not be
82  * omitted for certain trajectory formats.
83  * The precision for .xtc and .gro is fr->prec, when fr->bPrec=FALSE,
84  * the precision is set to 1000.
85  */
86
87 int write_trx(int status,int nind,atom_id *ind,t_atoms *atoms,
88               int step,real time,matrix box,rvec x[],rvec *v);
89 /* Write an indexed frame to a TRX file.
90  * v can be NULL. 
91  * atoms can be NULL for file types which don't need atom names.
92  */ 
93
94 void close_trx(int status);
95 /* Close trj file as opened with read_first_x, read_frist_frame
96  * or open_trx. Identical to close_trj.
97  */
98
99 int open_trx(char *outfile,char *filemode);
100 /* Open a TRX file and return the file number */
101
102 extern bool bRmod(double a,double b);
103 /* Returns TRUE when a MOD b = 0, using a margin which is slightly
104  * larger than the float/double precision.
105  */
106
107 extern int check_times(real t,real t0);
108 /* This routine checkes if the read-in time is correct or not;
109  * returns -1 if t<tbegin or t MOD dt = t0,
110  *         0  if tbegin <= t <=tend,
111  *         1  if t>tend
112  */
113
114 extern char *time_label(void);
115 /* return time unit label (e.g. ps or ns) */
116
117 extern real time_factor(void);
118 /* return time conversion factor from ps (i.e. 1e-3 for ps->ns) */
119
120 extern real convert_time(real time);
121 /* return converted time */
122
123 extern void convert_times(int n, real *time);
124 /* convert array of times */
125
126 extern void default_time(void);
127 /* set time conversion to default (i.e. ps) */
128
129 /* For trxframe.flags, used in trxframe read routines.
130  * When a READ flag is set, the field will be read when present,
131  * but a frame might be returned which does not contain the field.
132  * When a NEED flag is set, frames not containing the field will be skipped.
133  */
134 #define TRX_READ_X    (1<<0)
135 #define TRX_NEED_X    (1<<1)
136 #define TRX_READ_V    (1<<2)
137 #define TRX_NEED_V    (1<<3)
138 #define TRX_READ_F    (1<<4)
139 #define TRX_NEED_F    (1<<5)
140 /* Useful for reading natoms from a trajectory without skipping */
141 #define TRX_DONT_SKIP (1<<6)
142
143 /* For trxframe.not_ok */
144 #define HEADER_NOT_OK (1<<0)
145 #define DATA_NOT_OK   (1<<1)
146 #define FRAME_NOT_OK  (HEADER_NOT_OK | DATA_NOT_OK)
147
148 extern bool read_first_frame(int *status,char *fn,t_trxframe *fr,int flags);
149   /* Read the first frame which is in accordance with flags, which are
150    * defined further up in this file. 
151    * Returns natoms when succeeded, 0 otherwise.
152    * Memory will be allocated for flagged entries.
153    * The flags are copied to fr for subsequent calls to read_next_frame.
154    * Returns TRUE when succeeded, FALSE otherwise.
155    */
156
157 extern bool read_next_frame(int status,t_trxframe *fr);
158   /* Reads the next frame which is in accordance with fr->flags.
159    * Returns TRUE when succeeded, FALSE otherwise.
160    */
161
162 extern int read_first_x(int *status,char *fn,
163                         real *t,rvec **x,matrix box);
164 /* These routines read first coordinates and box, and allocates 
165  * memory for the coordinates, for a trajectory file.
166  * The routine returns the number of atoms, or 0 when something is wrong.
167  * The integer in status should be passed to calls of read_next_x
168  */
169
170 extern bool read_next_x(int status,real *t,int natoms,rvec x[],matrix box);
171 /* Read coordinates and box from a trajectory file. Return TRUE when all well,
172  * or FALSE when end of file (or last frame requested by user).
173  * status is the integer set in read_first_x.
174  */
175
176 extern void close_trj(int status);
177 /* Close trj file as opened with read_first_x, read_frist_frame
178  * or open_trx. Identical to close_trx.
179  */
180
181 extern void rewind_trj(int status);
182 /* Rewind trj file as opened with read_first_x */
183
184 extern t_topology *read_top(char *fn);
185 /* Extract a topology data structure from a topology file */
186
187 extern void mk_single_top(t_topology *top);
188 /* Make the topology file single node ready */
189
190 extern bool bDoView(void);
191 /* Return TRUE when user requested viewing of the file */
192
193 /*****************************************************
194  *         Some command line parsing routines 
195  *****************************************************/
196
197 #define PCA_CAN_VIEW       (1<<5)
198 /* add option -w to view output files (must be implemented in program) */
199 #define PCA_CAN_BEGIN      (1<<6)
200 #define PCA_CAN_END        (1<<7)
201 #define PCA_CAN_DT         (1<<14)
202 #define PCA_CAN_TIME       (PCA_CAN_BEGIN | PCA_CAN_END | PCA_CAN_DT)
203 /* adds options -b and -e for begin and end time for reading trajectories */
204 #define PCA_TIME_UNIT      (1<<15)
205 /* set time unit for output */
206 #define PCA_KEEP_ARGS      (1<<8)
207 /* keep parsed args in argv (doesn't make sense without NOEXIT_ON_ARGS) */
208 #define PCA_SILENT         (1<<9)
209 /* don't print options by default */
210 #define PCA_CAN_SET_DEFFNM (1<<10)
211 /* does something for non-master mdrun nodes */
212 #define PCA_NOEXIT_ON_ARGS (1<<11)
213 /* no fatal_error when invalid options are encountered */
214 #define PCA_QUIET          (1<<12)
215 /* does something for non-master mdrun nodes */
216 #define PCA_SET_NPRI       (1<<13)
217 /* set weightless prioriy by default */
218
219 extern int iscan(int argc,char *argv[],int *i);
220 /* Scan an int from the argument at *i. If the argument length
221  * is > 2, the int is assumed to be in the remainder of the arg,
222  * eg: -p32, else the int is assumed to be in the next argument
223  * eg: -p 32. If neither is the case the routine exits with an error,
224  * otherwise it returns the value found. If the value is in the next
225  * argument *i is incremented. You typically would want to pass
226  * a loop variable to this routine.
227  */
228
229 extern double dscan(int argc,char *argv[],int *i);
230 /* Routine similar to the above, but working on doubles. */
231
232 extern char *sscan(int argc,char *argv[],int *i);
233 /* Routine similar to the above, but working on strings. The pointer
234  * returned is a pointer to the argv field.
235  */
236
237 extern void vscan(int argc,char *argv[],int *i,rvec *vec);
238 /* Routine similar to the above, but working on rvecs. */
239
240 extern int nenum(char *enumc[]);
241 /* returns ordinal number of selected enum from args 
242  * depends on enumc[0] pointing to one of the other elements
243  * array must be terminated by a NULL pointer 
244  */
245
246 #ifdef HAVE_MOTIF
247 extern void gmx_gui(int *argc,char *argv[],
248                     int nfile,t_filenm fnm[],int npargs,t_pargs pa[],
249                     int ndesc,char *desc[],int nbugs,char *bugs[]);
250 /* This function plops up a Motif dialog box in which the command-line options
251  * can be changed.
252  */
253 #endif
254
255 extern void parse_common_args(int *argc,char *argv[],unsigned long Flags,bool bNice,
256                               int nfile,t_filenm fnm[],int npargs,t_pargs *pa,
257                               int ndesc,char **desc,int nbugs,char **bugs);
258 /* Get arguments from the arg-list. The arguments extracted
259  * are removed from the list. If manual is NULL a default message is displayed
260  * when errors are encountered. The Flags argument, when non-0 enables
261  * some input checks. Using this routine also means that the arguments
262  * -b and -e will be used for begin and end time, whether this is 
263  * appropriate or not!
264  */
265
266 #ifdef CPLUSPLUS
267 }
268 #endif
269
270 #endif