[sapug] Problem with reading binary file (different result between MATLAB and Python)

Hani Zahiri H.Zahiri at curtin.edu.au
Sun Jan 11 13:55:06 CET 2009

Hi folks,


I am trying to translate one of my MATLAB scripts to Python and I am
experiencing a strange problem (at least to me!) and I am desperetly
looking for help. The binary file is a raw binary containing header
information (first 720 bytes) following by radar data. For better
illustration and using python basic functions, first 800 bytes of the
file is look like this:


>>> fid = open("file_name","rb")

>>> fid.read(800)

'\x00\x00\x00\x012\xc0\x12\x12\x00\x00\x02\xd0A   CEOS-SAR-CCT A A 1.00
1AL1 PSRBIMOP    FSEQ       1   4FTYP       5   4FLGT       9   4
18432 88220                          32   2   8       1   18432   0
10976   0   0   0BSQ  1 1 412   87808   0      13 4PB  49 2PB  45 4PB
21 4PB  29 4PB                                  97 4PB
COMPLEX*8                   C*8    0   0
\x00\x00\x00\x00\x00\x00*\xe0\x00\x00\x00\x00\x00\x00\x00\x00\ ...
x00\x00\x00\x1c\xae\x93\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00ix ...



And now the problem is: 

If I read the file in MATLAB, let say to find out length of header part,
I will get the correct answer:


EDU>> fid=fopen('file_name','r','b');

EDU>> fseek(fid,8,'bof');

EDU>> fread(fid,1,'uint32')


ans =




However if I read this in python I am keep getting this wrong:


>>> fid.seek(8)

>>> scipy.fromfile(fid,'uint32',1)

array([3489792000], dtype=uint32)


I have almost tried every Scipy and Numpy classes with no result. I need
a quick answer to this and I appreciate if anybody can help me with this






More information about the sapug mailing list