From: Christian M. <mee...@un...> - 2006-11-14 11:13:59
|
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. TIA Christian |
From: Robert K. <rob...@gm...> - 2006-11-14 17:03:31
|
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 |
From: Christian M. <mee...@un...> - 2006-11-14 17:24:18
|
On Tuesday 14 November 2006 18:01, Robert Kern wrote: > > I don't believe anyone has posted anything about calling FORTRAN code using > ctypes. Why aren't you using f2py? What if we just forget about my last post? (I guess I was doing way too many things in parallel, stumbled across the g95 site and tried to apply what's posted there in the way described there ...) Sorry for this confusion and thanks, Robert, that again you brought me back on track, things are working now. Christian |
From: Hanno K. <kl...@ph...> - 2006-11-14 21:52:48
|
Hi Christian, I send this off-list as there are probably a lot more knowledgeable people around there. However, I don't entirely understand your problem (I'm not on the f2py list). What happens if you try: C file hello.f subroutine foo(a) integer a Cf2py intent(in) a print*, "Hello from Fortran!" print*, "a=",a end f2py -m -c hello hello.f That usually did the trick for me. What are your error messages, if you try the above? Best regards, Hanno On Nov 14, 2006, at 12:09 PM, 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. > > TIA > Christian > > ----------------------------------------------------------------------- > -- > Using Tomcat but need to do more? Need to support web services, > security? > Get stuff done quickly with pre-integrated technology to make your job > easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache > Geronimo > http://sel.as-us.falkag.net/sel? > cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > Numpy-discussion mailing list > Num...@li... > https://lists.sourceforge.net/lists/listinfo/numpy-discussion > -- Hanno Klemm kl...@it... ETH Zurich tel: +41-1-6332580 Institute for theoretical physics mobile: +41-79-4500428 http://www.mth.kcl.ac.uk/~klemm |