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"; Column@ReadList[string1, String]; Column@ReadList[string2, String]) 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"}]; Quiet@netlink[name[[ix]], pr, 2], {ix, Length@name}]; Run["gfortran myutility.o hybrid.f90 debug_hybrid.o -o resx.exe"]; Run["resx.exe"] result = ReadList["...\\results.txt", Real] So now my question is that how can we modify the debug_hybrid.f90 (main program that calls fsolvehybrid) file to act as a subroutine that gets the initial values and returns the result?





FindRootfor you root finding? $\endgroup$