- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Steve Lionel (Intel)
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Steve Lionel (Intel)
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.
cst

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page