Calling Fortran variables from Julia

I don’t know of a reliable way to do this without changing the Fortran source, but this may help if you can.

If you are able to edit your source and it is practical to do so, I recommend using Fortran’s C interoperability (by declaring use iso_c_binding in the module before implicit none).

For the constants, I would write (or make the computer write if there are many such definitions needed) a wrapper function like so:

function get_hparam() bind(c)
  integer(C_INT) :: get_hparam

  get_hparam = int(hparam, C_INT)
end function get_hparam

which can be called in Julia like this:

julia> ccall((:get_hparam, "./simplemodule.so"), Cint, ())
10

For allocatable arrays, I believe you have to declare the array a pointer or target. You can then use c_loc to get a C pointer to the data. In the Fortran module:

function get_s() bind(c)
  type(c_ptr) :: get_s

  get_s = c_loc(s)
end function get_s

From Julia:

julia> ps = ccall((:get_s, "simplemodule.so"), Ptr{Cfloat}, ())
Ptr{Float32} @0x00007ff1254b8d50

julia> s = unsafe_wrap(Vector{Cfloat}, ps, 10)
10-element Array{Float32,1}:
  1.0
  2.0
  3.0
  4.0
  5.0
  6.0
  7.0
  8.0
  9.0
 10.0