fe6f7df8b0abee6694b2c0abf2f3160e2358671c
[alexxy/gromacs.git] / include / trnio.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 _trnio_h
37 #define _trnio_h
38
39 /**************************************************************
40  *
41  * These routines handle trj (trajectory) I/O, they read and
42  * write trj/trr files. The routines should be able to read single
43  * and double precision files without the user noting it.
44  * The files are backward compatible, therefore the header holds
45  * some unused variables.
46  *
47  * The routines in the corresponding c-file trnio.c
48  * are based on the lower level routines in gmxfio.c
49  * The integer file pointer returned from open_trn
50  * can also be used with the routines in gmxfio.h
51  *
52  **************************************************************/
53 #include "visibility.h" 
54 #include "typedefs.h"
55 #include "gmxfio.h"
56
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60
61 typedef struct          /* This struct describes the order and the      */
62   /* sizes of the structs in a trjfile, sizes are given in bytes.       */
63 {
64   gmx_bool  bDouble;        /* Double precision?                            */
65   int   ir_size;        /* Backward compatibility                       */
66   int   e_size;         /* Backward compatibility                       */
67   int   box_size;       /* Non zero if a box is present                 */
68   int   vir_size;       /* Backward compatibility                       */
69   int   pres_size;      /* Backward compatibility                       */
70   int   top_size;       /* Backward compatibility                       */
71   int   sym_size;       /* Backward compatibility                       */
72   int   x_size;         /* Non zero if coordinates are present          */
73   int   v_size;         /* Non zero if velocities are present           */
74   int   f_size;         /* Non zero if forces are present               */
75
76   int   natoms;         /* The total number of atoms                    */
77   int   step;           /* Current step number                          */
78   int   nre;            /* Backward compatibility                       */
79   real  t;              /* Current time                                 */
80   real  lambda;         /* Current value of lambda                      */
81   int   fep_state;  /* Current value of alchemical state */
82 } t_trnheader;
83
84 GMX_LIBGMX_EXPORT
85 t_fileio *open_trn(const char *fn,const char *mode);
86 /* Open a trj / trr file */
87
88 GMX_LIBGMX_EXPORT
89 void close_trn(t_fileio *fio);
90 /* Close it */
91
92 GMX_LIBGMX_EXPORT
93 gmx_bool fread_trnheader(t_fileio *fio,t_trnheader *trn,gmx_bool *bOK);
94 /* Read the header of a trn file. Return FALSE if there is no frame.
95  * bOK will be FALSE when the header is incomplete.
96  */
97
98 GMX_LIBGMX_EXPORT
99 void read_trnheader(const char *fn,t_trnheader *header);
100 /* Read the header of a trn file from fn, and close the file afterwards. 
101  */
102
103 void pr_trnheader(FILE *fp,int indent,char *title,t_trnheader *sh);
104 /* Print the header of a trn file to fp */
105
106 gmx_bool is_trn(FILE *fp);
107 /* Return true when the file is a trn file. File will be rewound
108  * afterwards.
109  */
110
111 GMX_LIBGMX_EXPORT
112 void fwrite_trn(t_fileio *fio,int step,real t,real lambda,
113                        rvec *box,int natoms,rvec *x,rvec *v,rvec *f);
114 /* Write a trn frame to file fp, box, x, v, f may be NULL */
115
116 GMX_LIBGMX_EXPORT
117 gmx_bool fread_htrn(t_fileio *fio,t_trnheader *sh,
118                        rvec *box,rvec *x,rvec *v,rvec *f);
119 /* Extern read a frame except the header (that should be pre-read,
120  * using routine read_trnheader, see above) from a trn file.
121  * Return FALSE on error
122  */
123  
124 gmx_bool fread_trn(t_fileio *fio,int *step,real *t,real *lambda,
125                       rvec *box,int *natoms,rvec *x,rvec *v,rvec *f);
126 /* Read a trn frame, including the header from fp. box, x, v, f may
127  * be NULL, in which case the data will be skipped over.
128  * return FALSE on error
129  */
130  
131 GMX_LIBGMX_EXPORT
132 void write_trn(const char *fn,int step,real t,real lambda,
133                       rvec *box,int natoms,rvec *x,rvec *v,rvec *f);
134 /* Write a single trn frame to file fn, which is closed afterwards */
135
136 GMX_LIBGMX_EXPORT
137 void read_trn(const char *fn,int *step,real *t,real *lambda,
138                      rvec *box,int *natoms,rvec *x,rvec *v,rvec *f);
139 /* Read a single trn frame from file fn, which is closed afterwards 
140  */
141
142 #ifdef __cplusplus
143 }
144 #endif
145
146
147 #endif