1
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ Yeah!!! mumax3 what’s up!! Hah! Have you seen ovf2mathematica.go? $\endgroup$ – CA Trevillian Aug 4 at 18:55
  • $\begingroup$ 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? $\endgroup$ – CA Trevillian Sep 3 at 22:32
  • $\begingroup$ @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.... $\endgroup$ – Walter Lars Lee Sep 9 at 21:07
  • 1
    $\begingroup$ 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. $\endgroup$ – CA Trevillian Sep 9 at 21:59
  • $\begingroup$ That is really helpful! $\endgroup$ – Walter Lars Lee Sep 10 at 7:17
0
$\begingroup$

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]:= 
(*Look at header*)
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.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.