Re: problem with library function



On Jan 31, 11:40 am, "nakisa" <nakisa.noor...@xxxxxxxxx> wrote:
hi
i defined them in main program ,because i want to compute them in do
loop for times .

program lightcurve
Use numerical_libraries
implicit none
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
integer ITMAX, N
real ERRREL
PARAMETER (N=2)

integer K, NOUT
real FNORM, X(N), XGUESS(N)
EXTERNAL FCN ! , NEQNF, UMACH

real u1,u2 ! position of source
real tE ! velocity of source .
real b1 ! impcat parameter
real theta ! the angle between sorce trace and horzintal axis
real t0 !time of nearest ray to lens which centered on
origin .in unit of day
real t ! time of moving source
real A
real pi
pi=3.1428

theta=pi/4
t0=0.2
tE=10
b1=0.5

do t=0,1,0.1

u1=b1*sin(theta)+((t-t0)/tE)*cos(theta)
u2=b1*cos(theta)-((t-t0)/tE)*sin(theta)

data XGUESS/ 4.0, 2.0 / !Set values of initial guess

ERRREL = 0.0001
ITMAX = 100

call UMACH (2, NOUT)
call NEQNF (FCN, ERRREL, N, ITMAX, XGUESS, X, FNORM)

write (*,*),X(1),X(2)

end do ! do of t

end program lightcurve !deghat kon ,baranem inja tamom mishe

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! User-defined subroutine

subroutine FCN (X, F, N)
integer N
real X(N), F(N)

real u1,u2

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


u1 and u2 are undefined here.

F(1)=u1-(X(1)-X(1)/(X(1)**2+X(2)**2))
F(2)=u2-(X(2)-X(2)/(X(1)**2+X(2)**2))

return
end subroutine
<snip>

I suggest defining a module

module umod
implicit none
private
public :: u1,u2
real :: u1,u2
end module umod

and replacing the

"real u1,u2" statements in the function and main program with

use umod, only: u1, u2

It is important to understand that a local variable "x" in one program
unit has nothing to do with a local variable "x" in another unit. You
must understand this to accomplish anything in Fortran.

.