Read sIndices as uint32's in binarywave.load.
authorW. Trevor King <wking@tremily.us>
Thu, 19 Jul 2012 13:56:47 +0000 (09:56 -0400)
committerW. Trevor King <wking@tremily.us>
Thu, 19 Jul 2012 14:51:02 +0000 (10:51 -0400)
igor/binarywave.py
test/test.py

index 4fa5e4a68a276eec0a3ed6a2bcd3b5743f4c20ae..e7f1282989650fffbe36fe8bde139a52b6e1daaa 100644 (file)
@@ -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)
index bf8d6deab26a9509f9cdb642e399637d073f6826..cda1355813b3aea051d1801ef08eb35cea193250 100644 (file)
@@ -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}