[Numpy-discussion] example reading binary Fortran file

David Froger david.froger.info@gmail....
Thu May 28 12:48:51 CDT 2009


Sorry, I still don't understand how to use FortranFile ...

============
The fortran code
============

program writeArray

implicit none
integer,parameter:: nx=2,ny=5
real(4),dimension(nx,ny):: ux,uy,p
integer :: i,j

do i = 1,nx
do j = 1,ny
   ux(i,j) = 100.  + j+(i-1.)*10.
   uy(i,j) = 200. + j+(i-1.)*10.
   p(i,j) = 300. + j+(i-1.)*10.
enddo
enddo

open(11,file='uxuyp.bin',form='unformatted')
write(11) ux,uy
write(11) p
close(11)

end program writeArray

=============
The Python script
=============

from fortranfile import FortranFile

f = FortranFile('uxuyp.bin')

x = f.readReals()

=============
The output
=============

Traceback (most recent call last):
  File "readArray.py", line 5, in <module>
    x = f.readReals()
  File
"/home/users/redone/file2/froger/travail/codes/lib/Tests/fortranread/fortranfile.py",
line 181, in readReals
    data_str = self.readRecord()
  File
"/home/users/redone/file2/froger/travail/codes/lib/Tests/fortranread/fortranfile.py",
line 128, in readRecord
    raise IOError('Could not read enough data')
IOError: Could not read enough dat


=> How to read the file 'uxuyp.bin' ?


2009/5/28 David Froger <david.froger.info@gmail.com>

> Thank you very much :-)
>
> 2009/5/28 Neil Martinsen-Burrell <nmb@wartburg.edu>
>
>> On 2009-05-28 09:32 , David Froger wrote:
>>
>>> Hy Neil Martinsen-Burrell,
>>>
>>> I'm trying the FortranFile class,
>>> http://www.scipy.org/Cookbook/FortranIO/FortranFile
>>>
>>> It looks like there are some bug in the last revision (7):
>>>
>>>    * There are errors cause by lines 60,61,63 in
>>>
>>>    * There are indentation errors on lines 97 and 113.
>>>
>>
>> There seem to have been some problems in putting the file on the wiki
>> ("Proxy-Connection: keep-alive\nCache-Control: max-age=0" seems to come from
>> an HTML communication).  I've attached my current version of the file to
>> this email.  Let me know if you have problems with this.  I will try to get
>> the working version up on the wiki.  Peace,
>>
>> -Neil
>>
>> _______________________________________________
>> Numpy-discussion mailing list
>> Numpy-discussion@scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090528/b58db76e/attachment.html 


More information about the Numpy-discussion mailing list