function IsSorted=sim_issortedcat(Sim,SortCol)
%--------------------------------------------------------------------------
% sim_issortedcat function                                         ImBasic
% Description: For each SIM array catalog, check if catalog is sorted
%              by a specific column.
% Input  : - SIM array with catalogs.
%          - Column to check. Default is 'YWIN_IMAGE'.
% Output : - Vector of logicals indicating if each one of the SIM catalogs
%            is sorted.
% License: GNU general public license version 3
% Tested : Matlab R2015b
%     By : Eran O. Ofek                    Feb 2016
%    URL : http://weizmann.ac.il/home/eofek/matlab/
% Example: IsSorted=sim_issortedcat(Sim);
% Reliable: 2
%--------------------------------------------------------------------------


CatField         = 'Cat';
CatColCellField  = 'ColCell';

if (nargin==1),
    SortCol = 'YWIN_IMAGE';
end


if (~issim(Sim)),
    error('Input must be a SIM array with catalog');
end

Nsim = numel(Sim);
IsSorted = false(Nsim,1);
for Isim=1:1:Nsim,
    % get the index of the column to sort by
    [~,ColSort]=col_name2ind(Sim(Isim).(CatColCellField),SortCol);

    % is sorted
    IsSorted(Isim) = issorted(Sim(Isim).(CatField)(:,ColSort));
end

  