7939ceb515c6ad7defe9be5906c854c1694aea93
[alexxy/gromacs.git] / include / trnio.h
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 2.0
11  * 
12  * Copyright (c) 1991-1999
13  * BIOSON Research Institute, Dept. of Biophysical Chemistry
14  * University of Groningen, The Netherlands
15  * 
16  * Please refer to:
17  * GROMACS: A message-passing parallel molecular dynamics implementation
18  * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
19  * Comp. Phys. Comm. 91, 43-56 (1995)
20  * 
21  * Also check out our WWW page:
22  * http://md.chem.rug.nl/~gmx
23  * or e-mail to:
24  * gromacs@chem.rug.nl
25  * 
26  * And Hey:
27  * Green Red Orange Magenta Azure Cyan Skyblue
28  */
29
30 #ifndef _trnio_h
31 #define _trnio_h
32
33 static char *SRCID_trnio_h = "$Id$";
34
35 #ifdef HAVE_CONFIG_H
36 #include <config.h>
37 #endif
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         
54 #include "typedefs.h"
55
56 typedef struct          /* This struct describes the order and the      */
57   /* sizes of the structs in a trjfile, sizes are given in bytes.       */
58 {
59   int   ir_size;        /* Backward compatibility                       */
60   int   e_size;         /* Backward compatibility                       */
61   int   box_size;       /* Non zero if a box is present                 */
62   int   vir_size;       /* Backward compatibility                       */
63   int   pres_size;      /* Backward compatibility                       */
64   int   top_size;       /* Backward compatibility                       */
65   int   sym_size;       /* Backward compatibility                       */
66   int   x_size;         /* Non zero if coordinates are present          */
67   int   v_size;         /* Non zero if velocities are present           */
68   int   f_size;         /* Non zero if forces are present               */
69
70   int   natoms;         /* The total number of atoms                    */
71   int   step;           /* Current step number                          */
72   int   nre;            /* Backward compatibility                       */
73   real  t;              /* Current time                                 */
74   real  lambda;         /* Current value of lambda                      */
75 } t_trnheader;
76
77 extern int open_trn(char *fn,char *mode);
78 /* Open a trj / trr file */
79
80 extern void close_trn(int fp);
81 /* Close it */
82
83 extern bool fread_trnheader(int fp,t_trnheader *trn,bool *bOK);
84 /* Read the header of a trn file. Return FALSE if there is no frame.
85  * bOK will be FALSE when the header is incomplete.
86  */
87
88 extern void read_trnheader(char *fn,t_trnheader *header);
89 /* Read the header of a trn file from fn, and close the file afterwards. 
90  */
91
92 extern void pr_trnheader(FILE *fp,int indent,char *title,t_trnheader *sh);
93 /* Print the header of a trn file to fp */
94
95 extern bool is_trn(FILE *fp);
96 /* Return true when the file is a trn file. File will be rewound
97  * afterwards.
98  */
99
100 extern void fwrite_trn(int fp,int step,real t,real lambda,
101                        rvec *box,int natoms,rvec *x,rvec *v,rvec *f);
102 /* Write a trn frame to file fp, box, x, v, f may be NULL */
103
104 extern bool fread_htrn(int fp,t_trnheader *sh,
105                        rvec *box,rvec *x,rvec *v,rvec *f);
106 /* Extern read a frame except the header (that should be pre-read,
107  * using routine read_trnheader, see above) from a trn file.
108  * Return FALSE on error
109  */
110  
111 extern bool fread_trn(int fp,int *step,real *t,real *lambda,
112                       rvec *box,int *natoms,rvec *x,rvec *v,rvec *f);
113 /* Read a trn frame, including the header from fp. box, x, v, f may
114  * be NULL, in which case the data will be skipped over.
115  * return FALSE on error
116  */
117  
118 extern void write_trn(char *fn,int step,real t,real lambda,
119                       rvec *box,int natoms,rvec *x,rvec *v,rvec *f);
120 /* Write a single trn frame to file fn, which is closed afterwards */
121
122 extern void read_trn(char *fn,int *step,real *t,real *lambda,
123                      rvec *box,int *natoms,rvec *x,rvec *v,rvec *);
124 /* Read a single trn frame from file fn, which is closed afterwards 
125  */
126
127 #endif