[Tutor] Running and passing variables to/from Fortran

Alan Gauld alan.gauld at btinternet.com
Tue May 8 15:55:11 CEST 2007


"John Washakie" <washakie at gmail.com> wrote

>I have a FORTRAN program which reads in unformatted sparse matrix
> data. Rather than rewriting the code in Python, I was hoping there 
> is
> a way to call the Fortran program, passing filename variables TO
> Fortran, and returning the data (which is an array) back to my .py
> code for use there.

It depends on whether your Fortran code reads the variables from
stdin (or on the command line) and spits out the result to stdout.
If it does (or can be modified to do so on demand) then its an easy
job using subprocess.Popen.

If you actually need to communicate at the variable level its
more difficult(!). If you cannot change the Fortran code at all
or only have the binary version then its more difficult still!

If you can change the Fortran then you can simply use files to
communicate between them...

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list