From: W. Trevor King Date: Thu, 19 Jul 2012 13:56:47 +0000 (-0400) Subject: Read sIndices as uint32's in binarywave.load. X-Git-Tag: v0.2~30 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=6c2c99bb35c9bbd3fab649403029e1f46747fe02;p=igor.git Read sIndices as uint32's in binarywave.load. --- diff --git a/igor/binarywave.py b/igor/binarywave.py index 4fa5e4a..e7f1282 100644 --- a/igor/binarywave.py +++ b/igor/binarywave.py @@ -382,20 +382,29 @@ def load(filename, strict=True): labels = str(f.read(size)).split(chr(0)) # split null-delimited strings bin_info['dimLabels'].append([L for L in labels if len(L) > 0]) if wave_info['type'] == 0: # text wave - bin_info['sIndices'] = f.read(bin_info['sIndicesSize']) + sIndices_data = f.read(bin_info['sIndicesSize']) + sIndices_count = bin_info['sIndicesSize']/4 + bin_info['sIndices'] = _numpy.ndarray( + shape=(sIndices_count,), + dtype=_numpy.dtype( + _numpy.uint32()).newbyteorder(byteOrder), + buffer=sIndices_data, + order='F', + ) if wave_info['type'] == 0: # text wave # use sIndices to split data into strings strings = [] start = 0 - for i,string_index in enumerate(bin_info['sIndices']): - offset = ord(string_index) + for i,offset in enumerate(bin_info['sIndices']): if offset > start: string = data[start:offset] strings.append(''.join(chr(x) for x in string)) start = offset + elif offset == start: + strings.append('') else: - assert offset == 0, offset + raise ValueError((offset, bin_info['sIndices'])) data = _numpy.array(strings) shape = [n for n in wave_info['nDim'] if n > 0] or (0,) data.reshape(shape) diff --git a/test/test.py b/test/test.py index bf8d6de..cda1355 100644 --- a/test/test.py +++ b/test/test.py @@ -58,7 +58,7 @@ array(['Mary', 'had', 'a', 'little', 'lamb'], 'noteSize': 0, 'optionsSize1': 0, 'optionsSize2': 0, - 'sIndices': '\x00\x00\x00\x04\x00\x00\x00\x07\x00\x00\x00\x08\x00\x00\x00\x0e\x00\x00\x00\x12', + 'sIndices': array([ 4, 7, 8, 14, 18], dtype=uint32), 'sIndicesSize': 20, 'version': 5, 'wfmSize': 338} @@ -374,7 +374,7 @@ array(['Mary', 'had', 'a', 'little', 'lamb'], 'noteSize': 0, 'optionsSize1': 0, 'optionsSize2': 0, - 'sIndices': '\x04\x00\x00\x00\x07\x00\x00\x00\x08\x00\x00\x00\x0e\x00\x00\x00\x12\x00\x00\x00', + 'sIndices': array([ 4, 7, 8, 14, 18], dtype=uint32), 'sIndicesSize': 20, 'version': 5, 'wfmSize': 338}