Re: example reading binary Fortran file
Neil Martinsen-Burrell <nmb <at> wartburg.edu>
2009-02-01 21:30:52 GMT
David Froger <david.froger.info <at> gmail.com> writes:
> Hy,My question is about reading Fortran binary file (oh no this question
> again...)
I've posted this before, but I finally got it cleaned up for the Cookbook.
For this purpose I use a subclass of file that has methods for reading
unformatted Fortran data. See
http://www.scipy.org/Cookbook/FortranIO/FortranFile. I'd gladly see this in
numpy or scipy somewhere, but I'm not sure where it belongs.
> program makeArray
> implicit none
> integer,parameter:: nx=10,ny=20
> real(4),dimension(nx,ny):: ux,uy,p
> integer :: i,j
> open(11,file='uxuyp.bin',form='unformatted')
> do i = 1,nx
> do j = 1,ny
> ux(i,j) = real(i*j)
> uy(i,j) = real(i)/real(j)
> p (i,j) = real(i) + real(j)
> enddo
> enddo
> write(11) ux,uy
> write(11) p
> close(11)
> end program makeArray
(Continue reading)