integer function period8(n, nit, aa, it)
real(8) aa(n, 0:nit), adif(n)

period8 =0

do it =nit-1, 0, -1

!if(aa(:, nit) ==aa(:, it)) then
adif =aa(:, nit) -aa(:, it)

if( ALL(adif ==0) ) then
period8 =nit -it
exit
endif
enddo

END function period8
