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