ModelicaStandardLibrary icon indicating copy to clipboard operation
ModelicaStandardLibrary copied to clipboard

Add .mat file checking

Open GarronFish opened this issue 1 month ago • 6 comments

When using Modelica.Blocks.Sources.CombiTimeTable if a -v5 .mat file is used the model can crash with: Error: The following error was detected at time: 0 InflateData: inflate returned data error

Could further details please be added to the error message, something like: Check the file being read, supported formats for .mat files are -v4, -v6 and -v7

GarronFish avatar Nov 20 '25 06:11 GarronFish

What is a -v5.mat file according to this table: https://github.com/tbeu/matio/ ?issues/154#issuecomment-694923374 ?

Can you add the MAT-file here?

beutlich avatar Nov 23 '25 19:11 beutlich

Apologies, I read the header of the .mat file and it says: MATLAB 5.0 MAT-file, Platform: PCWIN64 This actually means -v6 or -v7 format which I did not realise. Please close this ticket. I don't think I can provide a .mat file that shows this failure as the one I have contains sensitive information, and I don't want the client to have to spend a lot of time trying to create a non-sensitive data .mat file as the issue is sporadic. I think the workaround is to use the -v4 format. I think the issue is related to using int64 in the .mat file.

GarronFish avatar Nov 24 '25 06:11 GarronFish

Would be interesting how the MAT-file was created by which tool/framework/library.

Would also be interesting if MATLAB can load that MAT-file?

Generally speaking, it does not matter which version the MAT-file is, see for example this test

https://github.com/tbeu/ModelicaTableAdditions/blob/7677f73338f9aa9364e31ce9fa3e5a1d824855c5/ModelicaTableAdditions/Resources/Test/TablesFromMatFile.cc#L34-L37

beutlich avatar Nov 24 '25 18:11 beutlich

The MAT-file was created using Matlab 2024b using save and the default settings. Ulf thinks the issue is related to the int64 array. There are about 200 arrays of size 9400 by 2 elements all real except one that is an int64 array.

Then a simple model with a Modelica.Blocks.Sources.CombiTimeTable table that reads a MAT file is run on Dymola 2025x Golden.

The error that occurs is: Error: The following error was detected at time: 0 InflateData: inflate returned data error The stack of functions is: Modelica.Blocks.Types.ExternalCombiTimeTable Modelica.Blocks.Types.ExternalCombiTimeTable((if combiTimeTable.tableOnFile then combiTimeTable.tableName else "NoName"), (if combiTimeTable.tableOnFile and combiTimeTable.fileName <> "NoName" and not Modelica.Utilities.Strings.isEmpty(combiTimeTable.fileName) then combiTimeTable.fileName else "NoName"), combiTimeTable.table, combiTimeTable.startTime/combiTimeTable.timeScale, combiTimeTable.co...

GarronFish avatar Nov 24 '25 19:11 GarronFish

That error "InflateData: inflate returned data error" normally indicates some file format violation. But could be a ModelicaMatio issue if the MAT-file was created by MATLAB.

W/o the file it's hard to tell what the actual issue is.

Can you please run matdump.exe -f whos path/to/file.mat

matdump.zip

beutlich avatar Nov 24 '25 19:11 beutlich

This runs without a problem and displays information about the arrays stored in the .mat file, here is a snippet showing the int64 bit array.

Image

GarronFish avatar Nov 25 '25 09:11 GarronFish