From: W. Trevor King Date: Tue, 17 Jul 2012 12:59:17 +0000 (-0400) Subject: Move need_to_reorder_bytes from binarywave to util. X-Git-Tag: v0.2~37 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=f80fadab6d17098793f14f443d0a88aab648ebf8;p=igor.git Move need_to_reorder_bytes from binarywave to util. We'll be needing it for packed.load, so it's not binarywave-specific. --- 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(