4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
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)
21 * Also check out our WWW page:
22 * http://md.chem.rug.nl/~gmx
27 * Good ROcking Metal Altar for Chronical Sinners
37 static char *SRCID_gmxfio_h = "$Id$";
42 /* Enumerated for different items in files */
43 enum { eitemHEADER, eitemIR, eitemBOX,
44 eitemTOP, eitemX, eitemV, eitemF, eitemNR };
46 /* Enumerated for data types in files */
47 enum { eioREAL, eioINT, eioNUCHAR, eioUSHORT,
48 eioRVEC, eioNRVEC, eioIVEC, eioSTRING, eioNR };
50 /* Functions for reading and writing data */
51 typedef bool do_func(void *item,int nitem,int eio,
52 char *desc,char *srcfile,int line);
54 /* Global variables defined in gmxfio.h */
55 extern do_func *do_read;
56 extern do_func *do_write;
57 extern char *itemstr[eitemNR];
58 extern char *comment_str[eitemNR];
60 /********************************************************
62 ********************************************************/
64 extern int fio_open(char *fn,char *mode);
65 /* Open a new file for reading or writing.
66 * The file type will be deduced from the file name.
67 * If fn is NULL, stdin / stdout will be used for Ascii I/O (TPA type)
68 * mode may be "r", "w", "a"
71 extern void fio_close(int fp);
72 /* Close the file corresponding to fp (if not stdio)
73 * The routine will exit when an invalid fio is handled.
76 extern void fio_select(int fp);
77 /* This routine sets the global variables do_read and do_write
78 * to point to the correct routines for fp.
81 /********************************************************
82 * Change properties of the open file
83 ********************************************************/
85 extern void fio_setprecision(int fio,bool bDouble);
86 /* Select the floating point precision for reading and writing files */
88 extern char *fio_getname(int fio);
89 /* Return the filename corresponding to the fio index */
91 extern int fio_getftp(int fio);
92 /* Return the filetype corresponding to the fio index */
94 extern void fio_setftp_fio(int fio,int ftp);
97 extern void fio_setdebug(int fio,bool bDebug);
98 /* Set the debug mode */
100 extern bool fio_getdebug(int fio);
101 /* Return whether debug mode is on in fio */
103 extern bool fio_getread(int fio);
104 /* Return whether read mode is on in fio */
106 /***************************************************
108 ***************************************************/
110 extern void fio_rewind(int fio);
111 /* Rewind the tpa file in fio */
113 extern void fio_flush(int fio);
116 extern long fio_ftell(int fio);
117 /* Return file position if possible */
119 extern void fio_seek(int fio,long fpos);
120 /* Set file position if possible, quit otherwise */
122 extern FILE *fio_getfp(int fio);
123 /* Return the file pointer itself */
125 extern XDR *fio_getxdr(int fio);
126 /* Return the file pointer itself */
128 extern void set_comment(char *comment);
129 /* Add this to the comment string for debugging */
131 extern void unset_comment(void);
132 /* Remove previously set comment */
135 /********************************************************
136 * Dirty C macros... Try this in FORTRAN
137 * (Oh, and you can do structured programming in C too)
138 *********************************************************/
139 #define do_real(item) (bRead ?\
140 do_read ((void *)&(item),1,eioREAL,(#item),__FILE__,__LINE__) : \
141 do_write((void *)&(item),1,eioREAL,(#item),__FILE__,__LINE__))
143 #define do_int(item) (bRead ?\
144 do_read ((void *)&(item),1,eioINT,(#item),__FILE__,__LINE__) :\
145 do_write((void *)&(item),1,eioINT,(#item),__FILE__,__LINE__))
147 #define do_nuchar(item,n) (bRead ?\
148 do_read ((void *)(item),n,eioNUCHAR,(#item),__FILE__,__LINE__) :\
149 do_write((void *)(item),n,eioNUCHAR,(#item),__FILE__,__LINE__))
151 #define do_ushort(item) (bRead ?\
152 do_read ((void *)&(item),1,eioUSHORT,(#item),__FILE__,__LINE__) :\
153 do_write((void *)&(item),1,eioUSHORT,(#item),__FILE__,__LINE__))
155 #define do_rvec(item) (bRead ?\
156 do_read ((void *)(item),1,eioRVEC,(#item),__FILE__,__LINE__) :\
157 do_write((void *)(item),1,eioRVEC,(#item),__FILE__,__LINE__))
159 #define do_ivec(item) (bRead ?\
160 do_read ((void *)(item),1,eioIVEC,(#item),__FILE__,__LINE__) :\
161 do_write((void *)(item),1,eioIVEC,(#item),__FILE__,__LINE__))
163 #define do_string(item) (bRead ?\
164 do_read ((void *)(item),1,eioSTRING,(#item),__FILE__,__LINE__) :\
165 do_write((void *)(item),1,eioSTRING,(#item),__FILE__,__LINE__))
167 #define ndo_real(item,n,bOK) {\
169 for(i=0; (i<n); i++) {\
171 sprintf(buf,"%s[%d]",#item,i);\
172 bOK = bOK && (bRead ?\
173 do_read ((void *)&((item)[i]),1,eioREAL,buf,__FILE__,__LINE__):\
174 do_write((void *)&(item[i]),1,eioREAL,buf,__FILE__,__LINE__));\
178 #define ndo_int(item,n,bOK) {\
180 for(i=0; (i<n); i++) {\
182 sprintf(buf,"%s[%d]",#item,i);\
183 bOK = bOK && (bRead ?\
184 do_read ((void *)&(item[i]),1,eioINT,buf,__FILE__,__LINE__):\
185 do_write((void *)&(item[i]),1,eioINT,buf,__FILE__,__LINE__));\
189 #define ndo_rvec(item,n) (bRead ?\
190 do_read ((void *)(item),n,eioNRVEC,(#item),__FILE__,__LINE__) :\
191 do_write((void *)(item),n,eioNRVEC,(#item),__FILE__,__LINE__))
193 #define ndo_ivec(item,n,bOK) {\
195 for(i=0; (i<n); i++) {\
197 sprintf(buf,"%s[%d]",#item,i);\
198 bOK = bOK && (bRead ?\
199 do_read ((void *)(item)[i],1,eioIVEC,buf,__FILE__,__LINE__):\
200 do_write((void *)(item)[i],1,eioIVEC,buf,__FILE__,__LINE__));\
204 #define ndo_string(item,n,bOK) {\
206 for(i=0; (i<n); i++) {\
208 sprintf(buf,"%s[%d]",#item,i);\
209 bOK = bOK && (bRead ?\
210 do_read ((void *)(item)[i],1,eioSTRING,buf,__FILE__,__LINE__):\
211 do_write((void *)(item)[i],1,eioSTRING,buf,__FILE__,__LINE__));\