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
33 static char *SRCID_gmxfio_h
= "$Id$";
38 /* Enumerated for different items in files */
39 enum { eitemHEADER
, eitemIR
, eitemBOX
,
40 eitemTOP
, eitemX
, eitemV
, eitemF
, eitemNR
};
42 /* Enumerated for data types in files */
43 enum { eioREAL
, eioINT
, eioNUCHAR
, eioUSHORT
,
44 eioRVEC
, eioNRVEC
, eioIVEC
, eioSTRING
, eioNR
};
46 /* Functions for reading and writing data */
47 typedef bool do_func(void *item
,int nitem
,int eio
,
48 char *desc
,char *srcfile
,int line
);
50 /* Global variables defined in gmxfio.h */
51 extern do_func
*do_read
;
52 extern do_func
*do_write
;
53 extern char *itemstr
[eitemNR
];
54 extern char *comment_str
[eitemNR
];
56 /********************************************************
58 ********************************************************/
60 extern int fio_open(char *fn
,char *mode
);
61 /* Open a new file for reading or writing.
62 * The file type will be deduced from the file name.
63 * If fn is NULL, stdin / stdout will be used for Ascii I/O (TPA type)
64 * mode may be "r", "w", "a"
67 extern void fio_close(int fp
);
68 /* Close the file corresponding to fp (if not stdio)
69 * The routine will exit when an invalid fio is handled.
72 extern void fio_select(int fp
);
73 /* This routine sets the global variables do_read and do_write
74 * to point to the correct routines for fp.
77 /********************************************************
78 * Change properties of the open file
79 ********************************************************/
81 extern void fio_setprecision(int fio
,bool bDouble
);
82 /* Select the floating point precision for reading and writing files */
84 extern char *fio_getname(int fio
);
85 /* Return the filename corresponding to the fio index */
87 extern int fio_getftp(int fio
);
88 /* Return the filetype corresponding to the fio index */
90 extern void fio_setftp_fio(int fio
,int ftp
);
93 extern void fio_setdebug(int fio
,bool bDebug
);
94 /* Set the debug mode */
96 extern bool fio_getdebug(int fio
);
97 /* Return whether debug mode is on in fio */
99 extern bool fio_getread(int fio
);
100 /* Return whether read mode is on in fio */
102 /***************************************************
104 ***************************************************/
106 extern void fio_rewind(int fio
);
107 /* Rewind the tpa file in fio */
109 extern void fio_flush(int fio
);
112 extern long fio_ftell(int fio
);
113 /* Return file position if possible */
115 extern void fio_seek(int fio
,long fpos
);
116 /* Set file position if possible, quit otherwise */
118 extern FILE *fio_getfp(int fio
);
119 /* Return the file pointer itself */
121 extern XDR
*fio_getxdr(int fio
);
122 /* Return the file pointer itself */
124 extern void set_comment(char *comment
);
125 /* Add this to the comment string for debugging */
127 extern void unset_comment(void);
128 /* Remove previously set comment */
131 /********************************************************
132 * Dirty C macros... Try this in FORTRAN
133 * (Oh, and you can do structured programming in C too)
134 *********************************************************/
135 #define do_real(item) (bRead ?\
136 do_read ((void *)&(item),1,eioREAL,(#item),__FILE__,__LINE__) : \
137 do_write((void *)&(item),1,eioREAL,(#item),__FILE__,__LINE__))
139 #define do_int(item) (bRead ?\
140 do_read ((void *)&(item),1,eioINT,(#item),__FILE__,__LINE__) :\
141 do_write((void *)&(item),1,eioINT,(#item),__FILE__,__LINE__))
143 #define do_nuchar(item,n) (bRead ?\
144 do_read ((void *)(item),n,eioNUCHAR,(#item),__FILE__,__LINE__) :\
145 do_write((void *)(item),n,eioNUCHAR,(#item),__FILE__,__LINE__))
147 #define do_ushort(item) (bRead ?\
148 do_read ((void *)&(item),1,eioUSHORT,(#item),__FILE__,__LINE__) :\
149 do_write((void *)&(item),1,eioUSHORT,(#item),__FILE__,__LINE__))
151 #define do_rvec(item) (bRead ?\
152 do_read ((void *)(item),1,eioRVEC,(#item),__FILE__,__LINE__) :\
153 do_write((void *)(item),1,eioRVEC,(#item),__FILE__,__LINE__))
155 #define do_ivec(item) (bRead ?\
156 do_read ((void *)(item),1,eioIVEC,(#item),__FILE__,__LINE__) :\
157 do_write((void *)(item),1,eioIVEC,(#item),__FILE__,__LINE__))
159 #define do_string(item) (bRead ?\
160 do_read ((void *)(item),1,eioSTRING,(#item),__FILE__,__LINE__) :\
161 do_write((void *)(item),1,eioSTRING,(#item),__FILE__,__LINE__))
163 #define ndo_real(item,n,bOK) \
165 for(i=0; (i<n); i++) {\
167 sprintf(buf,"%s[%d]",#item,i);\
168 bOK = bOK && (bRead ?\
169 do_read ((void *)&((item)[i]),1,eioREAL,buf,__FILE__,__LINE__):\
170 do_write((void *)&(item[i]),1,eioREAL,buf,__FILE__,__LINE__));\
173 #define ndo_int(item,n,bOK) \
175 for(i=0; (i<n); i++) {\
177 sprintf(buf,"%s[%d]",#item,i);\
178 bOK = bOK && (bRead ?\
179 do_read ((void *)&(item[i]),1,eioINT,buf,__FILE__,__LINE__):\
180 do_write((void *)&(item[i]),1,eioINT,buf,__FILE__,__LINE__));\
183 #define ndo_rvec(item,n) (bRead ?\
184 do_read ((void *)(item),n,eioNRVEC,(#item),__FILE__,__LINE__) :\
185 do_write((void *)(item),n,eioNRVEC,(#item),__FILE__,__LINE__))
187 #define ndo_ivec(item,n,bOK) \
189 for(i=0; (i<n); i++) {\
191 sprintf(buf,"%s[%d]",#item,i);\
192 bOK = bOK && (bRead ?\
193 do_read ((void *)(item)[i],1,eioIVEC,buf,__FILE__,__LINE__):\
194 do_write((void *)(item)[i],1,eioIVEC,buf,__FILE__,__LINE__));\
197 #define ndo_string(item,n,bOK) \
199 for(i=0; (i<n); i++) {\
201 sprintf(buf,"%s[%d]",#item,i);\
202 bOK = bOK && (bRead ?\
203 do_read ((void *)(item)[i],1,eioSTRING,buf,__FILE__,__LINE__):\
204 do_write((void *)(item)[i],1,eioSTRING,buf,__FILE__,__LINE__));\