Commit d465ad8b authored by Mark Abraham's avatar Mark Abraham Committed by Berk Hess
Browse files

Fix logic of TRR reading

Commit f7d4d019 introduced a bug where TRR reading reaching the end of
the file was indistinguishable from a reading error or a magic-number
error. This is now fixed, restoring the end-of-file behaviour that
existed before f7d4d019, while retaining the wrong-magic-number
behaviour that it introduced.

Refs #1926

Change-Id: Ic8540846c481f022bc6ae7b774794792c8c7a523
parent ccbd250a
......@@ -82,6 +82,14 @@ static int nFloatSize(gmx_trr_header_t *sh)
return nflsize;
}
/* Returns whether a valid frame header was read. Upon exit, *bOK is
TRUE if a normal outcome resulted. Usually that is the same thing,
but encountering the end of the file before reading the magic
integer is a normal outcome for TRR reading, and it does not
produce a valid frame header, so the values differ in that case.
That does not exclude the possibility of a reading error between
frames, but the trajectory-handling infrastructure needs an
overhaul before we can handle that. */
static gmx_bool
do_trr_frame_header(t_fileio *fio, bool bRead, gmx_trr_header_t *sh, gmx_bool *bOK)
{
......@@ -94,9 +102,11 @@ do_trr_frame_header(t_fileio *fio, bool bRead, gmx_trr_header_t *sh, gmx_bool *b
if (!gmx_fio_do_int(fio, magic))
{
// Failed to read an integer, which should be the magic number
*bOK = FALSE;
return *bOK;
/* Failed to read an integer, which should be the magic
number, which usually means we've reached the end
of the file (but could be an I/O error that we now
might mishandle). */
return FALSE;
}
if (magic != magicValue)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment