# Support for MDF format

**URL:** <https://discourse.julialang.org/t/support-for-mdf-format/7162>\
**Category:** General Usage\
**Created:** [November 19, 2017, 1:50am UTC](https://discourse.julialang.org/t/support-for-mdf-format/7162 "2017-11-19T01:50:49Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![jayveesea](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jayveesea/32/6280_2.png) [@jayveesea](https://discourse.julialang.org/u/jayveesea)\
**Post date:** [November 19, 2017, 1:50am UTC](https://discourse.julialang.org/t/support-for-mdf-format/7162/1 "2017-11-19T01:50:49Z")

</div>

It would be great if the [MDF](https://vector.com/vi_mdf_en.html) format was supported like [HDF5](https://github.com/JuliaIO/HDF5.jl) is. Some examples are [here](https://www.mathworks.com/matlabcentral/fileexchange/9622-mdf-import-tool-and-function) for matlab and [here](https://github.com/ratal/mdfreader) ([and here](https://github.com/danielhrisca/asammdf)) for python. It’s also now [supported natively by matlab](https://www.mathworks.com/help/vnt/ug/mdf.html).

Just to be clear, I’m not referring to [this mdf file related to databases](https://en.wikipedia.org/wiki/Microsoft_SQL_Server#Data_storage).

thx for your time!

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [November 19, 2017, 10:16am UTC](https://discourse.julialang.org/t/support-for-mdf-format/7162/2 "2017-11-19T10:16:46Z")

</div>

In case you don’t know this, generally speaking your options are (1) to wait (weeks? years?) and hope an energetic volunteer adds this, (2) become that volunteer yourself, or (3) pay someone to do it. For the benefit of whoever decides to create an MDF.jl package, note that [FileIO](https://github.com/JuliaIO/FileIO.jl) is designed to handle magic byte and extension detection and dispatch.

---

<div class="post-metadata">

**Author:** ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)\
**Post date:** [November 19, 2017, 3:01pm UTC](https://discourse.julialang.org/t/support-for-mdf-format/7162/3 "2017-11-19T15:01:13Z")

</div>

There is a library ([https://vector.com/vi\_mdf4lib\_en.html](https://vector.com/vi_mdf4lib_en.html)) that provides a C++ interface.  
That might be the easiest way to add MDF support in Julia (with the help of one of the Julia C++ packages)  
It was unclear looking at the site whether the library was available for free, or there was a license fee for using it.

Another possibility in the mean-time for you might be to use the Python package from Julia, via PyCall.jl.

---

<div class="post-metadata">

**Author:** ![danielhrisca](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielhrisca/32/6208_2.png) [@danielhrisca](https://discourse.julialang.org/u/danielhrisca)\
**Post date:** [November 20, 2017, 1:58pm UTC](https://discourse.julialang.org/t/support-for-mdf-format/7162/4 "2017-11-20T13:58:04Z")

</div>

You have to pay to use Vector’s mdf4lib.

On the C++ side there are some alternatives:

- from turbolab [products](http://www.turbolab.de/products.html)
- from Tobias Lorenz (ETAS) [Bitbucket](https://bitbucket.org/tobylorenz/asam_mdf)

---

<div class="post-metadata">

**Author:** ![jayveesea](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jayveesea/32/6280_2.png) [@jayveesea](https://discourse.julialang.org/u/jayveesea)\
**Post date:** [November 21, 2017, 12:59pm UTC](https://discourse.julialang.org/t/support-for-mdf-format/7162/5 "2017-11-21T12:59:02Z")

</div>

Thx! I think I might be able to manage with one of these libraries and starting [here](https://docs.julialang.org/en/release-0.4/manual/calling-c-and-fortran-code/).

---

<div class="post-metadata">

**Author:** ![jayveesea](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jayveesea/32/6280_2.png) [@jayveesea](https://discourse.julialang.org/u/jayveesea)\
**Post date:** [November 21, 2017, 12:59pm UTC](https://discourse.julialang.org/t/support-for-mdf-format/7162/6 "2017-11-21T12:59:02Z")

</div>

Thx! I think this can get me going.

---

<div class="post-metadata">

**Author:** ![danielhrisca](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielhrisca/32/6208_2.png) [@danielhrisca](https://discourse.julialang.org/u/danielhrisca)\
**Post date:** [November 24, 2018, 3:52am UTC](https://discourse.julialang.org/t/support-for-mdf-format/7162/7 "2018-11-24T03:52:00Z")

</div>

Any progress for this topic?

---

<div class="post-metadata">

**Author:** ![jayveesea](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jayveesea/32/6280_2.png) [@jayveesea](https://discourse.julialang.org/u/jayveesea)\
**Post date:** [December 1, 2018, 1:25pm UTC](https://discourse.julialang.org/t/support-for-mdf-format/7162/8 "2018-12-01T13:25:59Z")

</div>

I have not made any progress, but I’m definetly still interested.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [December 1, 2018, 1:52pm UTC](https://discourse.julialang.org/t/support-for-mdf-format/7162/9 "2018-12-01T13:52:00Z")

</div>

In the meantime, you can use PyCall to call a Python package like mdfreader.

---

<div class="post-metadata">

**Author:** ![danielhrisca](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielhrisca/32/6208_2.png) [@danielhrisca](https://discourse.julialang.org/u/danielhrisca)\
**Post date:** [December 1, 2018, 2:00pm UTC](https://discourse.julialang.org/t/support-for-mdf-format/7162/10 "2018-12-01T14:00:03Z")

</div>

My interest is actually in comparing my Python implementation ([GitHub - danielhrisca/asammdf: Fast Python reader and editor for ASAM MDF / MF4 (Measurement Data Format) files](https://github.com/danielhrisca/asammdf)) with a julia implementation performance wise.

---

<div class="post-metadata">

**Author:** ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Post date:** [November 11, 2021, 11:35am UTC](https://discourse.julialang.org/t/support-for-mdf-format/7162/11 "2021-11-11T11:35:11Z")

</div>

This is what worked for me under MS Windows to install “asammdf” inside the miniconda environment of Julia:

```julia
ENV["PYTHON"] = raw"C:\bin\WPY64-~1\PYTHON~1.AMD\python.exe"
ENV["PYCALL_JL_RUNTIME"] = raw"C:\bin\WPY64-~1\PYTHON~1.AMD"
Pkg.build("PyCall")
import Pkg; Pkg.add("Conda")
using Conda
Conda.add("asammdf"; channel="conda-forge")

```

The environment variable ““PYCALL\_JL\_RUNTIME”” might not be necessary.  
And the a 8.3-filename format might not be necessary.

And this my trial to export MF4 → mat,v7.3:

```julia
using PyCall
asammdf = pyimport("asammdf")

mdf = asammdf.MDF(raw"C:\data\Rekorder_2020-10-19_16-20-40.MF4")
mdf.export(fmt="mat", filename=raw"C:\data\Rekorder_2020-10-19_16-20-40.mat", single_time_base=true, overwrite=true, format=7.3, oned_as="column")

```

The analogous python script is as follows:

```julia
from asammdf import MDF

mdf = MDF('C:/data/Rekorder_2020-10-19_16-20-40.MF4')
mdf.export(fmt='mat', filename='C:\data\Rekorder_2020-10-19_16-20-40.mat', single_time_base=True, overwrite=True, format=7.3, oned_as='column')

```

I have the impression that the execution is best, if I run it inside the Julia command window,  
with the include command:

```julia
include(raw"C:\data\julia\data_im_and_export\export_mf4_to_mat.jl")

```

The export can take some time (Julia v1.7rc2, Python v3.9.5).  
On my machine it is so slow that my first impression was: it is not exporting at all.

---

<div class="post-metadata">

**Author:** ![danielhrisca](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielhrisca/32/6208_2.png) [@danielhrisca](https://discourse.julialang.org/u/danielhrisca)\
**Post date:** [December 3, 2021, 7:23am UTC](https://discourse.julialang.org/t/support-for-mdf-format/7162/12 "2021-12-03T07:23:50Z")

</div>

Using `single_time_base=True` can be really slow if you have signals with different sampling rates.

It would be faster to first filter only the necessary signals, resample and then export

---

<div class="post-metadata">

**Author:** ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Post date:** [December 3, 2021, 12:48pm UTC](https://discourse.julialang.org/t/support-for-mdf-format/7162/13 "2021-12-03T12:48:15Z")

</div>

First of all: Thank you for this nice peace of software!!!  
The speed is related to the different version states of all the involved packages, even under python it took (depend on the versions installed) quite long to export and under Ubuntu 20.04 I was confronted with a memory buffer overflow).  
Now with Julia 1.7.0 I have the impression it works fine. The version that is automatically installed on  
my window machine is v5.19.16 (python is v3.9.7 from conda-forge).

---

<div class="post-metadata">

**Author:** ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Post date:** [December 16, 2021, 12:18pm UTC](https://discourse.julialang.org/t/support-for-mdf-format/7162/14 "2021-12-16T12:18:14Z")

</div>

Daniel told me how to avoid the buffer overflow, which occurs also with the newest  
version of asammdf (v7.0.1) under Python. If you also face a buffer overflow issue,  
you may add the option: `raster=0.1`
