function ret=crootssort(w)

# This function sorts complex numbers such that
# 1) All the pure reals come first and are sorted.
# 2) All complex numbers are sorted by 
#      their real parts.
iscol=iscolumn(w);
q=sort(w(imag(w)==0));
q1=(w(imag(w)!=0));
[s ii]=sort(real(q1));
q2=q1(ii);
if(iscol)
 ret=[q' q2']';
else
  ret=[q q2];
endif
endfunction