Reading fortran 'unformatted' binary files 
Author Message
 Reading fortran 'unformatted' binary files

I'm sure this has been asked before, but I can't seem to find any
information on deja or on the web. How can I get python (with Numpy) to read
in arrays from a file created from a fortran code? I've looked at a package
called numpy-signaltools, but the RPM seems to be missing a number of files
(so it doesn't work). Anybody have any simple solutions?

Tony.

--

Department of Mechanical Engineering, University of Queensland, AUSTRALIA



Fri, 25 Oct 2002 03:00:00 GMT  
 Reading fortran 'unformatted' binary files
[Tony Keating]

Quote:
> I'm sure this has been asked before, but I can't seem to find any
> information on deja or on the web. How can I get python (with
> Numpy) to read in arrays from a file created from a fortran code? ...

Because Fortran files have a record structure, every Fortran implementation
invents (because it must, on any OS without native record structures, which
is almost all OSes these days) its own low-level file formats.  If you can
reverse-engineer your Fortran's format, you can build a binary file reader
out of, e.g., Python's std "struct" module.

Easier would be to write a Fortran program (using the same implementation as
was used to create the files) to read the files in and write the data out as
formatted strings.  7-bit ASCII is God's solution to portability <wink>.

can't-get-there-from-here-but-can-from-two-steps-left-ly y'rs  - tim



Fri, 25 Oct 2002 03:00:00 GMT  
 Reading fortran 'unformatted' binary files
The tim-bot thusly spake:

Quote:
>7-bit ASCII is God's solution to portability <wink>.

Amen.  Down with the eight bit.  Heed the words of the wise
prophet tim-bot.  Binary files are evil incarnate. Unicode is a
temptation created by the evil one.  Do not be lead.  Down that
dark path lies pain, anguish, and a thread on python-dev that
just won't end.

    Neil

--
"Its fun to have fun but you have to know how."  -- Dr. Seuss



Fri, 25 Oct 2002 03:00:00 GMT  
 Reading fortran 'unformatted' binary files

Quote:

> I'm sure this has been asked before, but I can't seem to find any
> information on deja or on the web. How can I get python (with Numpy) to read
> in arrays from a file created from a fortran code? I've looked at a package
> called numpy-signaltools, but the RPM seems to be missing a number of files
> (so it doesn't work). Anybody have any simple solutions?

What problems with the RPM are you having?   Are you compiling or
installing a binary?  I made the RPM and the package and have used it
successfully for many months.  There may be installation wrinkles which
have not been ironed out.

In numpy-signaltools is a class called mIO that uses numpy and the struct
module to read and write Fortran records (fortread and fortwrite methods)
directly, if the Fortran follows the common convention of starting and
ending each record with the number of bytes in the record.

Best,

Travis



Fri, 25 Oct 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Reading unformatted files 'bit a bit'

2. Reading MS-FORTRAN unformatted binary files *efficiently*

3. Reading Fortran generated unformatted binary files in tcl

4. Unformatted read's and write's

5. Unformatted read's and write's

6. Reading unformatted FORTRAN binary using C

7. Read the fortran unformatted binary data.

8. Reading any binary file as direct-access unformatted

9. Problem with R/M COBOL-85 can't read binary files

10. Binary format in Fortran UNFORMATTED files

11. Ruby code for reading unformatted Fortran files

12. Using Java to read unformatted Fortran output files?

 

 
Powered by phpBB® Forum Software