INFO: This post is outdated! Please have a look here.
Dymola stores its simulation results in regular mat-files, but the program uses a special variable structure to store the data efficiently. An easy way to access the data is MATLAB, but I was looking for a more pythonic solution.
If you want to access the data from python you can use the function scipy.io.loadmat() from the scipy package. Some conversion is necessary get access to the data as simple time rows. The format of the result file dsres.mat is explained dymola users guide. Short version: the file contains matrices of different shape, every matrix has its own abscissa. The names of all dymola variables are stored in a special matrix. Every dymola variable name points to a column of one of the data matrices. Usually a lot of names point to the same column, possibly using a different sign (+/-).
The following python script can be imported as a module or run as a standalone script.
The first argument is the name of the mat-file. If no second argument is given, it prints the names of all variables in the file. When you provide a variable name as the second argument, the values are printed with the corresponding time values in a format that can be directly printed with gnuplot. You may need to quote the variable name for the shell in some cases.
$ python DyMat.py dsres.mat x der(x) t $ python DyMat.py dsres.mat "der(x)" # Time | der(x) 0.000000 0 200.000000 0.0597325 400.000000 0.117873 600.000000 0.172892 800.000000 0.223386 1000.000000 0.268128 ... $ python DyMat.py dsres.mat "der(x)" > tmp $ gnuplot gnuplot> plot "tmp"
The module needs more testing. I played a bit with the conversion to netCDF, XLS and CSV, but it’s not easy to transfer the space-efficient data structure to these formats. The conversion to netCDF with the same structure is trivial, but has no advantage over the original format. If you expand all variables the size of the file will explode. This needs to be checked in detail.
When I find the time I will implement a handler for pydap. A plotting tool based on PyQwt would be nice too.
OpenModelica seems to use the same file structure. After I fixed one error in the script it was able to read mat files produced with OpenModelicas OMEdit.