Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read Modelica MATv4 files #181

Closed
wants to merge 100 commits into from
Closed

Read Modelica MATv4 files #181

wants to merge 100 commits into from

Conversation

bc0n
Copy link

@bc0n bc0n commented Feb 28, 2023

This adds support for reading v4 MAT files written by OpenModelica, according to the format detailed here. This Modelica format is not readable by either #132 or #164.

At this point I'm not exporting any of the operations into MAT.jl. As in test/runtests_modelica.jl they can be accessed directly by MAT.MAT_v4_Modelica.readAclass("matfile.mat"). The function design is very literal right now and will be condensed into all-in-one accessors at some point.

Given the size of MAT files, read operations are atomic. This differs from the MAT.jl interface, as the file pointer is never given to the user. And right now, there is now ability to write files, mostly because I have no workflow requirement for this. Also my development only included files authored by OpenModelica; Dymola appears to write a slightly different format.

Stepping back, I'd appreciate comments on the design and whether and how the operations for reading OpenModelica MATv4 files can be added to MAT.jl. I was not able to use MAT.jl's basic accessors to read these files because of the explicit v4 test.

@sjkelly
Copy link
Member

sjkelly commented Jun 7, 2023

We now have the version kwarg to the read/write functions. I am not sure of the Matlab v4 and OpenModelica v4 distinction, so if there needs to be a slight different handling, we can add it as a special case.

@qnikil7
Copy link
Contributor

qnikil7 commented Jun 7, 2023

OpenModelica v4 and Dymola v4 use Matlab v4 format, but have the variables and values stored in a particular format as mentioned by @bc0n above.

DyMat or buildingspy can read these in python.

The above work by @bc0n, reads OpenModelica v4 files, and with slight fixes reads Dymola v4 format with this.

My only concern is whether there would be some repetition in some code, as Modelica .mat is also a matalb v4 files.

Ideally (according to me) the function reading the Modelica .mat file should be using the matlab v4 read function, to return variables or values.

Practically I would love to have this functionality as it is, and and issue could be create to potentially use matread/matopen functions in the future. If this is okay, this PR could be merged as is or we can add Dymola .mat files support as well with sight fixes, as this PR.

@sjkelly
Copy link
Member

sjkelly commented Jun 8, 2023

If we can autovdetect the Matlabv4 and the Modelicav4, I think that would be great. I think this PR certainly needs two things in the interim:

  • Rebase on the latest merge for v4 support
  • Drop Dataframes (This seems like a heavy dep for this package)

Added support for Dymola .mat files, merged the latest JuliaIO repo
@bc0n
Copy link
Author

bc0n commented Jun 9, 2023

Thanks @qnikil7 et all, can you also simulate the FallingBodyBox model under Dymola2021 so that we have some coverage into the Modelica Standard Library?

sjkelly and others added 17 commits July 3, 2023 17:05
author Steve Kelly <[email protected]> 1686172667 -0400
committer Ben Conrad <[email protected]> 1688421797 -0500

parent 61648d7
author Steve Kelly <[email protected]> 1686172667 -0400
committer Ben Conrad <[email protected]> 1688421721 -0500

parent 61648d7
author Steve Kelly <[email protected]> 1686172667 -0400
committer Ben Conrad <[email protected]> 1688421288 -0500

Update make.jl
readAllVarialbes requires all data to be Vector
* initial read support

* v4 write support

* add tests for v4

* move check routine

* edit docs

* added functionality to write into v4 mat files using keyword argument

* Reset version number

* Updated readme

* Updated readme

---------

Co-authored-by: vsaase <[email protected]>
Co-authored-by: Quadras <[email protected]>
* Add documentation

* Tweak docstring

* Add urls to readme

---------

Co-authored-by: Steve Kelly <[email protected]>
author Ben Conrad <[email protected]> 1675804063 -0600
committer Ben Conrad <[email protected]> 1688437150 -0500

started reader write
@bc0n
Copy link
Author

bc0n commented Jul 4, 2023

@sjkelly the rebase was a bit rough but is much clearer now, let me know if you'd like me to open a new pr in place of this one.

src/MAT.jl Show resolved Hide resolved
.gitignore Show resolved Hide resolved
@bc0n
Copy link
Author

bc0n commented Aug 31, 2023

Looks like the _mecpy error has gone away; again let me know if there's anything I can do to get this to merge. Or if it's not a fit I'll put it elsewhere.
Thanks

@ViralBShah
Copy link
Contributor

Given the size of this commit, wouldn't it be better to have a separate package?

@bc0n
Copy link
Author

bc0n commented Aug 21, 2024

That's fine, @ViralBShah, moving to https://github.com/mechanomy/ModelicaMAT

@bc0n bc0n closed this Aug 21, 2024
@ViralBShah
Copy link
Contributor

@bc0n Thanks! If you'd like to have that package in this org (naturally with ownership permissions), please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants