From: W. Trevor King Date: Mon, 20 Aug 2012 18:01:36 +0000 (-0400) Subject: Fix DynamicLabelsField parsing algorithm. X-Git-Tag: v0.3~7 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=551d9bca2f161511b1b09afdbeabff86284cb371;p=igor.git Fix DynamicLabelsField parsing algorithm. 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'], [], []] --- diff --git a/igor/binarywave.py b/igor/binarywave.py index bcccda2..6d87d14 100644 --- a/igor/binarywave.py +++ b/igor/binarywave.py @@ -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 = []