23af481054a03829f8501ea842f283727c14bc0c
[alexxy/gromacs.git] / include / binio.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  * Good ROcking Metal Altar for Chronical Sinners
28  */
29
30 #ifndef _binio_h
31 #define _binio_h
32
33 static char *SRCID_binio_h = "$Id$";
34 #ifdef HAVE_CONFIG_H
35 #include <config.h>
36 #endif
37
38 #ifdef HAVE_IDENT
39 #ident  "@(#) binio.h 1.5 11/23/92"
40 #endif /* HAVE_IDENT */
41
42 #include <stdio.h>
43 #include "sysstuff.h"
44 #include "fatal.h"
45
46 /*
47  *    Module to binary write and read.
48  *
49  *                                        @                   
50  *    @@@   @@                            @
51  *     @     @
52  *     @  @  @   @@@   @@ @@@  @@ @@    @@@    @@ @@     @@ @@
53  *     @  @  @  @   @   @@   @  @@  @     @     @@  @   @  @@
54  *     @ @ @ @      @   @       @   @     @     @   @  @    @
55  *      @@ @@   @@@@@   @       @   @     @     @   @  @    @
56  *      @   @  @    @   @       @   @     @     @   @  @    @
57  *      @   @  @   @@   @       @   @     @     @   @   @  @@
58  *      @   @   @@@ @@ @@@@    @@@ @@@  @@@@@  @@@ @@@   @@ @
59  *                                                          @
60  *                                                         @
61  *                                                      @@@
62  *
63  *    Use this module only to write and read simple types or array(s)
64  *    of simple types. STRUCTURES ARE DEFINITELY NOT ALLOWED.
65  */
66
67 #define nblockwrite(fp,nelem,data) \
68   _blockwrite(fp,nelem,sizeof(*data),(data),#data,__FILE__,__LINE__)
69 #define blockwrite(fp,data) \
70   _blockwrite(fp,1,sizeof(data),&(data),#data,__FILE__,__LINE__)
71 #define cblockwrite(fp,ptr,nchars) \
72   _blockwrite(fp,1,(nchars),(ptr),#ptr,__FILE__,__LINE__)
73 #define nblockread(fp,nelem,data) \
74   _blockread(fp,nelem,sizeof(*data),(data),#data,__FILE__,__LINE__)
75 #define blockread(fp,data) \
76   _blockread(fp,1,sizeof(data),&(data),#data,__FILE__,__LINE__)
77 #define cblockread(fp,ptr,nchars) \
78   _blockread(fp,1,(nchars),(ptr),#ptr,__FILE__,__LINE__)
79
80 #define patch(fp,fpos,write) \
81   do \
82     { \
83       int result,fhere; \
84       \
85       fhere=ftell(fp); \
86       if ((result=fseek(fp,fpos,SEEK_SET))!=0) \
87         fatal_error(errno,"could not seek to position %d from file %s, " \
88                     "line %d, result=%d",(fpos),__FILE__,__LINE__,result); \
89       write; \
90       if ((result=fseek(fp,fhere,SEEK_SET))!=0) \
91         fatal_error(errno,"could not seek back to %d from file %s, line %d," \
92                     " result=%d",fhere,__FILE__,__LINE__,result); \
93     } \
94   while (0)
95
96 extern void _blockwrite(FILE *fp,int nelem,int size,void *data,
97                         char *what,char *file,int line);
98
99 extern void _blockread(FILE *fp,int nelem,int size,void *data,
100                        char *what,char *file,int line);
101
102 #endif  /* _binio_h */