zroots_unity Function

public function zroots_unity(n, nn)

Arguments

Type IntentOptional AttributesName
integer(kind=I4B), intent(in) :: n
integer(kind=I4B), intent(in) :: nn

Return Value complex(kind=SPC), DIMENSION(nn)


Contents

Source Code


Source Code

	FUNCTION zroots_unity(n,nn)
	INTEGER(I4B), INTENT(IN) :: n,nn
	COMPLEX(SPC), DIMENSION(nn) :: zroots_unity
	INTEGER(I4B) :: k
	REAL(SP) :: theta
	zroots_unity(1)=1.0
	theta=TWOPI/n
	k=1
	do
		if (k >= nn) exit
		zroots_unity(k+1)=cmplx(cos(k*theta),sin(k*theta),SPC)
		zroots_unity(k+2:min(2*k,nn))=zroots_unity(k+1)*&
			zroots_unity(2:min(k,nn-k))
		k=2*k
	end do
	END FUNCTION zroots_unity