Hello, everyone in the Julia discourse community, this is my first post here and I’m having a problem with calling Fortran in Julia.
The Fortran code I’m calling can be downloaded here, which is a scientific code.
What I changed is to add this function to the file adj8632_Code_S1.f90:
real*8 function pot_H2CO_V23(R, th1, th2, phi, rh2, rco)
implicit none
real*8,intent(in) :: R, th1, th2, phi, rh2, rco
real*8 :: eint
call pot_H2CO6D_V23(R, th1, th2, phi, rh2, rco, eint)
pot_H2CO_V23 = eint
return
end function pot_H2CO_V23
which is what I will be calling from Julia.
Then I compiled adj8632_Code_S1.f90 with
ifort -shared -fPIC adj8632_Code_S1.f90 -o adj8632_Code_S1.so
, and then called from Julia:
function h2copes(R, θ1, θ2, ϕ, rh2, rco)
eint = @ccall "path to library".:pot_h2co_v23_(R::Ref{Float64}, θ1::Ref{Float64}, θ2::Ref{Float64}, ϕ::Ref{Float64}, rh2::Ref{Float64}, rco::Ref{Float64})::Float64
return eint
end
h2copes(8., 0., 180., 0., 1.474, 2.165)
now no matter what my input is, it always returns 0.0
. And I don’t know what’s wrong.
I have used this approach with other Fortran codes, no problem has occured.