1

How to link Mathematica and Fortran with WSTP?

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
  • 3
    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? – Rolf Mertig Jun 07 '19 at 10:15
  • 3
    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. – Szabolcs Jun 07 '19 at 10:25
  • At that time I used iso_c_binding, see e.g. [this] (https://gcc.gnu.org/onlinedocs/gfortran/Interoperable-Subroutines-and-Functions.html). It is possible, but not so easy. – Rolf Mertig Jun 07 '19 at 10:41
  • @RolfMertig Related. OP insists in calling high level Mathematica functions from FORTRAN. IIRC, this is not possible with LibraryLink. – Henrik Schumacher Jun 07 '19 at 11:03
  • 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. – Szabolcs Jun 07 '19 at 11:38
  • Basically i want to call a function of mathematica called Global Adaptive method to integrate a function numerically in fortran code. So is that possible anyhow? – Prabhakar Namdev Jun 07 '19 at 11:42
  • @PrabhakarNamdev you could do it via a System call and wolframscript as a poor man’s version of MathLink – b3m2a1 Jun 07 '19 at 22:06
  • can we call NIntegrate function of mathematica from external program with mathlink? – Prabhakar Namdev Jun 18 '19 at 11:35

0 Answers0