- def _get_data_chunk(self,whichchunk):
-
- data = None
- f = open(self.filename, 'rb')
- ####################### ORDERING
- # machine format for IEEE floating point with big-endian
- # byte ordering
- # MacIgor use the Motorola big-endian 'b'
- # WinIgor use Intel little-endian 'l'
- # If the first byte in the file is non-zero, then the file is a WinIgor
- firstbyte = struct.unpack('b', f.read(1))[0]
- if firstbyte == 0:
- format = '>'
- else:
- format = '<'
- ####################### CHECK VERSION
- f.seek(0)
- version = struct.unpack(format+'h', f.read(2))[0]
- ####################### READ DATA AND ACCOMPANYING INFO
- if version == 2 or version == 3:
- # pre header
- wfmSize = struct.unpack(format+'i', f.read(4))[0] # The size of the WaveHeader2 data structure plus the wave data plus 16 bytes of padding.
- noteSize = struct.unpack(format+'i', f.read(4))[0] # The size of the note text.
- if version==3:
- formulaSize = struct.unpack(format+'i', f.read(4))[0]
- pictSize = struct.unpack(format+'i', f.read(4))[0] # Reserved. Write zero. Ignore on read.
- checksum = struct.unpack(format+'H', f.read(2))[0] # Checksum over this header and the wave header.
- # wave header
- dtype = struct.unpack(format+'h', f.read(2))[0]
- if dtype == 2:
- dtype = numpy.float32(.0).dtype
- elif dtype == 4:
- dtype = numpy.double(.0).dtype
- else:
- assert False, "Wave is of type '%i', not supported" % dtype
- dtype = dtype.newbyteorder(format)
-
- ignore = f.read(4) # 1 uint32
- bname = self._flatten(struct.unpack(format+'20c', f.read(20)))
- ignore = f.read(4) # 2 int16
- ignore = f.read(4) # 1 uint32
- dUnits = self._flatten(struct.unpack(format+'4c', f.read(4)))
- xUnits = self._flatten(struct.unpack(format+'4c', f.read(4)))
- npnts = struct.unpack(format+'i', f.read(4))[0]
- amod = struct.unpack(format+'h', f.read(2))[0]
- dx = struct.unpack(format+'d', f.read(8))[0]
- x0 = struct.unpack(format+'d', f.read(8))[0]
- ignore = f.read(4) # 2 int16
- fsValid = struct.unpack(format+'h', f.read(2))[0]
- topFullScale = struct.unpack(format+'d', f.read(8))[0]
- botFullScale = struct.unpack(format+'d', f.read(8))[0]
- ignore = f.read(16) # 16 int8
- modDate = struct.unpack(format+'I', f.read(4))[0]
- ignore = f.read(4) # 1 uint32
- # Numpy algorithm works a lot faster than struct.unpack
- data = numpy.fromfile(f, dtype, npnts)
-
- elif version == 5:
- # pre header
- checksum = struct.unpack(format+'H', f.read(2))[0] # Checksum over this header and the wave header.
- wfmSize = struct.unpack(format+'i', f.read(4))[0] # The size of the WaveHeader2 data structure plus the wave data plus 16 bytes of padding.
- formulaSize = struct.unpack(format+'i', f.read(4))[0]
- noteSize = struct.unpack(format+'i', f.read(4))[0] # The size of the note text.
- dataEUnitsSize = struct.unpack(format+'i', f.read(4))[0]
- dimEUnitsSize = struct.unpack(format+'4i', f.read(16))
- dimLabelsSize = struct.unpack(format+'4i', f.read(16))
- sIndicesSize = struct.unpack(format+'i', f.read(4))[0]
- optionSize1 = struct.unpack(format+'i', f.read(4))[0]
- optionSize2 = struct.unpack(format+'i', f.read(4))[0]
-
- # header
- ignore = f.read(4)
- CreationDate = struct.unpack(format+'I',f.read(4))[0]
- modData = struct.unpack(format+'I',f.read(4))[0]
- npnts = struct.unpack(format+'i',f.read(4))[0]
- # wave header
- dtype = struct.unpack(format+'h',f.read(2))[0]
- if dtype == 2:
- dtype = numpy.float32(.0).dtype
- elif dtype == 4:
- dtype = numpy.double(.0).dtype