Reputation: 3
My code is currently breaking when I try to pass an array to another array. I'm using gfortran as the compiler with no special flags. I'm also writing the file as a ".f95". Here's the backbone of the code that's causing the problem:
program foo
integer, parameter :: pp = 16
call fooyoo
contains
subroutine fooyoo
real(kind=pp), allocatable :: f(:,:,:), y_ix(:), r(:)
integer :: ii, jj, nn
nn = 32
r = zoo(nn)
y_ix = r ! this is done because I'm actually allocating two other 1D arrays
do ii = 1, nn
do jj = 1, nn
write(*,*) "crashes here"
f(ii,jj,:) = y_ix
write(*,*) "nothing here"
end do
end do
end subroutine
function zoo(nn) result(r)
integer :: i, nn
real(kind=pp) :: r(nn)
do i = 1, nn
r(i) = i
end do
end function
end program
Upvotes: 0
Views: 132
Reputation: 78364
Probably
do ii = 1, nn
do jj = 1, nn
write(*,*) "crashes on executing the next line because programmer forgot ", &
"to allocate f before trying to set values"
f(ii,jj,:) = y_ix
write(*,*) "nothing here"
end do
end do
In this line
y_ix = r
automatic allocation works because the expression on the lhs is an allocatable array. In
f(ii,jj,:) = y_ix
automatic allocation fails because the expression on the lhs is an array section, not an allocatable array.
Upvotes: 3