1
$\begingroup$

How to link Mathematica and Fortran with WSTP?

$\endgroup$
  • 3
    $\begingroup$ Yes, it is possible, I have done that in the past, but it is tedious. Why not use the simpler approach using LibraryLink ? On which operating system do you want to do that? $\endgroup$ – Rolf Mertig Jun 7 '19 at 10:15
  • 3
    $\begingroup$ Both the LibraryLink and MathLink ( = WSTP) APIs are C language APIs. What you need to figure out is how to call C functions from Fortran. Then you can use the MathLink API from Fortran. However, it might be easier to do the reverse: learn how to call your Fortran library from C and write the glue code in C (either using MathLink, or as Rolf said, using LibraryLink). I suggest you start by learning how to do this in pure C first. Once that's done, hook up the Fortran functions. $\endgroup$ – Szabolcs Jun 7 '19 at 10:25
  • $\begingroup$ At that time I used iso_c_binding, see e.g. [this] (gcc.gnu.org/onlinedocs/gfortran/…). It is possible, but not so easy. $\endgroup$ – Rolf Mertig Jun 7 '19 at 10:41
  • $\begingroup$ @RolfMertig Related. OP insists in calling high level Mathematica functions from FORTRAN. IIRC, this is not possible with LibraryLink. $\endgroup$ – Henrik Schumacher Jun 7 '19 at 11:03
  • $\begingroup$ I am not sure why you tagged this mathematica-online. If that's what you're using, then the simple answer is that it's not possible. Please address Henrik's comment above and explain what you want to do precisely. $\endgroup$ – Szabolcs Jun 7 '19 at 11:38