# Issue passing array to FORTRAN subroutine

**URL:** https://discourse.julialang.org/t/issue-passing-array-to-fortran-subroutine/43383
**Category:** New to Julia
**Tags:** fortran
**Created:** [July 20, 2020, 3:55pm UTC](https://discourse.julialang.org/t/issue-passing-array-to-fortran-subroutine/43383 "2020-07-20T15:55:36Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![AstroBarker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/astrobarker/32/15170_2.png) [@AstroBarker](https://discourse.julialang.org/u/AstroBarker)
#### Post date: [July 20, 2020, 3:55pm UTC](https://discourse.julialang.org/t/issue-passing-array-to-fortran-subroutine/43383/1 "2020-07-20T15:55:36Z")

</div>

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:

```julia
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:

```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.

---

<div class="post-metadata">

### Author: ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)
#### Post date: [July 20, 2020, 4:20pm UTC](https://discourse.julialang.org/t/issue-passing-array-to-fortran-subroutine/43383/2 "2020-07-20T16:20:20Z")

</div>

```julia
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

```
