subroutine qrdec(A,n,m,nmax,Q,R)
parameter(tiny=1.e-10)
dimension A(nmax,nmax),Q(nmax,nmax),R(nmax,nmax)

do i=1,m
	R(i,i)=sqrt(dot(a(1,i),a(1,i),n))
	if( R(i,i)<tiny )stop 'determinant = 0 ?'
	do j=1,n
		q(j,i)=a(j,i)/R(i,i)
	end do
	do j=i+1,m
		R(i,j)=dot(q(1,i),a(1,j),n)
		   do k=1,n
		   	a(k,j)=a(k,j)-R(i,j)*q(k,i)
		   end do
	end do
end do	

return; end

function dot(a,b,n); dimension a(n),b(n)
dot=0; do i=1,n; dot=dot+a(i)*b(i); end do
return; end
