integer function period(n, aa, i)
real aa(0:n)

period =0
do i =n-1, 1, -1
if(aa(n) ==aa(i)) then
period =n-i
exit
endif
enddo

END function period
