# Fortran to Julia struct

**URL:** https://discourse.julialang.org/t/fortran-to-julia-struct/79081
**Category:** New to Julia
**Tags:** question, fortran, array
**Created:** [April 6, 2022, 2:49am UTC](https://discourse.julialang.org/t/fortran-to-julia-struct/79081 "2022-04-06T02:49:26Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![james3](https://avatars.discourse-cdn.com/v4/letter/j/b5e925/32.png) [@james3](https://discourse.julialang.org/u/james3)
#### Post date: [April 6, 2022, 2:49am UTC](https://discourse.julialang.org/t/fortran-to-julia-struct/79081/1 "2022-04-06T02:49:26Z")

</div>

I’m having some difficulty calling some Fortran code from Julia. I have some Fortran code like the following

```julia
module fortranjulia
  
  use, intrinsic :: iso_c_binding
  implicit none

  type, bind(c) :: m_t
    integer(c_int) :: a1
    real(c_double) :: a2(3)
  end type m_t

contains

  subroutine print_mytype(m) bind(C, name = "print_mytype")
    type(m_t), intent(in) :: m
    print *, m%a1
    print *, m%a2
  end subroutine print_mytype

end module

```

Which I compile using `ifort -shared -lifcore -fPIC fortranjulia.f90 -o fortran_julia.so` or `gfortran -shared -fPIC fortranjulia.f90 -o fortran_julia.so`.

On the Julia side I have

```julia
using StaticArrays
using Parameters

@with_kw mutable struct m_t
    a1::Cint = 123456
    a2::MVector{3, Cdouble} = [1.0, 2.0, 3.0]
end

m = m_t()
println("Julia")
println(m.a1)
println(m.a2)
println("Fortran")
ccall((:print_mytype, "/path/to/fortran_julia"), Cvoid, (Ref{m_t},), m)

```

However, the output is mangled for the array when calling the Fortran code.

```julia
Julia
123456
[1.0, 2.0, 3.0]
Fortran
      123456
  6.914404822817115E-310 0.000000000000000E+000 6.914470367016270E-310

```

What am I do wrong with the arrays? Thanks.

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [April 6, 2022, 3:10am UTC](https://discourse.julialang.org/t/fortran-to-julia-struct/79081/2 "2022-04-06T03:10:12Z")

</div>

> [@james3](#):
>
> `MVector`

this needs to be `SVector`

or alternatively:

> [@james3](#):
>
> `a2::NTuple{3, Cdouble} = (1.0, 2.0, 3.0)`
