Call fortran function from Python with ctypes

I am looking to use ctypes to call the old fortran libraries that my boss wrote several years ago. I followed the example given in this previous question and I get the results as expected.

However, when I change the code to get a little closer to the situation that I am facing,

integer function addtwo(a, b)
  integer, intent(in) :: a, b
  addtwo = a + b
end function

becomes

real function addtwo(a, b)
  integer, intent(in) :: a, b
  addtwo = a + b
end function

ie, now a function real, not a integerreturn value always 0. Can someone explain what is happening and how can I get around this?

(PS. I use the 64-bit gfortran compiler on mac os snow leopard)

EDIT: The function I'm struggling with is as follows:

real function ykr(seed)

  integer, intent(in) :: seed
  real ykr0
  ykr= real(seed)
end function

, ykr , ykr0, , , . , , ykr_(byref(c_int(4))) 0, 4, ...

+3
1

ykr_.restype = c_float

python, ykr_(byref(c_int(4))). float ( real Fortan).

, int .

+4

All Articles