# Communicating a struct to Fortran with a large array

**URL:** <https://discourse.julialang.org/t/communicating-a-struct-to-fortran-with-a-large-array/80453>\
**Category:** New to Julia\
**Tags:** question, fortran, array, staticarrays\
**Created:** [May 3, 2022, 10:28pm UTC](https://discourse.julialang.org/t/communicating-a-struct-to-fortran-with-a-large-array/80453 "2022-05-03T22:28:07Z")\
**Posts on this page:** 1\
**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:** [May 3, 2022, 10:28pm UTC](https://discourse.julialang.org/t/communicating-a-struct-to-fortran-with-a-large-array/80453/1 "2022-05-03T22:28:08Z")

</div>

What is the best practice for communicating a struct to Fortran that contains a large array object? (In practice, the struct `s_t` that I define below will also contain other elements).

I was doing something like

```julia
using StaticArrays

struct s_t
    fmat::SMatrix{n,m,Cchar,n*m}
end

```

where `n` and `m` are constants.

I then call interface with Fortran using

```julia
function test()
    sref = Ref{s_t}()
    ccall((:C_MyRoutine, /path/to/lib.so), Cvoid, (Ref{s_t},), sref)
    return sref[]
end

```

This is great when `n` and `m` are “small”, but as StaticArrays does not work well with large dimensions, this becomes painfully slow in my application.

What is the best way to communicate a struct to Fortran in this case? I can, of course, pass each argument of `s_t` to a Fortran wrapper individually (where I am now using a regular matrix rather than SMatrix), and reconstruct the derived type in Fortran by copying, but I am wondering what the “best practice” would be in these settings. Thanks.
