Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28990 Discussions

How to pass parameters to IMSL subroutines

cst99
Beginner
1,063 Views
I have searched google many times, but never found an example of how to pass an extra parameter to IMSL subroutines. Here is my code. It is to solve nonlinear equations for x given parameter para, but I do not know how to pass para to FCN.

program main
use NEQBF_INT
implicit none

real :: x(2), a(3), para,x0(2)
integer :: i
external fcn

a = (/0.1, 0.2, 0.3/)

do i=1,3
para = 2.0*sqrt(a(i))
x0=0.0
call neqbf (fcn, x,x0)
print*, 'x', x
end do

SUBROUTINE FCN (N, X, F)
implicit none
INTEGER N
REAL X(N), F(N)
F(1) = X(1) + EXP(X(1)-1.0) - 2.0
F(2) = EXP(X(2)-2.0)/X(1) + para*X(2)*X(2) - 10.0 ! (???)
RETURN
END

Any help is appreciated.

cst99
0 Kudos
4 Replies
Steven_L_Intel1
Employee
1,063 Views

You posted in our Linux/Mac forum - are you uising IMSL on Linux or Mac OS?

IMSL doesn't typically provide a way to pass extra context to worker functions. You could use COMMON or module variables for that.
0 Kudos
cst99
Beginner
1,063 Views

You posted in our Linux/Mac forum - are you uising IMSL on Linux or Mac OS?

IMSL doesn't typically provide a way to pass extra context to worker functions. You could use COMMON or module variables for that.

Thanks for reply. I use ifort + imsl in redhat. It does not have to be an imsl library in this case, but any subroutine that does not allow passing parameters.

In my example, I could have used module. But the problem is the loop number i. I cannot define i as a parameter in a module because its value changes.

cst99
0 Kudos
Steven_L_Intel1
Employee
1,063 Views
If you make FCN an internal procedure with CONTAINS, then it will have access to the local variables of the main program. Be very careful about this - see Doctor Fortran in "Think, Thank, Thunk" for how easy it is to get in trouble.
0 Kudos
cst99
Beginner
1,063 Views
If you make FCN an internal procedure with CONTAINS, then it will have access to the local variables of the main program. Be very careful about this - see Doctor Fortran in "Think, Thank, Thunk" for how easy it is to get in trouble.
Thanks. Also, I have hadto use COMMON to address original question.

cst
0 Kudos
Reply