[SciPy-user] Reading Binary Files

George Nurser gnurser@googlemail....
Thu Mar 8 13:58:25 CST 2007

This short routine might be useful it gets rid of the extra stuff at
the beginning and end that fortran adds. But I can't guarantee it will
work for you.

use swap=True if you are reading little-endian on big
endian/big-endian on little endian.
f8=false if you are using real*4 instead of real*8 ( double precision)

You also need to put somewhere:
from numpy import *

def readbin(file_in,swap=False,f8=True):
    if f8:
        htot =fromfile(file = file_in ,dtype=Float)
        c = htot.view(single)
        hc = c[1:-1].view(double)
        htot =fromfile(file = file_in ,dtype=Float32)
        hc = c[1:-1]

    if swap:
        hc = hc.byteswap()
    return hc

More information about the SciPy-user mailing list