# How to integrate a function written in fortran that solves a set of nonlinear equations into mathematica?

I am trying to integrate the solver for the set of nonlinear equations link written in Fortran language into mathematica . To do so i developed a function called netlib based on the explanation given in link

Needs["NETLink"];
GFortran1[name_, inp_] := (
Export[name <> ".f90", inp, "Text"];
string1 = "!gfortran -c " <> name <> ".f90 ";
string2 =
"!gfortran -s -shared -mrtd -o " <> name <> ".dll " <> name <> ".o";
netlink[name_, code_, fun_] := Block[{string1, string2},

ReinstallNET["Force32Bit" -> True];
ReinstallNET["Force32Bit" -> False];
SetDirectory[NotebookDirectory[]];
path = FileNameJoin[{Directory[], name <> ".dll"}];
If[fun == 1,
(Evaluate@ToExpression@name) =
DefineDLLFunction[name <> "_", path,
"double", {"double[]", "double*"}], (Evaluate@
ToExpression@name) =
DefineDLLFunction[name <> "_", path,
"void", {"Double[]", "Double*", "Double[]"}]];
DeleteFile[{name <> ".f90", name <> ".dll", name <> ".o",
name <> ".mod"}];
GFortran1[name, code];
]


and it works like this  So now with a slight modification of the FsolveHybridTest subroutine (x0 is the initial condition and xout2 is the result) in the hybrid.f90 file (to save the results in a file called results.txt) and debug_hybrid.f90

it is possible to call the netlink function to get the correct result (replace ... with a correct directory)

name = {"myutility", "hybrid", "debug_hybrid"};
Table[
pr = Import[
".../Optimization-master/" <> name[[ix]] <>
".f90", {"Text"}];
Run["gfortran myutility.o hybrid.f90  debug_hybrid.o -o resx.exe"];
Run["resx.exe"] • I understand this is not your question but have you tried FindRoot` for you root finding? – user21 Sep 5 '19 at 4:31