Update copyright statements and change license to LGPL
[alexxy/gromacs.git] / src / gmxlib / gmxfio_int.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5  * Copyright (c) 2001-2004, The GROMACS development team,
6  * check out http://www.gromacs.org for more information.
7  * Copyright (c) 2012, by the GROMACS development team, led by
8  * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9  * others, as listed in the AUTHORS file in the top-level source
10  * directory and at http://www.gromacs.org.
11  *
12  * GROMACS is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public License
14  * as published by the Free Software Foundation; either version 2.1
15  * of the License, or (at your option) any later version.
16  *
17  * GROMACS is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with GROMACS; if not, see
24  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
26  *
27  * If you want to redistribute modifications to GROMACS, please
28  * consider that scientific software is very special. Version
29  * control is crucial - bugs must be traceable. We will be happy to
30  * consider code for inclusion in the official distribution, but
31  * derived work must not be called official GROMACS. Details are found
32  * in the README & COPYING files - if they are missing, get the
33  * official version at http://www.gromacs.org.
34  *
35  * To help us fund GROMACS development, we humbly ask that you cite
36  * the research papers on the package. Check out http://www.gromacs.org.
37  */
38
39
40
41 /* This is the new improved and thread safe version of gmxfio.  */
42
43
44 /* WARNING WARNING WARNING WARNING
45    The data types used here are PRIVATE to gmxfio routines. DO NOT use them
46    directly in your own code, but use the external functions provided in 
47    include/gmxfio.h 
48
49    If you don't heed this warning, your code will suddenly stop working 
50    at some point in the not-so-distant future. 
51
52    WARNING WARNING WARNING WARNING */
53
54
55 /* XDR should be available on all platforms now, 
56  * but we keep the possibility of turning it off...
57  */
58 #define USE_XDR
59
60
61
62 /* the reader/writer functions  for t_iotype */
63 typedef gmx_bool read_func(t_fileio *fio, void *item, int nitem, int eio,
64                        const char *desc,const char *srcfile,int line);
65 typedef gmx_bool write_func(t_fileio *fio, const void *item, int nitem, int eio,
66                         const char *desc,const char *srcfile,int line);
67
68
69 /* these are pointers to the actual reading & writing functions */
70 typedef struct
71 {
72     read_func *nread;
73     write_func *nwrite;
74 } t_iotype;
75
76
77
78 struct t_fileio
79 {
80     FILE *fp; /* the file pointer */
81     const t_iotype *iotp;  /* file type */
82     gmx_bool bOpen,  /* the file is open */
83          bRead,  /* the file is open for reading */
84          bDouble, /* write doubles instead of floats */
85          bDebug, /* the file ops should come with debug info */
86          bStdio, /* the file is actually stdin or stdout */
87          bLargerThan_off_t,  /* if the file position is largen than off_t 
88                                 could hold */
89          bReadWrite; /* the file is open for reading and writing */
90     char *fn; /* the file name */
91     XDR *xdr; /* the xdr data pointer */
92     enum xdr_op xdrmode; /* the xdr mode */
93     int iFTP; /* the file type identifier */
94
95     const char *comment; /* a comment string for debugging */
96
97     t_fileio *next, *prev; /* next and previous file pointers in the
98                               linked list */
99 #ifdef GMX_THREAD_MPI
100     tMPI_Lock_t  mtx;  /* content locking mutex. This is a fast lock
101                           for performance reasons: in some cases every
102                           single byte that gets read/written requires
103                           a lock */
104 #endif
105 }; 
106
107
108
109 extern const t_iotype asc_iotype;
110 extern const t_iotype bin_iotype;
111 extern const t_iotype xdr_iotype;
112 extern const t_iotype dummy_iotype;
113
114 extern const char *eioNames[eioNR];
115
116
117
118 #define GMX_FIO_BUFLEN 256
119
120 /* make a debug string if that is requested in the fio */
121 const char *gmx_fio_dbgstr(t_fileio *fio, const char *desc, char *buf);
122 /* check the number of items against the allowed number of items */
123 void gmx_fio_check_nitem(t_fileio *fio, int eio, int nitem, const char *file, 
124                          int line);
125 /* check the output type against allowed values */
126 void gmx_fio_fe(t_fileio *fio, int eio, const char *desc, const char *srcfile, 
127                 int line);
128
129 /* lock/unlock the mutex associated with a fio  */
130 void gmx_fio_lock(t_fileio *fio);
131 void gmx_fio_unlock(t_fileio *fio);
132
133
134