clobber.f
program clobber
c This program illustrates the pit-falls of not watching array indices
c
c John Mahaffy 2/14/96
c
implicit none
integer ndim,nd2,i
parameter (ndim=10, nd2=ndim+2)
real a(ndim),b(ndim),c(ndim),adat,bdat,cdat
data adat,bdat,cdat/1.0,2.0,3.0/
do i=1,nd2
a(i)=adat
b(i)=bdat
c(i)=cdat
enddo
c
c From the above DO loop you would expect all elements of a to be 1.0
c all elements of b to be 2.0, and all elements of c to be 3.0, but
c look at the printout and see how the inappropriate DO loop index
c maximum clobbers the first 2 elements of b and c.
c
print *, ' i a b c '
write (*,2000) (i,a(i),b(i),c(i),i=1,ndim)
2000 format (i3,3f7.3)
stop
end