Hi all,
I was playing with calling a stupid fortran code in julia. I encountered some weird results.
1)Here is my fortran code to calculate “volume”.
module volmod
implicit none
contains
function volume(x,y,z) result(vol)
!DEC$ ATTRIBUTES DLLEXPORT :: volume
use, intrinsic :: iso_fortran_env, only: RK => real64
real(RK), intent(in) :: x,y,z
real(RK) :: vol
vol = x*y*z
end function volume
end module volmod
I, then, created a shared library with
ifort /dll square3.f90
I called this function in julia using
function volum(DX, DY,DZ)
product = ccall(("VOLMOD_mp_VOLUME", "C:/Users/<user>/Desktop/recycling_bin/module/square3.dll"),
Float64,
(Ref{Float32},Ref{Float32},Ref{Float32}),
DX,DY,DZ)
return product
end
rt=volum(4.0,4.0,3.0)
It returns 0. If I change the fortran code to
module volmod
implicit none
contains
function volume(x,y,z) result(vol)
!DEC$ ATTRIBUTES DLLEXPORT :: volume
use, intrinsic :: iso_fortran_env, only: RK => real64
real(RK), intent(in) :: x,y,z
real(RK) :: vol
vol = 100
end function volume
end module volmod
The julia code returns 100 as expected. Any ideas, what is wrong with the first code?
- Separate from the above issue, whenever I ccall a fortran function that requires a single input argument, I always receive the following error
LoadError: syntax: ccall argument types must be a tuple; try "(T,)" around c:\Users\<user>\Desktop\recycling_bin\module\julia\square.jl:7
“”
Basically, ccall requires me to pass at least two input arguments. Any ideas?
- Finally, although julia documentation says "
(:function, "library")
and("function", "library")
" are the same for ccall. :function does not work in my case.
----I am using Julia 1.6 on windows 10 in case it is helpful.