function s = sortrows( m,c ),
  ## returns m sorted "lexicographically", or following the columns in
  ## the second argument. Set implicit_str_to_num_ok and
  ## implicit_num_to_str_ok to 1 if you use this for string sorting.
  
  ## Daniel Calvelo. Use modify and debug at will.
  if nargin<2,
    indices = [1:size(m,2)]';
  else,
    indices = c(:);
  endif
  indices=flipud(indices);
  ii=1;
  while ii<=length(indices),
    [trash,idx] = sort( m(:,indices(ii)) ); # sort keeps the original
order :)
    m = m( idx,: );
    ii++;
  endwhile
  s = m;
endfunction
