cd51ce39a27d698ce0ba4e4de468dcbd696c6079
[alexxy/gromacs.git] / include / trnio.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5  * Copyright (c) 2001-2004, The GROMACS development team,
6  * check out http://www.gromacs.org for more information.
7  * Copyright (c) 2012, by the GROMACS development team, led by
8  * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9  * others, as listed in the AUTHORS file in the top-level source
10  * directory and at http://www.gromacs.org.
11  *
12  * GROMACS is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public License
14  * as published by the Free Software Foundation; either version 2.1
15  * of the License, or (at your option) any later version.
16  *
17  * GROMACS is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with GROMACS; if not, see
24  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
26  *
27  * If you want to redistribute modifications to GROMACS, please
28  * consider that scientific software is very special. Version
29  * control is crucial - bugs must be traceable. We will be happy to
30  * consider code for inclusion in the official distribution, but
31  * derived work must not be called official GROMACS. Details are found
32  * in the README & COPYING files - if they are missing, get the
33  * official version at http://www.gromacs.org.
34  *
35  * To help us fund GROMACS development, we humbly ask that you cite
36  * the research papers on the package. Check out http://www.gromacs.org.
37  */
38
39 #ifndef _trnio_h
40 #define _trnio_h
41
42 /**************************************************************
43  *
44  * These routines handle trj (trajectory) I/O, they read and
45  * write trj/trr files. The routines should be able to read single
46  * and double precision files without the user noting it.
47  * The files are backward compatible, therefore the header holds
48  * some unused variables.
49  *
50  * The routines in the corresponding c-file trnio.c
51  * are based on the lower level routines in gmxfio.c
52  * The integer file pointer returned from open_trn
53  * can also be used with the routines in gmxfio.h
54  *
55  **************************************************************/
56 #include "visibility.h" 
57 #include "typedefs.h"
58 #include "gmxfio.h"
59
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63
64 typedef struct          /* This struct describes the order and the      */
65   /* sizes of the structs in a trjfile, sizes are given in bytes.       */
66 {
67   gmx_bool  bDouble;        /* Double precision?                            */
68   int   ir_size;        /* Backward compatibility                       */
69   int   e_size;         /* Backward compatibility                       */
70   int   box_size;       /* Non zero if a box is present                 */
71   int   vir_size;       /* Backward compatibility                       */
72   int   pres_size;      /* Backward compatibility                       */
73   int   top_size;       /* Backward compatibility                       */
74   int   sym_size;       /* Backward compatibility                       */
75   int   x_size;         /* Non zero if coordinates are present          */
76   int   v_size;         /* Non zero if velocities are present           */
77   int   f_size;         /* Non zero if forces are present               */
78
79   int   natoms;         /* The total number of atoms                    */
80   int   step;           /* Current step number                          */
81   int   nre;            /* Backward compatibility                       */
82   real  t;              /* Current time                                 */
83   real  lambda;         /* Current value of lambda                      */
84   int   fep_state;  /* Current value of alchemical state */
85 } t_trnheader;
86
87 GMX_LIBGMX_EXPORT
88 t_fileio *open_trn(const char *fn,const char *mode);
89 /* Open a trj / trr file */
90
91 GMX_LIBGMX_EXPORT
92 void close_trn(t_fileio *fio);
93 /* Close it */
94
95 GMX_LIBGMX_EXPORT
96 gmx_bool fread_trnheader(t_fileio *fio,t_trnheader *trn,gmx_bool *bOK);
97 /* Read the header of a trn file. Return FALSE if there is no frame.
98  * bOK will be FALSE when the header is incomplete.
99  */
100
101 GMX_LIBGMX_EXPORT
102 void read_trnheader(const char *fn,t_trnheader *header);
103 /* Read the header of a trn file from fn, and close the file afterwards. 
104  */
105
106 void pr_trnheader(FILE *fp,int indent,char *title,t_trnheader *sh);
107 /* Print the header of a trn file to fp */
108
109 gmx_bool is_trn(FILE *fp);
110 /* Return true when the file is a trn file. File will be rewound
111  * afterwards.
112  */
113
114 GMX_LIBGMX_EXPORT
115 void fwrite_trn(t_fileio *fio,int step,real t,real lambda,
116                        rvec *box,int natoms,rvec *x,rvec *v,rvec *f);
117 /* Write a trn frame to file fp, box, x, v, f may be NULL */
118
119 GMX_LIBGMX_EXPORT
120 gmx_bool fread_htrn(t_fileio *fio,t_trnheader *sh,
121                        rvec *box,rvec *x,rvec *v,rvec *f);
122 /* Extern read a frame except the header (that should be pre-read,
123  * using routine read_trnheader, see above) from a trn file.
124  * Return FALSE on error
125  */
126  
127 gmx_bool fread_trn(t_fileio *fio,int *step,real *t,real *lambda,
128                       rvec *box,int *natoms,rvec *x,rvec *v,rvec *f);
129 /* Read a trn frame, including the header from fp. box, x, v, f may
130  * be NULL, in which case the data will be skipped over.
131  * return FALSE on error
132  */
133  
134 GMX_LIBGMX_EXPORT
135 void write_trn(const char *fn,int step,real t,real lambda,
136                       rvec *box,int natoms,rvec *x,rvec *v,rvec *f);
137 /* Write a single trn frame to file fn, which is closed afterwards */
138
139 GMX_LIBGMX_EXPORT
140 void read_trn(const char *fn,int *step,real *t,real *lambda,
141                      rvec *box,int *natoms,rvec *x,rvec *v,rvec *f);
142 /* Read a single trn frame from file fn, which is closed afterwards 
143  */
144
145 #ifdef __cplusplus
146 }
147 #endif
148
149
150 #endif