%
% SORTE  Sort in ascending order, first by real value and then 
%        by the complex numbers are sorted so that a negative 
%        imaginary part comes above the positive imaginaryb part.
%
function [Xs,Is] = sorte(X,epp)

   if nargin < 2
      epp = 1e-12;
   end

   [Xt, Is] = sort(real(X));

   Xs = X(Is,:);

   for c=1:size(Xs,2)
      for r=1:size(Xs,1)-1
         if (isreal(Xs(r,c))==0) & (imag(Xs(r,c))>0) &...
            (abs(Xs(r,c)-cjt(Xs(r+1,c)))<epp) 
               
            H = Xs(r,c); 
            Xs(r,c)   = Xs(r+1,c);
            Xs(r+1,c) = H;
          
            H = Is(r,c); 
            Is(r,c)   = Is(r+1,c);
            Is(r+1,c) = H;

         end
      end
   end

end
