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