I have an integral in which the integrand is a combination of ratio of modified bessel function of second kind. I am able to find the solution of this integral with mathematica Nintegrate module with global adaptive method but i want to use this global adaptive method code to write a separate program in fortran. Can i do that?
That's not possible. That's not so easy.
NIntegrate is probably too complex to be automagically ported to FORTRAN or any other programming language. Depending on the effort that you are willing to invest, there are several options:
You may use Mathematica to find out which fixed quadrature rule works best for this family of integrands. Afterwards, you will have to implement this quadrature rule yourself in FORTRAN. Or you better use a library that is specialized on computing numerical integrals (as you will also have to use a library for evaluating the modified Bessel functions). From the fact that you are working in FORTRAN, I deduce that you are interested mostly in runtime performance. If you have to compute really many of such integrals and if these computations are time-critical, this is probably the most efficient way; in contrast adaptive methods tend to have quite an overhead.
You may use WSTP to set up communication between FORTRAN and a Mathematica kernel. I do not have any experience with this. IIRC, this will require you (i) to write a wrapper library in C that sets up the WSTP connection and (ii) to call the generated library from FORTRAN. This will require a running Mathematica kernel and thus an appropriate license. (The latter might be mended by using the free Wolfram Engine for developers; I am not sure about this.) In any case, this won't be very efficient.
As JimB pointed out, the commercial addon MathCode F90 might do the job. I cannot tell, because I have not used it yet. But I somewhat doubt that it will work as expected. As far as I know, only a subset of Mathematica code is actually compilable by MathCode F90 (Mathematica's
FunctionCompilehave similar limitations). For example, it is stated on this page that
FindMinimumis not compilable.
NIntegrateis similarly complex, so I do believe that it is not compilable either. You might find more details in Appendix A of the manual.
If you require the integrals only for an a a priorily know, low-dimensional range of parameters, then you may try to compute the integrals once on a fixed grid of points with Mathematica, export the data to file, load it into FORTRAN (at runtime), and use interpolation to approximate the integrals for arbitrary parameters. This might be very fast, even faster than method 1 because Bessel functions are notoriously expensive to evaluate. However, this requires that the integrals depend smoothly on the parameters.
I recommend that you look at numerical libraries for FORTRAN. I haven't used FORTRAN in a quarter of a century, so I'm not familiar with what's available today, but this is the kind of problem FORTRAN was designed for. I expect you'll find something that fits your needs.
It wouldn't surprise me if
NIntegrate works in this case by first symbolically analyzing the problem (very difficult to automate in FORTRAN) and then handing it to a chosen FORTRAN library function. You'll have to do that choosing yourself.