Fix that skipping fails if target is 2nd frame
authorRoland Schulz <roland@utk.edu>
Sat, 14 Jun 2014 03:39:20 +0000 (23:39 -0400)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Tue, 17 Jun 2014 15:19:50 +0000 (17:19 +0200)
With bSeekForwardOnly the current file position should be an inclusive boundary,
but because the binary search stops if the search region (high-low) becomes
header_size, the current frame wasn't found. Because trjconv always reads the
first frame before calling seek, it failed if the target was the 2nd frame.

Fixes #1154

Change-Id: Id4151f0106abdb68d6067f02fe2927a4ec6d77a0

src/gmxlib/libxdrf.c

index d3209280241d9c746c01700b42f4c1aca5de0869..dd56225b548d38e697a25c9ee0f5b68bd029730f 100644 (file)
@@ -1466,7 +1466,7 @@ int xdr_xtc_seek_time(real time, FILE *fp, XDR *xdrs, int natoms, gmx_bool bSeek
 
     if (bSeekForwardOnly)
     {
-        low = gmx_ftell(fp);
+        low = gmx_ftell(fp)-header_size;
     }
     if (gmx_fseek(fp, 0, SEEK_END))
     {