ratal / mdfreader

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

Issue with mdfinfo3.readCGBlock handling of duplicate channel names #117

Closed cristi-neagu closed 6 years ago

cristi-neagu commented 6 years ago

Hello,

mdfinfo3.readCGBlock handles duplicate channel names by appending the datagroup number to their name. But if the duplicates are all inside the same datagroup, this causes an error in mdf3reader.readSortedRecord when creating the recarray, due to duplicate names (Value Error: name already used as a name or title).

Unfortunately, i cannot share the mdf file that causes this issue, but i can investigate further, if needed.

ratal commented 6 years ago

Hi, Dupmicate names should happen in case of unsorted data but it should be avoided by line 223 in mdfinfo3. Something went wrong there, key 'ChannelNamesByDG' might be wrong, can you check ?

cristi-neagu commented 6 years ago

Hello,

Good call. The signal in question has a long name (41 characters). As such, signalName and self['CNBlock'][dg][cg][channel]['signalName'] are not the same, since the first contains the long name (from line 209), and the latter has the short name. In line 221 you are checking for what basically is the short name in self['ChannelNamesByDG'][dg], but with line 230 you effectively put the long name in that list. As such, the check on line 221 you will always return False. Line 224 will pick up the duplicate, will append the dg number to it, and move on. This will catch situations with two duplicates, but not situations with more than two duplicates, such as in my case.

So, basically, this is the order of events, keeping in mind that self['CNBlock'][dg][cg][channel]['signalName'] contains the short name, and signalName contains the long name:

The last 3 lines repeat for every other occurrence, leading to multiple channels with the same name, with the dg attached.

Seems like the solution is to use signalName instead of self['CNBlock'][dg][cg][channel]['signalName']

ratal commented 6 years ago

Hi, Thanks for the investigation, very clear and you are right. I corrected it I think according to your proposal in last commit, you can check it.

cristi-neagu commented 6 years ago

Hello,

Works now. No errors during file load and channels are getting the correct termination.

Thanks!