I need help debugging stack/heap corruption problems. I have the following code
real(kind=8) :: Offset(1,3), POffset(1,3), A(3,4), B(3,4)
...
do ii = 1,3
Offset(1,ii) = (sum(A(ii,:))/8.d0 - sum(B(ii,:)))/8.d0
enddo
write(*,*)'A',offset
do ii = 1,3
Offset(1,ii) = (sum(A(ii,:))-sum(B(ii,:)))/8.d0
POffset(1,ii) = (sum(A(ii,:))+sum(B(ii,:)))/8.d0
enddo
write(*,*)'B',offset
There is a lot of other stuff happening in the subroutine before that block of code i've written here but that is where the bug I have is currently manifesting itself as a mismatch in the two write statements. Strange things happen of course: If I add a third write statement within the second loop then the first two write statements will match. If i delete the underlined line of code then the write statements match. Could someone point me in the right direction to debug this kind of error (online tutorial/guide etc)? It's pretty clear that the problem is not in those lines of code. So somewhere above the stack must have been corrupted? I am at a loss as to how to debug this. I've been programming Fortran for years and, embarrassingly I still don't know how to debug this kind of bug. I'm using the compiler on a 32 bit linux machine.
Nate