ratal / mdfreader

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

How to handle cases with numberOfRecords == 0? #23

Closed kkreplin closed 8 years ago

kkreplin commented 8 years ago

Dear Aymeric,

Unfortunately, I found a corner case in some of my files, that causes an numpy core records error:

lib/python2.7/site-packages/numpy/core/records.pyc in fromfile(fd, dtype, shape, offset, formats, names, titles, aligned, byteorder)
    781     nbytesread = fd.readinto(_array.data)
    782     if nbytesread != nbytes:
--> 783         raise IOError("Didn't read as many bytes as expected")
    784     if name:
    785         fd.close()

It is triggered, when numberOfRecords == 0. In the readSortedRecord function, I'm in the case channelList is None and self.byte_aligned. Then the call return fromfile(fid, dtype=self.numpyDataRecordFormat, shape=self.numberOfRecords, names=self.dataRecordName) throws the numpy error.

Do you have a suggestion how to handle this corner case? It is a measurement, which is written to file, but no data is actually recorded.

Thanks, Katharina

ratal commented 8 years ago

Dear Katharina, You can try adding a condition in mdf4 class read4 method after if not info['DGBlock'][dataGroup]['dg_data'] == 0 add and info['CGBlock'][dataGroup][0]['cg_cycle_count'] Tell me if it solves your issue Aymeric

ratal commented 8 years ago

Dear Katharina, You can have a look in latest version, I added this additionnal condition for cycle_count in case of empty data. By the way weird because normally pointer for data block should be null and already filtered out for reading. Also merged recordchannel, invalid_bytes and canopen classes into a single class channel for simplification.

kkreplin commented 8 years ago

Dear Aymeric,

thanks, that solved the issue!

Regards, Katharina