accessing FORTRAN from Python

Robert Kern robert.kern at gmail.com
Tue Nov 14 11:01:09 CST 2006


Christian Meesters wrote:
> Hoi,
> 
> thanks to Robert Kern who helped me out yesterday on the f2py-list, I was able 
> to make some progress in accessing FORTRAN from Python. But only some 
> progress ...
> 
> If I have the following code, named 'hello.f':
> C File hello.f
>       subroutine foo (a)
>       integer a
>       print*, "Hello from Fortran!"
>       print*, "a=",a
>       end
> 
> and compile it with g77 -shared -fPIC hello.f -o hello.so
> 
> and then start python, I get the following:
>>>> from numpy import *
>>>> from ctypes import c_int,  POINTER, byref
>>>> hellolib = ctypeslib.load_library('hello', '.')
>>>> hello = hellolib.foo_
>>>> hello(42)
>  Hello from Fortran!
> Segmentation fault
> 
> Can anybody tell me where my mistake is? (Currently python 2.4.1 (no intention 
> to update soon), the most recent ctypes, and numpy '1.0.dev3341' from svn.)
> 
> And a second question: Are there simple examples around which show how to pass 
> and retrieve lists, numpy arrays, and dicts to and from FORTRAN? Despite an 
> intensive web search I couldn't find anything.

I don't believe anyone has posted anything about calling FORTRAN code using
ctypes. Why aren't you using f2py?

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco


-------------------------------------------------------------------------
SF.net email is sponsored by: A Better Job is Waiting for You - Find it Now.
Check out Slashdot's new job board. Browse through tons of technical jobs
posted by companies looking to hire people just like you.
http://jobs.slashdot.org/




More information about the Numpy-discussion mailing list