Created
May 28, 2016 13:51
-
-
Save zzj99/3fad6f29eb00ee6274a96a351c5aa018 to your computer and use it in GitHub Desktop.
read unformatted / binary fortran file with python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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