[Matrix-SIG] Interfaces to some common FORTRAN routines.
Paul F. Dubois
dubois1@llnl.gov
Tue, 13 Apr 1999 15:38:34 -0700
I don't normally preannounce products but since you ask, I am nearing
completion on a Python module called PyFort. PyFort translates an input
format which is highly similar to F90 interface blocks into Python module
glue. Although I know others have tools that use SWIG, my feeling was the
Fortran programmers need something that is more or less in their language
and which at least has the potential to someday handle real F90 interfaces.
PyFort is, of course, being written in 100% Pure Python.
Here is the input to my test routine, for example:
! Sample interface description file for Python/Fortran connection tool.
! Paul F. Dubois dubois1@llnl.gov
! More than one module is allowed, this file just has one.
module testpyf
! testpyf contains doit, times, and bang and others
function doit(x)
! y = doit(x) returns y = x**2
! x must be a Python float.
doubleprecision x !scalar float
doubleprecision doit !returns scalar float
end
subroutine times(x, y, n, w)
! times(x, y, n, w) sets w(i) = x(i) * y(i), i = 1, n
doubleprecision, intent(in):: x(n), y(n) ! must have size n
doubleprecision, intent(out):: w(n)
integer n
end subroutine
subroutine ctimes(x, y, n, w)
!for complex x, y, w, ctimes(x, y, n, w) sets w(i) = x(i) * y(i), i =
1, n
complex, intent(in):: x(n), y(n) ! must have size n
complex, intent(out):: w(n)
integer n
end subroutine
function bang( r, ra, n, k, c, t)
integer n, k
complex c(2)
real r, ra(n), bang
real, intent(temporary):: t(n, k)
end function bang
function two (a, n, m, k, b, c)
real two
integer n, m, k
real a(n, m), b(m, k)
real, intent(out):: c(n, k)
end function two
subroutine noreturn ()
end subroutine noreturn
function sarg (s, x)
! sarg(s) if s is 'yes', will return 1, otherwise 0
integer, intent(out):: sarg, x(1)
character*(*) s
end subroutine sarg
end module testpyf
! Comments here are ignored
--- ok, that is the input.
The comments immediately after the subroutine signature are called "head
comments". Head comments become the doc string. A separate file is printed
giving the python calling sequence, as shown below. Right now this is for me
to use to debug pyfort, but cleaned up a little it will serve users as
documentation on how they call various routines. I haven't thought about
routines with arguments that are externals, although that would obviously be
a good thing. The rules are pretty simple. The outputs are the routine
result if any followed by any of the Fortran arguments that had intent out
or inout. If there is <= 1 output that is the result, otherwise you get a
tuple. The special intent "temporary" is used for "work arrays" so the
Python user need not create them a priori.
------------
Procedures in module testpyf
----------- doit ------------
y = doit(x) returns y = x**2
x must be a Python float.
Calling sequence: result = doit(x)
doubleprecision, intent(out):: doit ()
doubleprecision, intent(in):: x ()
----------- times ------------
times(x, y, n, w) sets w(i) = x(i) * y(i), i = 1, n
Calling sequence: w = times(x, y, n)
doubleprecision, intent(in):: x (n)
doubleprecision, intent(in):: y (n)
integer, intent(in):: n ()
doubleprecision, intent(out):: w (n)
----------- ctimes ------------
for complex x, y, w, ctimes(x, y, n, w) sets w(i) = x(i) * y(i), i = 1, n
Calling sequence: w = ctimes(x, y, n)
complex, intent(in):: x (n)
complex, intent(in):: y (n)
integer, intent(in):: n ()
complex, intent(out):: w (n)
----------- bang ------------
Calling sequence: result = bang(r, ra, n, k, c)
real, intent(out):: bang ()
real, intent(in):: r ()
real, intent(in):: ra (n)
integer, intent(in):: n ()
integer, intent(in):: k ()
complex, intent(in):: c (2)
real, intent(temporary):: t (n, k)
----------- two ------------
Calling sequence: result, c = two(a, n, m, k, b)
real, intent(out):: two ()
real, intent(in):: a (n, m)
integer, intent(in):: n ()
integer, intent(in):: m ()
integer, intent(in):: k ()
real, intent(in):: b (m, k)
real, intent(out):: c (n, k)
----------- noreturn ------------
Calling sequence: noreturn()
----------- sarg ------------
sarg(s) if s is 'yes', will return 1, otherwise 0
Calling sequence: result, x = sarg(s)
integer, intent(out):: sarg ()
character*(*), intent(in):: s ()
integer, intent(out):: x (1)
-----Original Message-----
From: Travis Oliphant <Oliphant.Travis@mayo.edu>
To: matrix-sig@python.org <matrix-sig@python.org>
Date: Tuesday, April 13, 1999 2:51 PM
Subject: [Matrix-SIG] Interfaces to some common FORTRAN routines.
>
>I'm making available my interface to the FORTRAN package MINPACK at
>http://oliphant.netpedia.net
>under the name package called multipack-0.3
>
>There is a Linux i386 binary and a Source RPM package along with a
>tarball. You need a fortran compiler to compile the code. That's the
>cleanest way to do it on my system. Calling fortran from C can be system
>dependent and I assume the underscore convention.
>
>My plan is to include ODEPACK, QUADPACK, and others in this module. I'm
>currently working on putting QUADPACK and ODEPACK in. If anyone has
>experience with these routines and can offer suggestions as to how you
>would like to interface with them, I'd love to hear about it.
>
>This list seems to have quieted down a bit with regard to getting some
>of these codes into Numerical Python. Has interest in using
>Numerical Python subsided, is everyone just happy with where things stand,
>or just busy doing work with it?
>
>Comments and suggestions welcome,
>
>
>
>--------------------------------------------------
>Travis Oliphant 200 First St SW
> Rochester MN 55905
>Ultrasound Research Lab (507) 286-5293
>Mayo Graduate School Oliphant.Travis@mayo.edu
>
>
>_______________________________________________
>Matrix-SIG maillist - Matrix-SIG@python.org
>http://www.python.org/mailman/listinfo/matrix-sig
>
>