function q=R2Quaternion(R)

ERR=10^-4;
if abs(det(R)-1)<ERR & isempty(find(abs(R*transpose(R)-eye(3,3))>ERR))
 [theta,w]=R2Euler(R);
 q=Euler2Quaternion(theta,w);
else
 fprintf('Error R2Quaternion: Invalid R \n');
end;