ratal / mdfreader

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

MDF3: Conversion is lost after write #43

Closed johp1029 closed 7 years ago

johp1029 commented 7 years ago

Hi,

a co-worker of mine is using this library to open a MDF3 file, change some values and write it back to a file. He noticed, that textual conversions get lost after writing the file. Steps to reproduce:

The output looks like this:

OpenFile, Print Channel:
 {   'conversion': {   'parameters': {   0: {   'Textrange': '',
                                                'lowerRange': 0.0,
                                                'pointerToTXBlock': 0,
                                                'upperRange': 0.0},
                                         1: {   'Textrange': 'Vorwaerts',
                                                'lowerRange': 0.0,
                                                'pointerToTXBlock': 115816,
                                                'upperRange': 0.0},
                                         2: {   'Textrange': 'Rueckwaerts',
                                                'lowerRange': 1.0,
                                                'pointerToTXBlock': 115830,
                                                'upperRange': 1.0},
                                         3: {   'Textrange': 'Init',
                                                'lowerRange': 2.0,
                                                'pointerToTXBlock': 115846,
                                                'upperRange': 2.0},
                                         4: {   'Textrange': 'ungueltig_oder_nicht_verbaut',
                                                'lowerRange': 3.0,
                                                'pointerToTXBlock': 115855,
                                                'upperRange': 3.0}},
                       'type': 12},
     'data': array([0, ..., 3], dtype=uint8),
     'description': 'Drehrichtung Rad HL',
     'master': 't_27',
     'masterType': 1,
     'unit': ''}

 Save File

 Open New File, Print Channel:
 {   'conversion': {   'parameters': {   }, 'type': 65535},
     'data': array(['V', ..., 'u'], dtype='|S1'),
     'description': 'Drehrichtung Rad HL',
     'master': 't_27',
     'masterType': 1,
     'unit': ''}

Before writing, the channel contains a textual conversion and the data array contains numerical values.

After writing and reopening the file the conversion is lost and the data array contains only the first letter of the String representation.

Debugging showed that data is correct until this line is executed (in mdf3reader.py): fid.write(pack('<' + dataTypeList * nRecords, *records)) # dumps data vector from numpy

Regards, Johannes

ratal commented 7 years ago

It could be textual conversion function testRangeTableConv bug or in the write3 function. Coud you please do after open file ?: mdfreaderInstance.getChannelData(channelName) to have a look at the array and check if it is already ['V', ..., 'u']

ratal commented 7 years ago

I have found the bug in write3. The numberOfBits considered was not correct in case of string array. Give a try to latest commit

johp1029 commented 7 years ago

Ok, the latest commit solves our problem. Thank you!