From b0d373c9cb47383f10ed8600a53434d02ad789f1 Mon Sep 17 00:00:00 2001 From: Niels Mueller Date: Tue, 8 Oct 2019 15:03:40 +0200 Subject: [PATCH] Enables time info for XTCReader --- pygmx/xtcio.pyx | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) mode change 100644 => 100755 pygmx/xtcio.pyx diff --git a/pygmx/xtcio.pyx b/pygmx/xtcio.pyx old mode 100644 new mode 100755 index 0624091..408db88 --- a/pygmx/xtcio.pyx +++ b/pygmx/xtcio.pyx @@ -152,27 +152,33 @@ cdef class XTCReader: size = xtc_stat.st_size with open(indexfile, 'rb') as fd: - unpacker = Unpacker(SubscriptableReader(fd)) + unpacker = Unpacker(fd.read()) + # first 4 * 8 bytes are used for checks, followed by N * (8 + 4) bytes of data + length = int((len(unpacker.get_buffer()) - 32) / 12) - if unpacker.unpack_hyper() != INDEX_MAGIC: - raise InvalidMagicException - if unpacker.unpack_hyper() != c_time and not ignore_time: - raise InvalidIndexException - if unpacker.unpack_hyper() != m_time and not ignore_time: - raise InvalidIndexException - if unpacker.unpack_hyper() != size: - raise InvalidIndexException + if length < 0: + raise InvalidIndexException - self._cache = array('L') - self._times = array('f') + if unpacker.unpack_hyper() != INDEX_MAGIC: + raise InvalidMagicException + if unpacker.unpack_hyper() != c_time and not ignore_time: + raise InvalidIndexException + if unpacker.unpack_hyper() != m_time and not ignore_time: + raise InvalidIndexException + if unpacker.unpack_hyper() != size: + raise InvalidIndexException - try: - while True: - self._cache.append(unpacker.unpack_hyper()) - self._times.append(unpacker.unpack_float()) - except EOFError: - pass + self._cache = array('L') + self._times = array('f') + + try: + while True: + self._cache.append(unpacker.unpack_hyper()) + self._times.append(unpacker.unpack_float()) + except EOFError: + pass self.has_cache = True + self.has_times = True def __cinit__(self): self.has_cache = False