[Tutor] reading Fortran unformatted files with Python

Gabriele Brambilla gb.gabrielebrambilla at gmail.com
Mon Jul 13 20:08:41 CEST 2015


The second method seem to work.
But how can I know which dtype in Python corresponds to REAL in fortran?

Thanks



On Mon, Jul 13, 2015 at 11:29 AM, Laura Creighton <lac at openend.se> wrote:

> In a message of Mon, 13 Jul 2015 11:14:36 -0400, Gabriele Brambilla writes:
> >Hi,
> >
> >I have problems reading unformatted fortran output (binary) with python.
> >
> >I have a code in fortran where I write data on a file inside a cycle:
> >
> >write(11) x,y,z,BA01(i,j,k,1),BA01(i,j,k,2),1
> >BB01(i,j,k,1),BB01(i,j,k,2),2           BE01(i,j,k,1),3
> >EC01(i,j,k,1),EC01(i,j,k,2),4           ED01(i,j,k,1),ED01(i,j,k,2),5
> >         EF01(i,j,k,1),6           rGH01(i,j,k,1),rGH01(i,j,k,2),7
> >      rGI01(i,j,k,1),rGI01(i,j,k,2),8           rGJ01(i,j,k,1),1
> >    rGL(i,j,k,2),rGM(i,j,k,2),rGN(i,j,k,2)
> >
> >How can I read this 21 real line by line in Python? How can I decode this
> >unit specifier 11? All the numbers are defined as REAL.
> >
> >thanks
> >
> >Gabriele
> >_______________________________________________
> >Tutor maillist  -  Tutor at python.org
> >To unsubscribe or change subscription options:
> >https://mail.python.org/mailman/listinfo/tutor
>
> You want to use this package:
> https://pypi.python.org/pypi/fortranfile
>
> You need to also load numpy for this to work.
>
> Some people cannot get this to work, and like this way of doing
> things better:
>
> https://physics.ucf.edu/~dle/blog.php?id=1
>
> Again, needs numpy.  Write back if you need a numpy-free solution (i.e.
> you are on Jython).
>
> Laura
>


More information about the Tutor mailing list