Looking for advice/experience/pitfalls on calling Julia from Fortran.
The situation:
Coupled Climate Model (Fortran coupler & Fortran ocean, ice, atmosphere, land models,…) which we’d like to be able to have the coupler call a prototype wave model written in Julia.
Hi @hkershaw, welcome to the forum. Maybe there are others here who have already done it. Otherwise I would start with the link you posted, and call those C functions from Fortran via iso_c_binding, link everything together and see.
(In the long run, I would like LFortran and other Fortran compilers to gain support for out of the box support for interoperation with other languages including Python, Julia, JavaScript, WASM, etc., automatically converting arguments, and so on.)
This shows how to create a C-compatible function pointer to a Julia function. This allows the possibly less intrusive pattern (not tried myself):
turn your Fortran main program into a main subroutine with BIND(C) attribute, accepting arguments of type C_FUNPTR corresponding to the Julia functions you want to call later
compile your Fortran code with -fPIC and create a shared library
write a Julia main script that loads your Julia modules, creates callbacks to Julia functions to be called from Fortran, loads your shared lib and calls your main Fortran subroutine with these callbacks as arguments.