[Numpy-discussion] f2py: Can anyone tell me why this simple call-back example fails?
Dave Lang
dave.seattledl at gmail.com
Wed Nov 12 19:06:44 EST 2008
My system......
Ubuntu v8.0.4; Gnu gcc v4.0.3; g95 v0.92
Python v2.5.2; Numpy v1.2.1; f2py v2.5972
Hope someone can see what's wrong here?
thanks
Dave Lang
..............Here is the F90 code...........
! PROGRAM TO DEMONSTRATE PYTHON-->F90 AND F90-->PYTHON INTERFACE
SUBROUTINE CBSET(N, call_back)
!f2py intent(in) N
!f2py intent(callback) call_back
EXTERNAL call_back
INTEGER N, m
! IDENTIFY THAT FORTRAN IS EXECUTING & WHO CALLED CBSET
PRINT *,'Enter CBSET.F, N=',N
IF(N .EQ. 1) THEN
PRINT *,' in CBSET: This Call originated to test call-back'
PRINT *,' in CBSET: Make callback to PYTHON...EXPECT reply'
m=1
CALL call_back(m)
PRINT *,' in CBSET: Returned from call-back to PYTHON'
END IF
IF(N .EQ. 2) THEN
PRINT *,' in CBSET: Call came from Python to test Py->For'
END IF
RETURN
END
..............Here is the f2py created Signature code...........
! -*- f90 -*-
! Note: the context of this file is case sensitive.
python module cbset__user__routines
interface cbset_user_interface
subroutine call_back(m) ! in :foo:CBSET.F90:cbset:unknown_interface
intent(callback) call_back
integer :: m
end subroutine call_back
end interface cbset_user_interface
end python module cbset__user__routines
python module foo ! in
interface ! in :foo
subroutine cbset(n) ! in :foo:CBSET.F90
use cbset__user__routines
integer intent(in) :: n
intent(callback) call_back
external call_back
end subroutine cbset
end interface
end python module foo
! This file was auto-generated with f2py (version:2_5972).
! See http://cens.ioc.ee/projects/f2py2e/
..............Here is the Python Main Program code...........
# Main Python program to test nominal "wrap" and "call back"
import foo
def main():
print 'HELLO, pymain is about to call CBSET to test f2py operation'
print 'BUT, 1st test call_back subr from within python itself'
call_back(979)
#test "Python --> FORTRAN" (nominal wrap) from Python
print 'NOW, call CBSET to test Python --> FORTRAN wrap'
n = 2
foo.cbset(n, call_back)
#test "FORTRAN --> Python" (call-back) scheme as seen from Python
print 'NOW, call CBSET to test FORTRAN --> Python call-back'
n = 1
foo.cbset(n, call_back)
# define call-back routine
def call_back(m):
m +=20
print '..Confirming call_back, Python is entered from Fortran'
print '..in call_back: m = ', m
return
# end of call-back defn
if __name__ =='__main__':
main()
..............Here is the execution result...........
david at david-desktop:~/Pyth/ACB$ python pymain.py
HELLO, pymain is about to call CBSET to test f2py operation
BUT, 1st test call_back subr from within python itself
..Confirming call_back, Python is entered from Fortran
..in call_back: m = 999
NOW, call CBSET to test Python --> FORTRAN wrap
Enter CBSET.F, N= 2
in CBSET: Call came from Python to test Py->For
NOW, call CBSET to test FORTRAN --> Python call-back
Enter CBSET.F, N= 1
in CBSET: this Call originated to test call-back
in CBSET: Make callback to PYTHON...EXPECT reply
Segmentation fault
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20081112/1fe5bbc1/attachment.html>
More information about the NumPy-Discussion
mailing list