combining python with fortran, trouble with tutorial -
i'm following tutorial http://www.sam.math.ethz.ch/~raoulb/teaching/pythontutorial/combining.html
i use same code
program hwtest real*8 r1, r2 ,s r1 = 1.0 r2 = 0.0 s = hw1(r1, r2) write(*,*) 'hw1, result:',s write(*,*) 'hw2, result:' call hw2(r1, r2) call hw3(r1, r2, s) write(*,*) 'hw3, result:', s end real*8 function hw1(r1, r2) real*8 r1, r2 hw1 = sin(r1 + r2) return end subroutine hw2(r1, r2) real*8 r1, r2, s s = sin(r1 + r2) write(*,1000) 'hello, world! sin(',r1+r2,')=',s 1000 format(a,f6.3,a,f8.6) return end c special version of hw1 result c returned argument: subroutine hw3_v1(r1, r2, s) real*8 r1, r2, s s = sin(r1 + r2) return end c f2py treats s input arg. in hw3_v1; fix this: subroutine hw3(r1, r2, s) real*8 r1, r2, s cf2py intent(out) s s = sin(r1 + r2) return end c test case sensitivity: subroutine hw4(r1, r2, s) real*8 r1, r2, s cf2py intent(out) s s = sin(r1 + r2) return end c end of f77 file
but when use command
f2py -m hw -c ../hw.f
i following error:
gfortran:f77: ../hw.f ../hw.f:5.13: s = hw1(r1, r2) 1 error: return type mismatch of function 'hw1' @ (1) (real(4)/real(8)) ../hw.f:5.13: s = hw1(r1, r2) 1 error: return type mismatch of function 'hw1' @ (1) (real(4)/real(8)) error: command "/usr/bin/gfortran -wall -ffixed-form -fno-second-underscore -fpic -o3 -funroll-loops -i/tmp/tmprghzqj/src.linux-x86_64-2.7 -i/usr/lib/python2.7/dist-packages/numpy/core/include -i/usr/include/python2.7 -c -c ../hw.f -o /tmp/tmprghzqj/fortran/hw.o" failed exit status 1
i have no experience fortran, need implement existing fortran code use in python.
the interface hw1
missing in code. either specify explicitly:
program hwtest real*8 r1, r2 ,s real*8 hw1 c [...]
or, better, put functions module, , use
module.
btw: change *8
better suited, like:
program hwtest integer,parameter :: dp = kind(1.d0) real(dp) r1, r2 ,s real(dp) hw1
or, use iso_fortran_env
, , pre-defined parameters real64
, real32
.
Comments
Post a Comment