Fix that seeking was wrong if frame time was modified
authorRoland Schulz <roland@utk.edu>
Sat, 14 Jun 2014 01:07:43 +0000 (21:07 -0400)
committerRoland Schulz <roland@rschulz.eu>
Fri, 20 Jun 2014 10:36:43 +0000 (12:36 +0200)
The trjconv -t0 option causes fr->time to be modified and
this then causes the skipping to be incorrect. Alternative
we could document that fr->time shouldn't be modified
and change that trjconv makes a copy of fr before changing
time. This change has the advantage it is less likely
to reintroduce the problem.

Fixes #1405, #1406

Change-Id: Ibd692dfecdf175450fc43f7f35b774bf4446b316

include/types/trx.h
src/gmxlib/trxio.c

index 481aaffb1470b974949ad2bc16787bf34a3cd7c3..82e36c908d92916d9eab302546653a973225ccd8 100644 (file)
@@ -60,6 +60,7 @@ typedef struct trxframe
     int      natoms;           /* number of atoms (atoms, x, v, f) */
     real     t0;               /* time of the first frame, needed  *
                                 * for skipping frames with -dt     */
+    real     tf;               /* internal frame time - DO NOT CHANGE */
     real     tpf;              /* time of the previous frame, not  */
                                /* the read, but real file frames   */
     real     tppf;             /* time of two frames ago           */
index 5822627fba5ef01d0eccd22f742b35577a1afcba..e56f383cac870a761081802bede862e6e6767c7d 100644 (file)
@@ -180,6 +180,7 @@ void clear_trxframe(t_trxframe *fr, gmx_bool bFirst)
         fr->bDouble = FALSE;
         fr->natoms  = -1;
         fr->t0      = 0;
+        fr->tf      = 0;
         fr->tpf     = 0;
         fr->tppf    = 0;
         fr->title   = NULL;
@@ -805,13 +806,13 @@ gmx_bool read_next_frame(const output_env_t oenv, t_trxstatus *status, t_trxfram
     int      dummy = 0;
 
     bRet = FALSE;
-    pt   = fr->time;
+    pt   = fr->tf;
 
     do
     {
         clear_trxframe(fr, FALSE);
         fr->tppf = fr->tpf;
-        fr->tpf  = fr->time;
+        fr->tpf  = fr->tf;
 
         switch (gmx_fio_getftp(status->fio))
         {
@@ -842,7 +843,7 @@ gmx_bool read_next_frame(const output_env_t oenv, t_trxstatus *status, t_trxfram
                 /* DvdS 2005-05-31: this has been fixed along with the increased
                  * accuracy of the control over -b and -e options.
                  */
-                if (bTimeSet(TBEGIN) && (fr->time < rTimeValue(TBEGIN)))
+                if (bTimeSet(TBEGIN) && (fr->tf < rTimeValue(TBEGIN)))
                 {
                     if (xtc_seek_time(status->fio, rTimeValue(TBEGIN), fr->natoms, TRUE))
                     {
@@ -880,6 +881,7 @@ gmx_bool read_next_frame(const output_env_t oenv, t_trxstatus *status, t_trxfram
                           gmx_fio_getname(status->fio));
 #endif
         }
+        fr->tf = fr->time;
 
         if (bRet)
         {
@@ -1043,6 +1045,7 @@ int read_first_frame(const output_env_t oenv, t_trxstatus **status,
 #endif
             break;
     }
+    fr->tf = fr->time;
 
     /* Return FALSE if we read a frame that's past the set ending time. */
     if (!bFirst && (!(fr->flags & TRX_DONT_SKIP) && check_times(fr->time) > 0))