Fixed segv in make_edi when no reference structure given
[gromacs/adressmacs.git] / include / statutil.h
blob52a79c222a71dfa2690123b3dba6b1d34023594c
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 _statutil_h
38 #define _statutil_h
40 #ifdef HAVE_CONFIG_H
41 #include <config.h>
42 #endif
44 #ifdef CPLUSPLUS
45 extern "C" {
46 #endif
48 #include <stdio.h>
49 #include "typedefs.h"
50 #include "filenm.h"
51 #include "readinp.h"
52 #include "wman.h"
54 /* The code below is to facilitate controlled begin and end of
55 trajectory reading. Corresponding routines in
56 src/gmxlib/tcontrol.c
58 enum { TBEGIN, TEND, TDELTA, TNR };
60 extern bool bTimeSet(int tcontrol);
62 extern real rTimeValue(int tcontrol);
64 extern void setTimeValue(int tcontrol,real value);
66 /* End trajectory time control */
68 typedef int t_first_x(int *status,char *fn,real *t,rvec **x,matrix box);
70 typedef bool t_next_x(int status,real *t,int natoms,rvec x[],matrix box);
72 /* I/O function types */
74 extern char *Program(void);
75 /* Return the name of the program */
76 extern char *ShortProgram(void);
77 /* Id. without leading directory */
78 extern char *command_line(void);
79 /* Return the command line for this program */
80 extern void set_program_name(char *argvzero);
81 /* set the program name to the provided string, but note
82 * that it must be a real file - we determine the library
83 * directory from its location!
86 /************************************************
87 * Trajectory functions
88 ************************************************/
90 extern int prec2ndec(real prec);
91 /* Convert precision in 1/(nm) to number of decimal places */
93 extern void clear_trxframe(t_trxframe *fr,bool bFirst);
94 /* Set all content booleans to FALSE.
95 * When bFirst = TRUE, set natoms=-1, all pointers to NULL
96 * and all data to zero.
99 extern void set_trxframe_ePBC(t_trxframe *fr,int ePBC);
100 /* Set the type of periodic boundary conditions, ePBC=-1 is not set */
102 extern int nframes_read(void);
103 /* Returns the number of frames read from the trajectory */
105 int write_trxframe_indexed(int status,t_trxframe *fr,int nind,atom_id *ind);
106 /* Write an indexed frame to a TRX file, see write_trxframe */
108 int write_trxframe(int status,t_trxframe *fr);
109 /* Write a frame to a TRX file.
110 * Only entries for which the boolean is TRUE will be written,
111 * except for step, time, lambda and/or box, which may not be
112 * omitted for certain trajectory formats.
113 * The precision for .xtc and .gro is fr->prec, when fr->bPrec=FALSE,
114 * the precision is set to 1000.
117 int write_trx(int status,int nind,atom_id *ind,t_atoms *atoms,
118 int step,real time,matrix box,rvec x[],rvec *v);
119 /* Write an indexed frame to a TRX file.
120 * v can be NULL.
121 * atoms can be NULL for file types which don't need atom names.
124 void close_trx(int status);
125 /* Close trj file as opened with read_first_x, read_frist_frame
126 * or open_trx. Identical to close_trj.
129 int open_trx(char *outfile,char *filemode);
130 /* Open a TRX file and return the file number */
132 extern bool bRmod_fd(double a, double b, double c,bool bDouble);
133 /* Returns TRUE when (a - b) MOD c = 0, using a margin which is slightly
134 * larger than the float/double precision.
137 #ifdef GMX_DOUBLE
138 #define bRmod(a,b,c) bRmod_fd(a,b,c,TRUE)
139 #else
140 #define bRmod(a,b,c) bRmod_fd(a,b,c,FALSE)
141 #endif
143 extern int check_times2(real t,real t0,real tp,real tpp,bool bDouble);
144 /* This routine checkes if the read-in time is correct or not;
145 * returns -1 if t<tbegin or t MOD dt = t0,
146 * 0 if tbegin <= t <=tend+margin,
147 * 1 if t>tend
148 * where margin is 0.1*min(t-tp,tp-tpp), if this positive, 0 otherwise.
149 * tp and tpp should be the time of the previous frame and the one before.
150 * The mod is done with single or double precision accuracy depending
151 * on the value of bDouble.
154 extern int check_times(real t);
155 /* This routine checkes if the read-in time is correct or not;
156 * returns -1 if t<tbegin,
157 * 0 if tbegin <= t <=tend,
158 * 1 if t>tend
161 extern char *time_unit(void);
162 /* return time unit (e.g. ps or ns) */
164 extern char *time_label(void);
165 /* return time unit label (e.g. "Time (ps)") */
167 extern char *xvgr_tlabel(void);
168 /* retrun x-axis time label for xmgr */
170 extern real time_factor(void);
171 /* return time conversion factor from ps (i.e. 1e-3 for ps->ns) */
173 extern real time_invfactor(void);
174 /* return inverse time conversion factor from ps (i.e. 1e3 for ps->ns) */
176 extern real convert_time(real time);
177 /* return converted time */
179 extern void convert_times(int n, real *time);
180 /* convert array of times */
182 /* For trxframe.flags, used in trxframe read routines.
183 * When a READ flag is set, the field will be read when present,
184 * but a frame might be returned which does not contain the field.
185 * When a NEED flag is set, frames not containing the field will be skipped.
187 #define TRX_READ_X (1<<0)
188 #define TRX_NEED_X (1<<1)
189 #define TRX_READ_V (1<<2)
190 #define TRX_NEED_V (1<<3)
191 #define TRX_READ_F (1<<4)
192 #define TRX_NEED_F (1<<5)
193 /* Useful for reading natoms from a trajectory without skipping */
194 #define TRX_DONT_SKIP (1<<6)
196 /* For trxframe.not_ok */
197 #define HEADER_NOT_OK (1<<0)
198 #define DATA_NOT_OK (1<<1)
199 #define FRAME_NOT_OK (HEADER_NOT_OK | DATA_NOT_OK)
201 extern int read_first_frame(int *status,char *fn,t_trxframe *fr,int flags);
202 /* Read the first frame which is in accordance with flags, which are
203 * defined further up in this file.
204 * Returns natoms when succeeded, 0 otherwise.
205 * Memory will be allocated for flagged entries.
206 * The flags are copied to fr for subsequent calls to read_next_frame.
207 * Returns TRUE when succeeded, FALSE otherwise.
210 extern bool read_next_frame(int status,t_trxframe *fr);
211 /* Reads the next frame which is in accordance with fr->flags.
212 * Returns TRUE when succeeded, FALSE otherwise.
215 extern int read_first_x(int *status,char *fn,
216 real *t,rvec **x,matrix box);
217 /* These routines read first coordinates and box, and allocates
218 * memory for the coordinates, for a trajectory file.
219 * The routine returns the number of atoms, or 0 when something is wrong.
220 * The integer in status should be passed to calls of read_next_x
223 extern bool read_next_x(int status,real *t,int natoms,rvec x[],matrix box);
224 /* Read coordinates and box from a trajectory file. Return TRUE when all well,
225 * or FALSE when end of file (or last frame requested by user).
226 * status is the integer set in read_first_x.
229 extern void close_trj(int status);
230 /* Close trj file as opened with read_first_x, read_frist_frame
231 * or open_trx. Identical to close_trx.
234 extern void rewind_trj(int status);
235 /* Rewind trj file as opened with read_first_x */
237 extern t_topology *read_top(char *fn,int *ePBC);
238 /* Extract a topology data structure from a topology file.
239 * If ePBC!=NULL *ePBC gives the pbc type.
242 extern bool bDoView(void);
243 /* Return TRUE when user requested viewing of the file */
245 extern bool bPrintXvgrCodes(void);
246 /* Return TRUE when user wants printing of legends etc. in the file. */
248 /*****************************************************
249 * Some command line parsing routines
250 *****************************************************/
252 #define PCA_CAN_VIEW (1<<5)
253 /* add option -w to view output files (must be implemented in program) */
254 #define PCA_CAN_BEGIN (1<<6)
255 #define PCA_CAN_END (1<<7)
256 #define PCA_CAN_DT (1<<14)
257 #define PCA_CAN_TIME (PCA_CAN_BEGIN | PCA_CAN_END | PCA_CAN_DT)
258 /* adds options -b and -e for begin and end time for reading trajectories */
259 #define PCA_TIME_UNIT (1<<15)
260 /* set time unit for output */
261 #define PCA_KEEP_ARGS (1<<8)
262 /* keep parsed args in argv (doesn't make sense without NOEXIT_ON_ARGS) */
263 #define PCA_SILENT (1<<9)
264 /* don't print options by default */
265 #define PCA_CAN_SET_DEFFNM (1<<10)
266 /* does something for non-master mdrun nodes */
267 #define PCA_NOEXIT_ON_ARGS (1<<11)
268 /* no fatal_error when invalid options are encountered */
269 #define PCA_QUIET (1<<12)
270 /* does something for non-master mdrun nodes */
271 #define PCA_BE_NICE (1<<13)
272 /* Default to low priority, unless configured with --disable-nice */
274 extern int iscan(int argc,char *argv[],int *i);
275 /* Scan an int from the argument at *i. If the argument length
276 * is > 2, the int is assumed to be in the remainder of the arg,
277 * eg: -p32, else the int is assumed to be in the next argument
278 * eg: -p 32. If neither is the case the routine exits with an error,
279 * otherwise it returns the value found. If the value is in the next
280 * argument *i is incremented. You typically would want to pass
281 * a loop variable to this routine.
284 extern double dscan(int argc,char *argv[],int *i);
285 /* Routine similar to the above, but working on doubles. */
287 extern char *sscan(int argc,char *argv[],int *i);
288 /* Routine similar to the above, but working on strings. The pointer
289 * returned is a pointer to the argv field.
292 extern void vscan(int argc,char *argv[],int *i,rvec *vec);
293 /* Routine similar to the above, but working on rvecs. */
295 extern int nenum(char *enumc[]);
296 /* returns ordinal number of selected enum from args
297 * depends on enumc[0] pointing to one of the other elements
298 * array must be terminated by a NULL pointer
301 #ifdef HAVE_MOTIF
302 extern void gmx_gui(int *argc,char *argv[],
303 int nfile,t_filenm fnm[],int npargs,t_pargs pa[],
304 int ndesc,char *desc[],int nbugs,char *bugs[]);
305 /* This function plops up a Motif dialog box in which the command-line options
306 * can be changed.
308 #endif
310 extern void parse_common_args(int *argc,char *argv[],unsigned long Flags,
311 int nfile,t_filenm fnm[],int npargs,t_pargs *pa,
312 int ndesc,char **desc,int nbugs,char **bugs);
313 /* Get arguments from the arg-list. The arguments extracted
314 * are removed from the list. If manual is NULL a default message is displayed
315 * when errors are encountered. The Flags argument, when non-0 enables
316 * some input checks. Using this routine also means that the arguments
317 * -b and -e will be used for begin and end time, whether this is
318 * appropriate or not!
321 #ifdef CPLUSPLUS
323 #endif
325 #endif