1 /* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
11 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
12 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
13 * Copyright (c) 2001-2004, The GROMACS development team,
14 * check out http://www.gromacs.org for more information.
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * If you want to redistribute modifications, please consider that
22 * scientific software is very special. Version control is crucial -
23 * bugs must be traceable. We will be happy to consider code for
24 * inclusion in the official distribution, but derived work must not
25 * be called official GROMACS. Details are found in the README & COPYING
26 * files - if they are missing, get the official version at www.gromacs.org.
28 * To help us fund GROMACS development, we humbly ask that you cite
29 * the papers on the package - you can find them in the top README file.
31 * For more info, check our website at http://www.gromacs.org
34 * GROningen Mixture of Alchemy and Childrens' Stories
47 #include "gmx_fatal.h"
57 #include "thread_mpi.h"
60 #include "gmxfio_int.h"
62 /* This is the part that reads dummy and ascii files. */
65 static gmx_bool
do_binread(t_fileio
*fio
, void *item
, int nitem
, int eio
,
66 const char *desc
, const char *srcfile
, int line
);
67 static gmx_bool
do_binwrite(t_fileio
*fio
, const void *item
, int nitem
, int eio
,
68 const char *desc
, const char *srcfile
, int line
);
71 const t_iotype bin_iotype
={do_binread
, do_binwrite
};
74 static gmx_bool
do_binwrite(t_fileio
*fio
, const void *item
, int nitem
, int eio
,
75 const char *desc
, const char *srcfile
, int line
)
77 size_t size
= 0, wsize
;
80 gmx_fio_check_nitem(fio
, eio
, nitem
, srcfile
, line
);
90 size
= sizeof(double);
95 case eioGMX_LARGE_INT
:
96 size
= sizeof(gmx_large_int_t
);
99 size
= sizeof(unsigned char);
102 size
= sizeof(unsigned char);
105 size
= sizeof(unsigned short);
117 size
= ssize
= strlen((char *) item
) + 1;
118 do_binwrite(fio
, &ssize
, 1, eioINT
, desc
, srcfile
, line
);
121 gmx_fio_fe(fio
, eio
, desc
, srcfile
, line
);
124 wsize
= fwrite(item
, size
, nitem
, fio
->fp
);
126 if ((wsize
!= nitem
) && fio
->bDebug
)
129 "Error writing %s %s to file %s (source %s, line %d)\n",
130 eioNames
[eio
], desc
, fio
->fn
, srcfile
, line
);
131 fprintf(stderr
, "written size %u bytes, source size %u bytes\n",
132 (unsigned int) wsize
, (unsigned int) size
);
134 return (wsize
== nitem
);
137 static gmx_bool
do_binread(t_fileio
*fio
, void *item
, int nitem
, int eio
,
138 const char *desc
, const char *srcfile
, int line
)
140 size_t size
= 0, rsize
;
143 gmx_fio_check_nitem(fio
, eio
, nitem
, srcfile
, line
);
148 size
= sizeof(double);
150 size
= sizeof(float);
153 size
= sizeof(float);
156 size
= sizeof(double);
161 case eioGMX_LARGE_INT
:
162 size
= sizeof(gmx_large_int_t
);
165 size
= sizeof(unsigned char);
168 size
= sizeof(unsigned char);
171 size
= sizeof(unsigned short);
176 size
= sizeof(double) * DIM
;
178 size
= sizeof(float) * DIM
;
184 do_binread(fio
, &ssize
, 1, eioINT
, desc
, srcfile
, line
);
188 gmx_fio_fe(fio
, eio
, desc
, srcfile
, line
);
191 rsize
= fread(item
, size
, nitem
, fio
->fp
);
194 /* Skip over it if we have a NULL pointer here */
195 gmx_fseek(fio
->fp
, (gmx_off_t
)(size
*nitem
), SEEK_CUR
);
198 if ((rsize
!= nitem
) && (fio
->bDebug
))
200 "Error reading %s %s from file %s (source %s, line %d)\n",
201 eioNames
[eio
], desc
, fio
->fn
, srcfile
, line
);
203 return (rsize
== nitem
);