- #1
winiepu
- 3
- 0
The following code is just an example. I try to apply mnbrak.f90 to my function f=(x-i)^2. I want to make i globle variable. If I use internal procedure, I can not use mnbrak.f90, since it can not accept the internal procedure. How do I deal with it? Thanks!
PROGRAM xbrent
USE nr
USE nrtype
IMPLICIT NONE
INTEGER(i4b) :: i
REAL(sp) :: ax, bx, cx, fa, fb, fc
!real, external:: f
! common i
DO i=1,10
ax=i-0.5_sp
bx=i+0.5_sp
CALL mnbrak(ax, bx, cx, fa, fb, fc, f)
!$ WRITE(*,'(1x,t13,a,t25,a,t37,a)') 'A','B','C'
!$ WRITE(*,'(1x,a3,t5,3f12.6)') 'X',ax,bx,cx
!$ WRITE(*,'(1x,a3,t5,3f12.6)') 'F',fa,fb,fc
write(*,*) f(ax),f(bx)
END DO
contains
FUNCTION f(x)
USE nr
USE nrtype
IMPLICIT NONE
REAL(sp) ::f,x
!common i
f=(x-i)**2.0_sp
END FUNCTION f
END PROGRAM xbrent
PROGRAM xbrent
USE nr
USE nrtype
IMPLICIT NONE
INTEGER(i4b) :: i
REAL(sp) :: ax, bx, cx, fa, fb, fc
!real, external:: f
! common i
DO i=1,10
ax=i-0.5_sp
bx=i+0.5_sp
CALL mnbrak(ax, bx, cx, fa, fb, fc, f)
!$ WRITE(*,'(1x,t13,a,t25,a,t37,a)') 'A','B','C'
!$ WRITE(*,'(1x,a3,t5,3f12.6)') 'X',ax,bx,cx
!$ WRITE(*,'(1x,a3,t5,3f12.6)') 'F',fa,fb,fc
write(*,*) f(ax),f(bx)
END DO
contains
FUNCTION f(x)
USE nr
USE nrtype
IMPLICIT NONE
REAL(sp) ::f,x
!common i
f=(x-i)**2.0_sp
END FUNCTION f
END PROGRAM xbrent