From f80fadab6d17098793f14f443d0a88aab648ebf8 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 17 Jul 2012 08:59:17 -0400 Subject: [PATCH] Move need_to_reorder_bytes from binarywave to util. We'll be needing it for packed.load, so it's not binarywave-specific. --- igor/binarywave.py | 12 ++---------- igor/util.py | 8 ++++++++ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/igor/binarywave.py b/igor/binarywave.py index 70af310..f9c4e18 100644 --- a/igor/binarywave.py +++ b/igor/binarywave.py @@ -36,6 +36,7 @@ from .struct import Structure as _Structure from .struct import Field as _Field from .util import assert_null as _assert_null from .util import byte_order as _byte_order +from .util import need_to_reorder_bytes as _need_to_reorder_bytes from .util import checksum as _checksum @@ -226,15 +227,6 @@ WaveHeader5 = _Structure( # End IGOR constants and typedefs from IgorBin.h -# Begin functions from ReadWave.c - -def _need_to_reorder_bytes(version): - # If the low order byte of the version field of the BinHeader - # structure is zero then the file is from a platform that uses - # different byte-ordering and therefore all data will need to be - # reordered. - return version & 0xFF == 0 - def _version_structs(version, byte_order): if version == 1: bin = BinHeader1 @@ -271,7 +263,7 @@ def load(filename, strict=True): version = BinHeaderCommon.unpack_dict_from(b)['version'] needToReorderBytes = _need_to_reorder_bytes(version) byteOrder = _byte_order(needToReorderBytes) - + if needToReorderBytes: BinHeaderCommon.set_byte_order(byteOrder) version = BinHeaderCommon.unpack_dict_from(b)['version'] diff --git a/igor/util.py b/igor/util.py index 55c015c..c263cd1 100644 --- a/igor/util.py +++ b/igor/util.py @@ -63,6 +63,14 @@ def byte_order(needToReorderBytes): return '<' # little-endian return '>' # big-endian +# From ReadWave.c +def need_to_reorder_bytes(version): + # If the low order byte of the version field of the BinHeader + # structure is zero then the file is from a platform that uses + # different byte-ordering and therefore all data will need to be + # reordered. + return version & 0xFF == 0 + # From ReadWave.c def checksum(buffer, byte_order, oldcksum, numbytes): x = _numpy.ndarray( -- 2.26.2