i run into a strange problem. I am using the locate subroutine from the Fortran-Recipe book. The goal is to find a random number in a CDF-table and return the index of the arrax, such that i can look in another table for the value this would correspond. However i cannot ge it to pass the value of j (jlo in the encompassing function) back. It just stays 0. The subroutine locate changes the value of j to the correct one, but then does not pass it back.
SUBROUTINE locate(xx,n,x,j)
INTEGER, INTENT(out) :: j
REAL*8 x,xx(n)
INTEGER jl,jm,ju,n
jl=0
ju=n+1
10 if(ju-jl.gt.1)then
jm=(ju+jl)/2
if((xx(n).ge.xx(1)).eqv.(x.ge.xx(jm)))then
jl=jm
else
ju=jm
endif
goto 10
endif
if(x.eq.xx(1))then
j=1
else if(x.eq.xx(n))then
j=n-1
else
j=jl
endif
return
END
This is the design of the subroutine
and this is how it is included:
function CDF() result(xyz)
implicit none
real(BW) :: rand
integer(I2B) :: jlo, N_points_table
real(BW), allocatable :: CDFtable(:)
N_points_table= 1000
jlo=0
CALL RANDOM_NUMBER(rand)
allocate(CDFtable(N_points_table))
...
!setting the content of CDFtable to a CDF of some kind
...
call locate(CDFtable,N_points_table,rand,jlo)
....
....
However after the subroutine ran, jlo is still 0 as it was initiated. Any help is greatly appreciated