integer function period_z(n, aa, i)
complex(8) aa(0:n)

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

END function period_z
