- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am using the following code for random permutations:
subroutine rperm(nsim, IPERM1)
integer, intent(in) :: nsim
integer, dimension(:), intent(out) :: IPERM1
integer :: mynumber, i, j, k
real, dimension(nsim) :: rand2
call random_number(rand2)
IPERM1= 0
do i=1,nsim
print*, 'HEREHEREHERE: i=', i
mynumber=1
do j=1,nsim
if (rand2(i) > rand2(j)) then
mynumber = mynumber+1
end if
end do
if (i>1) then
do k=1,i-1
if (rand2(i) <= rand2(k) .and. rand2(i) >= rand2(k)) then
mynumber = mynumber+1
end if
end do
c
end if
print*, 'RPERM WORKS HERE'
IPERM1(i) = mynumber
end do
return
end subroutine rperm
However, it is getting stuck at the line: IPERM1(i) = mynumber and exits the subroutine.
Why is this happening?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How are you calling the procedure? Does it have an explicit interface?
(Is the argument nsim redundant given the size of the IPERM1 argument is available inside the procedure?)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm guessing you don't have an explicit interface, and so iperm1(:) must be assumed size. Otherwise, as Ian hinted, size(iperm1) would be defined, and nsim > size(iperm1) could be checked to detect an obvious problem. In any case, violating that condition would make behavior unpredictable.
If iperm1 is meant to have dimension(nsize), writing it that way and invoking ifort interface checking would give you an automatic indication of the violation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Got it. I needed to declare it's size. Thanks
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page