Redefine the default boolean type to gmx_bool.
[alexxy/gromacs.git] / include / enxio.h
1 /*
2  * 
3  *                This source code is part of
4  * 
5  *                 G   R   O   M   A   C   S
6  * 
7  *          GROningen MAchine for Chemical Simulations
8  * 
9  *                        VERSION 3.2.0
10  * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12  * Copyright (c) 2001-2004, The GROMACS development team,
13  * check out http://www.gromacs.org for more information.
14
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  * 
20  * If you want to redistribute modifications, please consider that
21  * scientific software is very special. Version control is crucial -
22  * bugs must be traceable. We will be happy to consider code for
23  * inclusion in the official distribution, but derived work must not
24  * be called official GROMACS. Details are found in the README & COPYING
25  * files - if they are missing, get the official version at www.gromacs.org.
26  * 
27  * To help us fund GROMACS development, we humbly ask that you cite
28  * the papers on the package - you can find them in the top README file.
29  * 
30  * For more info, check our website at http://www.gromacs.org
31  * 
32  * And Hey:
33  * Gromacs Runs On Most of All Computer Systems
34  */
35
36 #ifndef _enxio_h
37 #define _enxio_h
38
39 #include "sysstuff.h"
40 #include "typedefs.h"
41 #include "pbc.h"
42 #include "gmxfio.h"
43
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47
48   /**************************************************************
49    * These are the base datatypes + functions for reading and 
50    * writing energy files (.edr). They are either called directly 
51    * (as in the processing tools), or indirectly through mdebin.c 
52    * during mdrun.
53    *
54    * The routines in the corresponding c-file enxio.c
55    * are based on the lower level routines in gmxfio.c.
56    * The file pointer returned from open_enx
57    * can also be used with the routines in gmxfio.h
58    *
59    **************************************************************/
60   
61   typedef struct {
62     char *name;
63     char *unit;
64   } gmx_enxnm_t;
65   
66   /* 
67    * Index for the IDs of additional blocks in the energy file.
68    * Blocks can be added without sacrificing backward and forward
69    * compatibility of the energy files.
70    *
71    * For backward compatibility, the order of these should not be changed.
72    */
73   enum {
74     enxOR,     /* Time and ensemble averaged data for orientation restraints */
75     enxORI,    /* Instantaneous data for orientation restraints              */
76     enxORT,    /* Order tensor(s) for orientation restraints                 */
77     enxDISRE,  /* Distance restraint blocks                                  */
78
79     enxDHCOLL, /* Data about the free energy blocks in this frame.           */
80     enxDHHIST, /* BAR histogram                                              */
81     enxDH,     /* BAR raw delta H data                                       */
82
83     enxNR      /* Total number of extra blocks in the current code,
84                 * note that the enxio code can read files written by
85                 * future code which contain more blocks.
86                 */
87   };
88
89   /* names for the above enum */
90   extern const char *enx_block_id_name[];
91
92
93   /* the subblocks that are contained in energy file blocks. Each of these
94      has a number of values of a single data type in a .edr file. */
95   typedef struct
96   {
97       int nr;               /* number of items in subblock */
98       xdr_datatype type;    /* the block type */
99
100       /* the values: pointers for each type */
101       float*             fval;
102       double*            dval;
103       int*               ival;
104       gmx_large_int_t*   lval;
105       unsigned char*     cval;
106       char**             sval;
107
108       /* the allocated sizes, defined separately. 
109          (nonzero sizes can be free()d later): */
110       int fval_alloc;
111       int dval_alloc;
112       int ival_alloc;
113       int lval_alloc;
114       int cval_alloc;
115       int sval_alloc; 
116   } t_enxsubblock;
117
118
119   /* the energy file blocks. Each block contains a number of sub-blocks
120      of a single type that contain the actual data. */
121   typedef struct t_enxblock{
122       int id;               /* block id, from the enx enums above */
123       int nsub;             /* number of subblocks */
124       t_enxsubblock *sub;   /* the subblocks */
125       int nsub_alloc;       /* number of allocated subblocks */
126   } t_enxblock;
127  
128
129   /* The frames that are read/written */
130   typedef struct {
131     double   t;             /* Timestamp of this frame                       */
132     gmx_large_int_t step;   /* MD step                                       */
133     gmx_large_int_t nsteps; /* The number of steps between frames            */
134     double   dt;            /* The MD time step                              */
135     int      nsum;          /* The number of terms for the sums in ener      */
136     int      nre;           /* Number of energies                            */
137     int      e_size;        /* Size (in bytes) of energies                   */
138     int      e_alloc;       /* Allocated size (in elements) of ener          */
139     t_energy *ener;         /* The energies                                  */
140     int      nblock;        /* Number of following energy blocks             */
141     t_enxblock *block;      /* The blocks                                    */
142     int      nblock_alloc;  /* The number of blocks allocated                */
143   } t_enxframe;
144
145   /* file handle */
146   typedef struct ener_file *ener_file_t;
147
148   /* 
149    * An energy file is read like this:
150    *
151    * ener_file_t fp;
152    * t_enxframe *fr;
153    *
154    * fp = open_enx(...);
155    * do_enxnms(fp,...);
156    * snew(fr,1);
157    * while (do_enx(fp,fr)) {
158    * ...
159    * }
160    * free_enxframe(fr);
161    * sfree(fr);
162    */
163   /* New energy reading and writing interface */
164
165
166   /* initialize a pre-allocated frame */
167   void init_enxframe(t_enxframe *ef);
168   /* delete a frame's memory (except the ef itself) */
169   void free_enxframe(t_enxframe *ef);
170
171
172   ener_file_t open_enx(const char *fn,const char *mode);
173
174   t_fileio *enx_file_pointer(const ener_file_t ef);
175
176   void close_enx(ener_file_t ef);
177   
178   void do_enxnms(ener_file_t ef,int *nre,gmx_enxnm_t **enms);
179   
180   void free_enxnms(int n,gmx_enxnm_t *nms);
181   /* Frees nms and all strings in it */
182
183   gmx_bool do_enx(ener_file_t ef,t_enxframe *fr);
184   /* Reads enx_frames, memory in fr is (re)allocated if necessary */
185
186   void get_enx_state(const char *fn, real t,
187                             gmx_groups_t *groups, t_inputrec *ir,
188                             t_state *state);
189   /*
190    * Reads state variables from enx file fn at time t.
191    * atoms and ir are required for determining which things must be read.
192    * Currently pcoupl and tcoupl state are read from enx.
193    */
194
195
196   /* block funtions */
197
198   /* allocate n blocks to a frame (if neccesary). Don't touch existing blocks */
199   void add_blocks_enxframe(t_enxframe *ef, int n);
200
201   /* find a block by id number; if prev!=NULL, it searches from 
202      that block's next block. 
203      Returns NULL if no block is found with the given id. */
204   t_enxblock *find_block_id_enxframe(t_enxframe *ef, int id, t_enxblock *prev);
205
206
207    /* allocate n subblocks to a block (if neccesary). Don't touch existing 
208       subbblocks. */
209   void add_subblocks_enxblock(t_enxblock *eb, int n);
210
211
212   
213 #ifdef __cplusplus
214 }
215 #endif
216
217 #endif  /* _enerio_h */