Hi,
When I tried the following Fortran routine (abc.f), it worked using the following shared file and ccall.
But when I tried after changing DOUBLE PRECISION with REAL, it did not work. How should it be fixed.
This is what I saw on the Internet and worked:
abc.f file I saw on the Internet
SUBROUTINE MULTIPLY(A,B,C)
DOUBLE PRECISION A,B,C
C = A*B
RETURN
END
gfortran abc.f -o abc.so -shared -fPIC
a = 2.0
b = 4.2
n = Float64[1.0]
ccall((:multiply_, "abc.so"), Void, (Ptr{Float64},Ptr{Float64},Ptr{Float64}),&a,&b, n)
julia> n
1-element Array{Float64,1}:
8.4
Again ccall worked with DOUBLE PRECISION.
When I used REAL like the following:
SUBROUTINE MULTIPLY(A,B,C)
DOUBLE PRECISION A,B,C
C = A*B
RETURN
END
and used the same procedure like
gfortran abc.f -o abc.so -shared -fPIC
a = 2.0
b = 4.2
julia> n = Array(Float64)
0-dimensional Array{Float64,0}:
0.0
julia> ccall((:multiply_, "abc.so"), Void, (Ptr{Float64},Ptr{Float64},Ptr{Float64}), &a, &b, n)
julia> n
0-dimensional Array{Float64,0}:
1.061e-314
The default value of 0.0 changed to 1.061e-314, which is not the correct answer.
When I assigned a specific number to n:
julia> n = Float64[1.0]
1-element Array{Float64,1}:
1.0
julia> ccall((:multiply_, "abc.so"), Void, (Ptr{Float64},Ptr{Float64},Ptr{Float64}), &a, &b, n)
Then the array element value was not changed.
julia> n
1-element Array{Float64,1}:
1.0
I am wondering why it does not work with REAL variables.
I tried Logical, Int, and Character variables, along with Double Precision.
All worked, except for REAL.
Thanks,