Skip to content

Instantly share code, notes, and snippets.

@zzj99
Created May 28, 2016 13:51
Show Gist options
  • Save zzj99/3fad6f29eb00ee6274a96a351c5aa018 to your computer and use it in GitHub Desktop.
Save zzj99/3fad6f29eb00ee6274a96a351c5aa018 to your computer and use it in GitHub Desktop.
read unformatted / binary fortran file with python
program test
integer :: i
open(1, file='test.dat', access='stream', form='unformatted')
do i = 1, 10
write(1) i
write(1) dble(i)**2
end do
close(1)
end program test
import numpy as np
f = open('test.dat', 'rb')
dt = np.dtype("i4,f8")
x = np.fromfile( f, dtype=dt, count=-1 )
f.close()
print x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment