Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XDR file seeks and tells working again on large files (closes #677) #678

Merged
merged 4 commits into from
Jan 29, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@ The rules for this file:

------------------------------------------------------------------------------
??/??/16 tyler.je.reddy, kain88-de, jbarnoud, richardjgowers, orbeckst
manuel.nuno.melo

* 0.14.0

API Changes

* Offsets files for Gromacs trajectory formats have been changed to a numpy
style format '.npz'. Offsets files will be regenerated when you load a
xtc/trr trajectory again. (Issue #441)

Enhancement

* XDR file seeking errors now report system errno. (PR #678)
* Offsets reading for xtc/trr files has been sped up. (Issue #441)
* select_atoms now implicitly ORs multiple values after a keyword for
many types of selections (Issue #345)
Expand All @@ -33,6 +37,8 @@ Changes
* util.NamedStream no longer inherits from basestring (Issue #649)

Fixes

* XDR file seeking and telling working again for large files (Issue #677).
* ContactAnalysis1 run method now starts at frame index 0 by deafult (Issue #624)
* Fixed PrimitivePDBWriter getting atom type column shifted to the right
(Issue #639)
Expand Down
19 changes: 13 additions & 6 deletions package/MDAnalysis/lib/formats/src/xdrfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <string.h>
#include <math.h>
#include <limits.h>
#include <errno.h>

/* get fixed-width types if we are using ANSI C99 */
#ifdef HAVE_STDINT_H
Expand Down Expand Up @@ -2515,8 +2516,8 @@ static int xdrstdio_getlong (XDR *, int32_t *);
static int xdrstdio_putlong (XDR *, int32_t *);
static int xdrstdio_getbytes (XDR *, char *, unsigned int);
static int xdrstdio_putbytes (XDR *, char *, unsigned int);
static unsigned int xdrstdio_getpos (XDR *);
static int xdrstdio_setpos (XDR *, unsigned int, int);
static off_t xdrstdio_getpos (XDR *);
static int xdrstdio_setpos (XDR *, off_t, int);
static void xdrstdio_destroy (XDR *);

/*
Expand Down Expand Up @@ -2598,16 +2599,22 @@ xdrstdio_putbytes (XDR *xdrs, char *addr, unsigned int len)
}


static unsigned int
static off_t
xdrstdio_getpos (XDR *xdrs)
{
return ftello((FILE *) xdrs->x_private);
}

static int
xdrstdio_setpos (XDR *xdrs, unsigned int pos, int whence)
xdrstdio_setpos (XDR *xdrs, off_t pos, int whence)
{
return fseeko((FILE *) xdrs->x_private, pos, whence) < 0 ? exdrNR : exdrOK;
/* A reason for failure can be filesystem limits on allocation units,
* before the actual off_t overflow (ext3, with a 4K clustersize,
* has a 16TB limit).*/
/* We return errno relying on the fact that it is never set to 0 on
* success, which means that if an error occurrs it'll never be the same
* as exdrOK, and xdr_seek won't be confused.*/
return fseeko((FILE *) xdrs->x_private, pos, whence) < 0 ? errno : exdrOK;
}


Expand All @@ -2621,7 +2628,7 @@ int xdr_seek(XDRFILE *xd, int64_t pos, int whence)
/* Seeks to position in file */
{
int result;
if ((result = xdrstdio_setpos(xd->xdr, (off_t) pos, whence)) != exdrOK)
if ((result = xdrstdio_setpos(xd->xdr, (off_t) pos, whence)) != 0)
return result;

return exdrOK;
Expand Down
Loading