Commit 6c2c99bb authored by W. Trevor King's avatar W. Trevor King
Browse files

Read sIndices as uint32's in binarywave.load.

parent 309967f6
......@@ -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)
......
......@@ -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}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment