Fix DynamicLabelsField parsing algorithm.
authorW. Trevor King <wking@tremily.us>
Mon, 20 Aug 2012 18:01:36 +0000 (14:01 -0400)
committerW. Trevor King <wking@tremily.us>
Mon, 20 Aug 2012 18:01:38 +0000 (14:01 -0400)
The old algorithm collapsed null bytes early on.  The new algorithm
keeps the null bytes until the 32-byte chunks have been read.

Parsing hooke/test/data/vclamp_mfp3d/Line0004Point0001.ibw with the
old algorithm gave labels as

  [[], ['RawDeflLVDT'], [], []]

The new algorithm gives

  [[], ['', 'Raw', 'Defl', 'LVDT'], [], []]

igor/binarywave.py

index bcccda2..6d87d14 100644 (file)
@@ -458,15 +458,22 @@ class DynamicLabelsField (DynamicStringField):
         wave_structure = parents[-1]
         wave_data = self._get_structure_data(parents, data, wave_structure)
         bin_header = wave_data['bin_header']
-        d = b''.join(wave_data[self.name])
+        d = wave_data[self.name]
         dim_labels = []
         start = 0
         for size in bin_header[self._size_field]:
             end = start + size
             if end > start:
                 dim_data = d[start:end]
-                # split null-delimited strings
-                labels = dim_data.split(b'\x00')
+                chunks = []
+                for i in range(size//32):
+                    chunks.append(dim_data[32*i:32*(i+1)])
+                labels = [b'']
+                for chunk in chunks:
+                    labels[-1] = labels[-1] + b''.join(chunk)
+                    if b'\x00' in chunk:
+                        labels.append(b'')
+                labels.pop(-1)
                 start = end
             else:
                 labels = []