On Mon, 2 Feb 2009 13:39:32 +0100
 Matthieu Brucher <matthieu.bruc...@gmail.com> wrote:
Hi,

There was a discussion about this last week. You can find it int he archives ;)

Matthieu
Hi Matthieu,

Sorry but I missed that.
Anyway I have some trouble with my short example.

g77 -c binary_fortran.f
g77 -o io binary_fortran.o
./io

 11 254  254.
 12 253  126.
 13 252  84.
 14 251  62.
 15 250  50.
 16 249  41.
 17 248  35.
 18 247  30.
 19 246  27.
 20 245  24.

python -i read_fortran.py

a
array([(16, 1090921693195, 254.0), (16, 16, 5.3686493512014268e-312), (4638566878703255552, 16, 7.9050503334599447e-323), (1082331758605, 4635611391447793664, 7.9050503334599447e-323), (16, 1078036791310, 62.0), (16, 16, 5.3049894774872906e-312), (4632233691727265792, 16, 7.9050503334599447e-323), (1069446856720, 4630967054332067840, 7.9050503334599447e-323), (16, 1065151889425, 35.0), (16, 16, 5.2413296037731544e-312), (4629137466983448576, 16, 7.9050503334599447e-323), (1056561954835, 4628293042053316608, 7.9050503334599447e-323),
       (16, 1052266987540, 24.0)],
dtype=[('irow', '<i8'), ('icol', '<i8'), ('value', '<f8')])

How can I fix the problem ?

Nils
c Testing how fortran handles binary files
c
      PROGRAM binarywriter
      IMPLICIT NONE
      INTEGER X(10),Y(10), a
      DOUBLE PRECISION Z(10)
 
      OPEN(10,status='unknown',file='bin.dat',form='UNFORMATTED')
      DO a = 1, 10
         X(a)=10+a
         Y(a)=255-a
         Z(a)=Y(a)/a
         write(6,*) X(a),Y(a),Z(a)
         write(10) X(a),Y(a),Z(a)
      END DO
      
      CLOSE(10)
      END PROGRAM binarywriter
import numpy as np
fname = open("bin.dat",'rb')
dt = np.dtype([('irow',int),('icol',int),('value',float)])
a  = np.fromfile(fname,dtype=dt)

_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to