Reading Fortran Data

Eric_Dexter at msn.com Eric_Dexter at msn.com
Sun Jan 21 18:08:33 EST 2007


I don't know if this is helpfull or not but (or for that matter
current).  http://cens.ioc.ee/projects/f2py2e/ offers some suggestions
and it looks like you can use it with c code also.


Tyler wrote:
> Hello All:
>
> After trying to find an open source alternative to Matlab (or IDL), I
> am currently getting acquainted with Python and, in particular SciPy,
> NumPy, and Matplotlib. While I await the delivery of Travis Oliphant's
> NumPy manual, I have a quick question (hopefully) regarding how to read
> in Fortran written data.
>
> The data files are not binary, but ASCII text files with no formatting
> and mixed data types (strings, integers, floats). For example, I have
> the following write statements in my Fortran code:
>
> I write the files as such:
>   WRITE(90,'(A30)') fgeo_name
>   WRITE(90,'(A30)') fmed_name
>   WRITE(90,*) nfault,npoint
>   WRITE(90,*) (xpt(n), n=1,npoint)
>   WRITE(90,*) (ypt(n), n=1,npoint)
>
> and,
>
>   WRITE(10,'(A30)') fname
>   DO i=1,nfault
>      WRITE(10,*) dbn(i),dtn(i),xfwnt(i),yfwnt(i),xfent(i),yfent(i),&
>           &        slpvlS(i),slpvlD(i),slpvlT(i),segdp1(i)
>   END DO
>
>
> I then respectively read them into Fortran as:
>   READ(70,'(A30)') fgeo_name
>   READ(70,'(A30)') fmed_name
>   READ(70,*) nfault,npoint
>   READ(70,*) (x(n), n=1,npoint)
>   READ(70,*) (y(n), n=1,npoint)
>
> and,
>
>   READ(20,'(A30)') fname
>   DO i=1,nfault
>      READ(20,*) dbn(i),dtn(i),xfwnt(i),yfwnt(i),xfent(i),yfent(i),&
>           &        slpvlS(i),slpvlD(i),slpvlT(i),segdp1(i)
>   END DO
>
> I also read them into IDL for visualization using the "READF" command.
> I was wondering how I might go about reading this into Python using
> NumPy. If this is not trivial, let me know and I'll just wait until the
> NumPy manual arrives.
> 
> Cheers,
> 
> t.




More information about the Python-list mailing list