Issue passing array to FORTRAN subroutine

I’m trying to use Julia to wrap a FORTRAN subroutine taking several arrays as arguments. The issue is that the subroutine receives garbage as the array values (1e-314 etc), so I must be defining something wrong for the ccall. I’ve attached a minimal FORTRAN and Julia combo that reproduces my issue.

FORTRAN:

SUBROUTINE ADD(x, y)

    real*8, INTENT(in)  :: x(2)
    real*8, INTENT(out) :: y(2)

    y(1) = x(1) + 1
    y(2) = x(2) + 2

    write(*,*) x
    write(*,*) y
    
END SUBROUTINE ADD

Julia:

x = [1.0, 2.0]
y = [0.0, 0.0]

ccall( (:add_, "./test.so"), Nothing, (Ref{Array{Float64,1}}, Ref{Array{Float64,1}}), Ref(x), y )

When the FORTRAN routine writes x it gets something like 2.2435970063560449E-314 9.8813129168249309E-324.

Any thoughts or suggestions would be helpful.

julia> x = [1.0, 2.0]
2-element Array{Float64,1}:
 1.0
 2.0

julia> y = [0.0, 0.0]
2-element Array{Float64,1}:
 0.0
 0.0

julia> ccall( (:add_, "./test.so"), Cvoid, (Ref{Float64}, Ref{Float64}), x, y )
   1.0000000000000000        2.0000000000000000     
   2.0000000000000000        4.0000000000000000     

julia> x
2-element Array{Float64,1}:
 1.0
 2.0

julia> y
2-element Array{Float64,1}:
 2.0
 4.0
2 Likes