[SciPy-user] Help needed: Problem in translating a file read routine from Matlab to Python-Scipy

Guasina Luca L.Guasina at barilla.it
Tue Oct 12 02:42:17 CDT 2004


I am trying to translate a Matlab program to Python - Scipy.
The task consist of reading a big data file from a FORTRAN code; the
file is written UNFORMATTED and contain a series of arrays.
Anyone can help me ? I am new user of Python and Scipy...
I am working in Windows XP with IDLE 1.02 and Python 2.3.3

See the attached files: luca.zip contain 5 files:
a test data file named luca.grm (202k)
a MATLAB program workin OK named luca.m
his output output_matlab.txt
My program in Python (NOT working) named luca.py
his output named output_python.txt .
(D:\U\work\bin is my working directory)

In the test I try to read just the first part of the file:
The first lines contain a first array of size 4 = (nx,ny,nz,ndiel); nx,
ny, nz, ndiel are the dimensions of arrays that follow.
Then I have in the file nx float that I want to read in the array x
(... And then others arrays follows ...)
In the example nx=1000, ny=10, nz=5, ndiel=12 .

The MATLAB program read correctly the first lines and nx=1000 data in
the x array 
My luca.py read nx=1000 but the statement 
x = numpyio.fread(fid,nx,'f')
only read 151 data...   I don't understand why!   ?!

You can see that in the luca.m I need to skip 2 data for every reading,
cooresponding to som FORTRAN record mark using:
 nu = fread(fid,2,'float32');  (Matlab)
I do the same in luca.py using:
 nu = numpyio.fread(fid,2,'f')

Any suggestion ?

Thanks !
Luca
-------------- next part --------------
A non-text attachment was scrubbed...
Name: luca.zip
Type: application/x-zip-compressed
Size: 8244 bytes
Desc: luca.zip
Url : http://www.scipy.net/pipermail/scipy-user/attachments/20041012/bd92f1eb/luca.bin


More information about the SciPy-user mailing list