Import OVF 2.0 Vector field files

I'm using a simulation software (mumax3) which outputs OVF_2.0 files. It can either export binary or text files. The binary files are usually much smaller than the text files. I would like to use the binary option, and I am looking for a way to import them in Mathematica.

• Yeah!!! mumax3 what’s up!! Hah! Have you seen ovf2mathematica.go? – CA Trevillian Aug 4 '20 at 18:55
• Walter, have you seen the new functionality to output a numpy array? I’ll try to write something for maybe like a dataset here or something, but I wonder if you can instead use the external evaluate functionality to import it as a numpy array? – CA Trevillian Sep 3 '20 at 22:32
• @CATrevillian that ovf2mathematica.go is great! I am not sure what output you are talking about? I did not see a new, documented, feature in mumax that allows writing HDF5 files or anything else regarding numpy arrays in mumax. I vaguely remember someone talking about this though.... – Walter Lars Lee Sep 9 '20 at 21:07
• I’m not sure about hdf5, but mentioned in the new release notes is that mumax3-convert can take the ovf files and convert them to numpy arrays, among other useful formats. – CA Trevillian Sep 9 '20 at 21:59
• That is really helpful! – Walter Lars Lee Sep 10 '20 at 7:17

Here is one way to do it, but you have to figure out the size of the header and footer beforehand.

SetDirectory[NotebookDirectory[]];

(*the header in this file is 479 bytes*)
import = Import["m000000.ovf", {"Binary", "Real32"},"HeaderBytes" -> (479)];

(*the footer in this file is 40 bytes. With 4 bytes (32bit) per number, this is the last 10 entries in "import"*)

data = import[[2 ;; -10]];


The lengths of header and footer can be found by importing the data in a different way:

In[1]:=
SetDirectory[NotebookDirectory[]];
import = Import["m000000.ovf", "Binary"];

In[3]:=
FromCharacterCode[import[[1 ;; 10]]]
FromCharacterCode[import[[1 ;; 20]]]
(*Look at footer*)
FromCharacterCode[import[[-10 ;; -1]]]
FromCharacterCode[import[[-20 ;; -1]]]

Out[3]=
"# OOMMF OV"

Out[4]=
"# OOMMF OVF 2.0
# Se"

Out[5]=
": Segment
"

Out[6]=
"ry 4
# End: Segment
"


By varying the part of the imported file (1;;10, 1;;20, ... 1;;479) that is converted to character code, you can find the lengths manually. Surely there is a better way to do this. Preferably one that does not require importing the file twice.