Tagged files with gromacs 3.0 header and added some license info
[alexxy/gromacs.git] / include / gmxfio.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 3.0
11  * 
12  * Copyright (c) 1991-2001
13  * BIOSON Research Institute, Dept. of Biophysical Chemistry
14  * University of Groningen, The Netherlands
15  * 
16  * This program is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU General Public License
18  * as published by the Free Software Foundation; either version 2
19  * of the License, or (at your option) any later version.
20  * 
21  * If you want to redistribute modifications, please consider that
22  * scientific software is very special. Version control is crucial -
23  * bugs must be traceable. We will be happy to consider code for
24  * inclusion in the official distribution, but derived work must not
25  * be called official GROMACS. Details are found in the README & COPYING
26  * files - if they are missing, get the official version at www.gromacs.org.
27  * 
28  * To help us fund GROMACS development, we humbly ask that you cite
29  * the papers on the package - you can find them in the top README file.
30  * 
31  * Do check out http://www.gromacs.org , or mail us at gromacs@gromacs.org .
32  * 
33  * And Hey:
34  * GRoups of Organic Molecules in ACtion for Science
35  */
36
37 #ifndef _gmxfio_h
38 #define _gmxfio_h
39
40 static char *SRCID_gmxfio_h = "$Id$";
41 #ifdef HAVE_CONFIG_H
42 #include <config.h>
43 #endif
44
45 static char *SRCID_gmxfio_h = "$Id$";
46
47 #include "typedefs.h"
48 #include "xdrf.h"
49
50 /* Enumerated for different items in files */
51 enum { eitemHEADER, eitemIR, eitemBOX, 
52        eitemTOP, eitemX, eitemV, eitemF, eitemNR };
53        
54 /* Enumerated for data types in files */
55 enum { eioREAL, eioINT,   eioNUCHAR, eioUSHORT, 
56        eioRVEC, eioNRVEC, eioIVEC,  eioSTRING, eioNR };
57
58 /* Functions for reading and writing data */
59 typedef bool do_func(void *item,int nitem,int eio,
60                      char *desc,char *srcfile,int line);
61                      
62 /* Global variables defined in gmxfio.h */
63 extern do_func *do_read;
64 extern do_func *do_write;
65 extern char *itemstr[eitemNR];
66 extern char *comment_str[eitemNR];
67
68 /********************************************************
69  * Open and Close 
70  ********************************************************/
71
72 extern int fio_open(char *fn,char *mode);
73 /* Open a new file for reading or writing.
74  * The file type will be deduced from the file name.
75  * If fn is NULL, stdin / stdout will be used for Ascii I/O (TPA type)
76  * mode may be "r", "w", "a"
77  */
78  
79 extern void fio_close(int fp);
80 /* Close the file corresponding to fp (if not stdio)
81  * The routine will exit when an invalid fio is handled.
82  */
83
84 extern void fio_select(int fp);
85 /* This routine sets the global variables do_read and do_write
86  * to point to the correct routines for fp.
87  */
88
89 /********************************************************
90  * Change properties of the open file
91  ********************************************************/
92
93 extern void fio_setprecision(int fio,bool bDouble);
94 /* Select the floating point precision for reading and writing files */
95
96 extern char *fio_getname(int fio);
97 /* Return the filename corresponding to the fio index */
98
99 extern int fio_getftp(int fio);
100 /* Return the filetype corresponding to the fio index */
101
102 extern void fio_setftp_fio(int fio,int ftp);
103 /* And set it */
104
105 extern void fio_setdebug(int fio,bool bDebug);
106 /* Set the debug mode */
107
108 extern bool fio_getdebug(int fio);
109 /* Return  whether debug mode is on in fio  */
110
111 extern bool fio_getread(int fio);
112 /* Return  whether read mode is on in fio  */
113
114 /***************************************************
115  * FILE Operations
116  ***************************************************/
117
118 extern void fio_rewind(int fio);
119 /* Rewind the tpa file in fio */
120
121 extern void fio_flush(int fio);
122 /* Flush the fio */
123
124 extern long fio_ftell(int fio);
125 /* Return file position if possible */
126
127 extern void fio_seek(int fio,long fpos);
128 /* Set file position if possible, quit otherwise */
129
130 extern FILE *fio_getfp(int fio);
131 /* Return the file pointer itself */
132
133 extern XDR *fio_getxdr(int fio);
134 /* Return the file pointer itself */
135
136 extern void set_comment(char *comment);
137 /* Add this to the comment string for debugging */
138
139 extern void unset_comment(void);
140 /* Remove previously set comment */
141
142
143 /********************************************************
144  * Dirty C macros... Try this in FORTRAN 
145  * (Oh, and you can do structured programming in C too) 
146  *********************************************************/
147 #define do_real(item)         (bRead ?\
148   do_read ((void *)&(item),1,eioREAL,(#item),__FILE__,__LINE__) : \
149   do_write((void *)&(item),1,eioREAL,(#item),__FILE__,__LINE__))
150   
151 #define do_int(item)          (bRead ?\
152   do_read ((void *)&(item),1,eioINT,(#item),__FILE__,__LINE__) :\
153   do_write((void *)&(item),1,eioINT,(#item),__FILE__,__LINE__))
154   
155 #define do_nuchar(item,n)     (bRead ?\
156   do_read ((void *)(item),n,eioNUCHAR,(#item),__FILE__,__LINE__) :\
157   do_write((void *)(item),n,eioNUCHAR,(#item),__FILE__,__LINE__))
158   
159 #define do_ushort(item)          (bRead ?\
160   do_read ((void *)&(item),1,eioUSHORT,(#item),__FILE__,__LINE__) :\
161   do_write((void *)&(item),1,eioUSHORT,(#item),__FILE__,__LINE__))
162   
163 #define do_rvec(item)         (bRead ?\
164   do_read ((void *)(item),1,eioRVEC,(#item),__FILE__,__LINE__) :\
165   do_write((void *)(item),1,eioRVEC,(#item),__FILE__,__LINE__))
166   
167 #define do_ivec(item)         (bRead ?\
168   do_read ((void *)(item),1,eioIVEC,(#item),__FILE__,__LINE__) :\
169   do_write((void *)(item),1,eioIVEC,(#item),__FILE__,__LINE__))
170   
171 #define do_string(item)       (bRead ?\
172   do_read ((void *)(item),1,eioSTRING,(#item),__FILE__,__LINE__) :\
173   do_write((void *)(item),1,eioSTRING,(#item),__FILE__,__LINE__))
174   
175 #define ndo_real(item,n,bOK) {\
176   bOK=TRUE;\
177   for(i=0; (i<n); i++) {\
178     char buf[128];\
179     sprintf(buf,"%s[%d]",#item,i);\
180     bOK = bOK && (bRead ?\
181       do_read ((void *)&((item)[i]),1,eioREAL,buf,__FILE__,__LINE__):\
182       do_write((void *)&(item[i]),1,eioREAL,buf,__FILE__,__LINE__));\
183   }\
184 }
185      
186 #define ndo_int(item,n,bOK)  {\
187   bOK=TRUE;\
188   for(i=0; (i<n); i++) {\
189     char buf[128];\
190     sprintf(buf,"%s[%d]",#item,i);\
191     bOK = bOK && (bRead ?\
192       do_read ((void *)&(item[i]),1,eioINT,buf,__FILE__,__LINE__):\
193       do_write((void *)&(item[i]),1,eioINT,buf,__FILE__,__LINE__));\
194   }\
195 }
196   
197 #define ndo_rvec(item,n)      (bRead ?\
198   do_read ((void *)(item),n,eioNRVEC,(#item),__FILE__,__LINE__) :\
199   do_write((void *)(item),n,eioNRVEC,(#item),__FILE__,__LINE__))
200   
201 #define ndo_ivec(item,n,bOK) {\
202   bOK=TRUE;\
203   for(i=0; (i<n); i++) {\
204     char buf[128];\
205     sprintf(buf,"%s[%d]",#item,i);\
206     bOK = bOK && (bRead ?\
207       do_read ((void *)(item)[i],1,eioIVEC,buf,__FILE__,__LINE__):\
208       do_write((void *)(item)[i],1,eioIVEC,buf,__FILE__,__LINE__));\
209   }\
210 }
211   
212 #define ndo_string(item,n,bOK) {\
213   bOK=TRUE;\
214   for(i=0; (i<n); i++) {\
215     char buf[128];\
216     sprintf(buf,"%s[%d]",#item,i);\
217     bOK = bOK && (bRead ?\
218       do_read ((void *)(item)[i],1,eioSTRING,buf,__FILE__,__LINE__):\
219       do_write((void *)(item)[i],1,eioSTRING,buf,__FILE__,__LINE__));\
220   }\
221 }
222
223 #endif