2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2013,2014,2015,2016,2017,2018,2019,2020, 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.
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.
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.
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.
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.
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.
37 #ifndef GMX_FILEIO_GMXFIO_XDR_H
38 #define GMX_FILEIO_GMXFIO_XDR_H
44 #include "gromacs/fileio/xdrf.h"
45 #include "gromacs/math/vectypes.h"
46 #include "gromacs/utility/basedefinitions.h"
47 #include "gromacs/utility/iserializer.h"
48 #include "gromacs/utility/real.h"
52 void gmx_fio_setprecision(struct t_fileio
* fio
, gmx_bool bDouble
);
53 /* Select the floating point precision for reading and writing files */
55 bool gmx_fio_is_double(struct t_fileio
* fio
);
57 XDR
* gmx_fio_getxdr(struct t_fileio
* fio
);
58 /* Return the file pointer itself */
60 gmx_bool
gmx_fio_writee_string(struct t_fileio
* fio
, const char* item
, const char* desc
, const char* srcfile
, int line
);
62 /* reading or writing, depending on the file's opening mode string */
63 gmx_bool
gmx_fio_doe_real(struct t_fileio
* fio
, real
* item
, const char* desc
, const char* srcfile
, int line
);
64 gmx_bool
gmx_fio_doe_float(struct t_fileio
* fio
, float* item
, const char* desc
, const char* srcfile
, int line
);
65 gmx_bool
gmx_fio_doe_double(struct t_fileio
* fio
, double* item
, const char* desc
, const char* srcfile
, int line
);
66 gmx_bool
gmx_fio_doe_gmx_bool(struct t_fileio
* fio
, gmx_bool
* item
, const char* desc
, const char* srcfile
, int line
);
67 gmx_bool
gmx_fio_doe_int(struct t_fileio
* fio
, int* item
, const char* desc
, const char* srcfile
, int line
);
68 gmx_bool
gmx_fio_doe_int32(struct t_fileio
* fio
, int32_t* item
, const char* desc
, const char* srcfile
, int line
);
69 gmx_bool
gmx_fio_doe_int64(struct t_fileio
* fio
, int64_t* item
, const char* desc
, const char* srcfile
, int line
);
70 gmx_bool
gmx_fio_doe_uchar(struct t_fileio
* fio
, unsigned char* item
, const char* desc
, const char* srcfile
, int line
);
71 gmx_bool
gmx_fio_doe_char(struct t_fileio
* fio
, char* item
, const char* desc
, const char* srcfile
, int line
);
72 gmx_bool
gmx_fio_doe_ushort(struct t_fileio
* fio
,
77 gmx_bool
gmx_fio_doe_rvec(struct t_fileio
* fio
, rvec
* item
, const char* desc
, const char* srcfile
, int line
);
78 gmx_bool
gmx_fio_doe_ivec(struct t_fileio
* fio
, ivec
* item
, const char* desc
, const char* srcfile
, int line
);
79 gmx_bool
gmx_fio_doe_string(struct t_fileio
* fio
, char* item
, const char* desc
, const char* srcfile
, int line
);
80 gmx_bool
gmx_fio_doe_opaque(struct t_fileio
* fio
,
87 /* array reading & writing */
88 gmx_bool
gmx_fio_ndoe_real(struct t_fileio
* fio
, real
* item
, int n
, const char* desc
, const char* srcfile
, int line
);
89 gmx_bool
gmx_fio_ndoe_float(struct t_fileio
* fio
, float* item
, int n
, const char* desc
, const char* srcfile
, int line
);
90 gmx_bool
gmx_fio_ndoe_double(struct t_fileio
* fio
, double* item
, int n
, const char* desc
, const char* srcfile
, int line
);
91 gmx_bool
gmx_fio_ndoe_gmx_bool(struct t_fileio
* fio
,
97 gmx_bool
gmx_fio_ndoe_int(struct t_fileio
* fio
, int* item
, int n
, const char* desc
, const char* srcfile
, int line
);
98 gmx_bool
gmx_fio_ndoe_int32(struct t_fileio
* fio
, int32_t* item
, int n
, const char* desc
, const char* srcfile
, int line
);
99 gmx_bool
gmx_fio_ndoe_int64(struct t_fileio
* fio
, int64_t* item
, int n
, const char* desc
, const char* srcfile
, int line
);
100 gmx_bool
gmx_fio_ndoe_uchar(struct t_fileio
* fio
,
106 gmx_bool
gmx_fio_ndoe_char(struct t_fileio
* fio
, char* item
, int n
, const char* desc
, const char* srcfile
, int line
);
107 gmx_bool
gmx_fio_ndoe_ushort(struct t_fileio
* fio
,
108 unsigned short* item
,
113 gmx_bool
gmx_fio_ndoe_rvec(struct t_fileio
* fio
, rvec
* item
, int n
, const char* desc
, const char* srcfile
, int line
);
114 gmx_bool
gmx_fio_ndoe_ivec(struct t_fileio
* fio
, ivec
* item
, int n
, const char* desc
, const char* srcfile
, int line
);
115 gmx_bool
gmx_fio_ndoe_string(struct t_fileio
* fio
, char* item
[], int n
, const char* desc
, const char* srcfile
, int line
);
118 /* convenience macros */
119 #define gmx_fio_write_string(fio, item) \
120 gmx_fio_writee_string(fio, item, (#item), __FILE__, __LINE__)
122 #define gmx_fio_do_real(fio, item) gmx_fio_doe_real(fio, &(item), (#item), __FILE__, __LINE__)
123 #define gmx_fio_do_float(fio, item) gmx_fio_doe_float(fio, &(item), (#item), __FILE__, __LINE__)
124 #define gmx_fio_do_double(fio, item) gmx_fio_doe_double(fio, &(item), (#item), __FILE__, __LINE__)
125 #define gmx_fio_do_gmx_bool(fio, item) \
126 gmx_fio_doe_gmx_bool(fio, &(item), (#item), __FILE__, __LINE__)
127 #define gmx_fio_do_int(fio, item) gmx_fio_doe_int(fio, &(item), (#item), __FILE__, __LINE__)
128 #define gmx_fio_do_int32(fio, item) gmx_fio_doe_int32(fio, &(item), (#item), __FILE__, __LINE__)
129 #define gmx_fio_do_int64(fio, item) gmx_fio_doe_int64(fio, &(item), (#item), __FILE__, __LINE__)
130 #define gmx_fio_do_uchar(fio, item) gmx_fio_doe_uchar(fio, &(item), (#item), __FILE__, __LINE__)
131 #define gmx_fio_do_char(fio, item) gmx_fio_doe_char(fio, &(item), (#item), __FILE__, __LINE__)
132 #define gmx_fio_do_ushort(fio, item) gmx_fio_doe_ushort(fio, &(item), (#item), __FILE__, __LINE__)
133 #define gmx_fio_do_rvec(fio, item) gmx_fio_doe_rvec(fio, &(item), (#item), __FILE__, __LINE__)
134 #define gmx_fio_do_ivec(fio, item) gmx_fio_doe_ivec(fio, &(item), (#item), __FILE__, __LINE__)
135 #define gmx_fio_do_string(fio, item) gmx_fio_doe_string(fio, item, (#item), __FILE__, __LINE__)
136 #define gmx_fio_do_opaque(fio, item, size) \
137 gmx_fio_doe_opaque(fio, item, size, (#item), __FILE__, __LINE__)
140 #define gmx_fio_ndo_real(fio, item, n) gmx_fio_ndoe_real(fio, item, n, (#item), __FILE__, __LINE__)
141 #define gmx_fio_ndo_float(fio, item, n) \
142 gmx_fio_ndoe_float(fio, item, n, (#item), __FILE__, __LINE__)
143 #define gmx_fio_ndo_double(fio, item, n) \
144 gmx_fio_ndoe_double(fio, item, n, (#item), __FILE__, __LINE__)
145 #define gmx_fio_ndo_gmx_bool(fio, item, n) \
146 gmx_fio_ndoe_gmx_bool(fio, item, n, (#item), __FILE__, __LINE__)
147 #define gmx_fio_ndo_int(fio, item, n) gmx_fio_ndoe_int(fio, item, n, (#item), __FILE__, __LINE__)
148 #define gmx_fio_ndo_int32(fio, item, n) \
149 gmx_fio_ndoe_int32(fio, item, n, (#item), __FILE__, __LINE__)
150 #define gmx_fio_ndo_int64(fio, item, n) \
151 gmx_fio_ndoe_int64(fio, item, n, (#item), __FILE__, __LINE__)
152 #define gmx_fio_ndo_uchar(fio, item, n) \
153 gmx_fio_ndoe_uchar(fio, item, n, (#item), __FILE__, __LINE__)
154 #define gmx_fio_ndo_char(fio, item, n) gmx_fio_ndoe_char(fio, item, n, (#item), __FILE__, __LINE__)
155 #define gmx_fio_ndo_ushort(fio, item, n) \
156 gmx_fio_ndoe_ushort(fio, item, n, (#item), __FILE__, __LINE__)
157 #define gmx_fio_ndo_rvec(fio, item, n) gmx_fio_ndoe_rvec(fio, item, n, (#item), __FILE__, __LINE__)
158 #define gmx_fio_ndo_ivec(fio, item, n) gmx_fio_ndoe_ivec(fio, item, n, (#item), __FILE__, __LINE__)
159 #define gmx_fio_ndo_string(fio, item, n) \
160 gmx_fio_ndoe_string(fio, item, n, (#item), __FILE__, __LINE__)
165 * Serializer to read/write XDR data.
167 class FileIOXdrSerializer
: public ISerializer
170 //! Only create with valid file I/O handle.
171 explicit FileIOXdrSerializer(t_fileio
* fio
);
173 //! If file is open in reading mode.
174 bool reading() const override
;
176 void doBool(bool* value
) override
;
177 //! Handle unsigned char I/O.
178 void doUChar(unsigned char* value
) override
;
180 void doChar(char* value
) override
;
181 //! Handle unsigned short I/O.
182 void doUShort(unsigned short* value
) override
;
183 //! Handle default integer I/O.
184 void doInt(int* value
) override
;
185 //! Handle int32 I/O.
186 void doInt32(int32_t* value
) override
;
187 //! Handle int64 I/O.
188 void doInt64(int64_t* value
) override
;
189 //! Handle single precision float I/O.
190 void doFloat(float* value
) override
;
191 //! Handle double precision float I/O.
192 void doDouble(double* value
) override
;
193 //! Handle GROMACS floating point number I/O.
194 void doReal(real
* value
) override
;
195 //! Handle I/O of integer vector of size DIM.
196 void doIvec(ivec
* value
) override
;
197 //! Handle I/O of GROMACS real vector of size DIM.
198 void doRvec(rvec
* value
) override
;
199 //! Handle I/O if string.
200 void doString(std::string
* value
) override
;
201 //! Handle opaque data.
202 void doOpaque(char* data
, std::size_t size
) override
;
203 //! Special case for handling I/O of a vector of characters.
204 void doCharArray(char* values
, int elements
) override
;
205 //! Special case for handling I/O of a vector of unsigned characters.
206 void doUCharArray(unsigned char* values
, int elements
) override
;
207 //! Special case for handling I/O of a vector of rvecs.
208 void doRvecArray(rvec
* values
, int elements
) override
;