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

period =0

do it =nit-1, 0, -1

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

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

END function period
