ratal / mdfreader

Read Measurement Data Format (MDF) versions 3.x and 4.x file formats in python
Other
169 stars 73 forks source link

ValueError: read length must be positive or -1 #167

Closed Jussi2thepowerof2 closed 4 years ago

Jussi2thepowerof2 commented 5 years ago

Python version

'3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 12:04:33) \n[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]'

Platform information

'Darwin-18.6.0-x86_64-i386-64bit'

Numpy version

'1.14.2'

mdfreader version

'3.2'

Description

Please describe the issue pr error stack here and eventually script used to use mdfreader

Hi!

I want to read an mdf file and get the following error. I have multiple mdf files which all result in the same issue.

The command is

yop = mdfreader.Mdf("Aq2_8.1_004.mdf")


ValueError Traceback (most recent call last)

in () ----> 1 yop = mdfreader.Mdf("Aq2_8.1_004.mdf") ~/anaconda3/lib/python3.6/site-packages/mdfreader/mdf.py in __init__(self, file_name, channel_list, convert_after_read, filter_channel_names, no_data_loading, compression, convert_tables, metadata) 158 no_data_loading=no_data_loading, 159 compression=compression, --> 160 metadata=metadata) 161 162 def add_channel(self, channel_name, data, master_channel, master_type=1, unit='', description='', conversion=None, ~/anaconda3/lib/python3.6/site-packages/mdfreader/mdfreader.py in read(self, file_name, multi_processed, channel_list, convert_after_read, filter_channel_names, no_data_loading, compression, metadata) 402 if not no_data_loading: 403 self.read3(self.fileName, None, multi_processed, channel_list, --> 404 convert_after_read, filter_channel_names, compression) 405 else: # populate minimum mdf structure 406 self._noDataLoading = True ~/anaconda3/lib/python3.6/site-packages/mdfreader/mdf3reader.py in read3(self, file_name, info, multi_processed, channel_list, convert_after_read, filter_channel_names, compression, metadata) 873 if info is None: 874 if self.info is None: --> 875 info = Info3(self.fileName, fid=None, filter_channel_names=False, minimal=minimal) 876 else: 877 info = self.info ~/anaconda3/lib/python3.6/site-packages/mdfreader/mdfinfo3.py in __init__(self, file_name, fid, filter_channel_names, minimal) 105 except IOError: 106 raise IOError('Can not find file ' + self.fileName) --> 107 self.read_info3(self.fid, minimal) 108 elif file_name is None and fid is not None: 109 self.read_info3(fid, minimal) ~/anaconda3/lib/python3.6/site-packages/mdfreader/mdfinfo3.py in read_info3(self, fid, minimal) 133 134 # Read text block (TXBlock) information --> 135 self['HDBlock']['TXBlock'] = read_tx_block(fid, self['HDBlock']['pointerToTXBlock']) 136 137 # Read text block (PRBlock) information ~/anaconda3/lib/python3.6/site-packages/mdfreader/mdfinfo3.py in read_tx_block(fid, pointer) 613 (block_type, 614 block_size) = tx_struct.unpack(fid.read(4)) --> 615 text = unpack('{}s'.format(block_size - 4), fid.read(block_size - 4))[0] 616 617 return text.rstrip(b'\x00').decode('latin1', 'replace') ValueError: read length must be positive or -1 Many thanks in advance!
ratal commented 4 years ago

Hi Can you put line 617 into a try: except: that displays the value for block_type, block_size and text ? Something is empty somewhere. Your mdf file is containing latin1 text or is there a chance some text uses another encoding ? (not according to mdf spec, possible with some mdf writers)

ratal commented 4 years ago

More than 6months without feedback, closing