int xtc_seek_frame(t_fileio *fio, int frame, int natoms);
-int xtc_seek_time(t_fileio *fio, real time, int natoms);
+int xtc_seek_time(t_fileio *fio, real time, int natoms,gmx_bool bSeekForwardOnly);
/* Add this to the comment string for debugging */
float xdr_xtc_estimate_dt(FILE *fp, XDR *xdrs, int natoms, gmx_bool * bOK);
-int xdr_xtc_seek_time(real time, FILE *fp, XDR *xdrs, int natoms);
+ int xdr_xtc_seek_time(real time, FILE *fp, XDR *xdrs, int natoms,gmx_bool bSeekForwardOnly);
int xdr_xtc_seek_frame(int frame, FILE *fp, XDR *xdrs, int natoms);
return ret;
}
-int xtc_seek_time(t_fileio *fio, real time, int natoms)
+int xtc_seek_time(t_fileio *fio, real time, int natoms,gmx_bool bSeekForwardOnly)
{
int ret;
gmx_fio_lock(fio);
- ret=xdr_xtc_seek_time(time, fio->fp, fio->xdr, natoms);
+ ret=xdr_xtc_seek_time(time, fio->fp, fio->xdr, natoms, bSeekForwardOnly);
gmx_fio_unlock(fio);
return ret;
-int xdr_xtc_seek_time(real time, FILE *fp, XDR *xdrs, int natoms)
+int xdr_xtc_seek_time(real time, FILE *fp, XDR *xdrs, int natoms,gmx_bool bSeekForwardOnly)
{
float t;
float dt;
int res;
int dt_sign = 0;
+ if (bSeekForwardOnly)
+ {
+ low = gmx_ftell(fp);
+ }
if (gmx_fseek(fp,0,SEEK_END))
{
return -1;
/* round to int */
high /= XDR_INT_SIZE;
high *= XDR_INT_SIZE;
- offset = ((high / 2) / XDR_INT_SIZE) * XDR_INT_SIZE;
+ offset = (((high-low) / 2) / XDR_INT_SIZE) * XDR_INT_SIZE;
if (gmx_fseek(fp,offset,SEEK_SET))
{
* accuracy of the control over -b and -e options.
*/
if (bTimeSet(TBEGIN) && (fr->time < rTimeValue(TBEGIN))) {
- if (xtc_seek_time(status->fio, rTimeValue(TBEGIN),fr->natoms)) {
- gmx_fatal(FARGS,"Specified frame doesn't exist or file not seekable");
+ if (xtc_seek_time(status->fio, rTimeValue(TBEGIN),fr->natoms,TRUE)) {
+ gmx_fatal(FARGS,"Specified frame (time %f) doesn't exist or file corrupt/inconsistent.",
+ rTimeValue(TBEGIN));
}
initcount(status);
}
{
searchtime = last_frame_time;
}
- if (xtc_seek_time(stfio,searchtime,fr.natoms))
+ if (xtc_seek_time(stfio,searchtime,fr.natoms,TRUE))
{
gmx_fatal(FARGS,"Error seeking to append position.");
}