danielhrisca / asammdf

Fast Python reader and editor for ASAM MDF / MF4 (Measurement Data Format) files
GNU Lesser General Public License v3.0
611 stars 216 forks source link

UnboundLocalError: local variable 'record_size' referenced before assignment #1034

Closed NageshKumarGowda closed 2 weeks ago

NageshKumarGowda commented 3 weeks ago

Python version

Please run the following snippet and write the output here

import platform
import sys
from pprint import pprint

pprint("python=" + sys.version)
pprint("os=" + platform.platform())

try:
    import numpy
    pprint("numpy=" + numpy.__version__)
except ImportError:
    pass

try:
    import asammdf
    pprint("asammdf=" + asammdf.__version__)
except ImportError:
    pass

Code

('python=3.10.0 (tags/v3.10.0:b494f59, Oct 4 2021, 19:00:18) [MSC v.1929 64 ' 'bit (AMD64)]') 'os=Windows-10-10.0.19045-SP0' 'numpy=1.26.4'

MDF version

MDF; 4.11

Code snippet

from asammdf import MDF, Signal data = MDF(r'D:\Docker\BW27\2024-04-23_12-39-24_2024-04-23_12-39-31_556495_9T56155_FRR_DEBUG_0000.MF4')

Traceback

File "D:\Docker\ARS540DP14_reprocessing_system\test.py", line 22, in data = MDF(r'D:\Docker\BW27\2024-04-23_12-39-24_2024-04-23_12-39-31_556495_9T56155_FRR_DEBUG_0000.MF4') File "C:\LegacyApp\Python\Python39\lib\site-packages\asammdf\mdf.py", line 350, in init self._mdf = MDF4(name, channels=channels, **kwargs) File "C:\LegacyApp\Python\Python39\lib\site-packages\asammdf\blocks\mdf_v4.py", line 402, in init self._read(mapped=True, progress=progress) File "C:\LegacyApp\Python\Python39\lib\site-packages\asammdf\blocks\mdf_v4.py", line 669, in _read record_size=record_size, UnboundLocalError: local variable 'record_size' referenced before assignment

Description

This is a small bug in asammdf\blocks\mdf_v4.py, we should initialize the record_size to 0 in case the MDF is reading an empty mf4 files or else we will get the error mentioned in traceback

This can be easily fixed by adding a line shown below

image

NageshKumarGowda commented 3 weeks ago

2024-04-23_12-39-24_2024-04-23_12-39-31_556495_9T56155_FRR_DEBUG_0000.zip attaching the file for your referrence

NageshKumarGowda commented 2 weeks ago

Resolved in the PR https://github.com/danielhrisca/asammdf/pull/1036