function [Ctime,Cmag,Data,Mc]=FiltMc(Ctime,Cmag,Catalog,s1)
clc
id_time=findfield(Catalog,'Occurrence_Time');
                                                                            %opts.Interpreter='tex';opts.Default='Yes';
                                                                            %quest='Do you wish to filter Data for Mc?';
                                                                            %answer=questdlg(quest,'Data Completenes','Yes','No',opts);
                                                                            %if strcmp(answer,'Yes')

%% THIS HAS MOVED TO A SEPARATE FUNCTION IN THE BEGINNING OF THE APPLICATION
% cou=1;
% for i=1:length(Catalog)
%     if strcmp(Catalog(i).fieldType,'Magnitude')==1
%         C(cou).field=Catalog(i).field;cou=cou+1;
%     end
% end
% 
% % Check for no magnitude
% if cou==1;error('MyComponent:incorrectType',...
% 'No magnitude column detected!! Please check: Magnitude fields must be noted as one of the following:\nM  ,  Mw  ,  ML  ,  Ms  ,  mb  ,  Md\n or select the entire sample for analysis');end
% 
% %Select Parameters from Seismic Catalog -
% [ss1,ok]=listdlg('PromptString','Please Select M scale:',...
%     'ListString',{C.field}, 'SelectionMode','single');
% 
%  id=findfield(Catalog,C(ss1).field);
%   Mtype=Catalog(id).field;
% Ctime=Catalog(id_time).val;
% id_M=findfield(Catalog,Mtype);
% Cmag=Catalog(id_M).val;

%% 

ar=min(Cmag):0.1:max(Cmag);
fig_Mc=figure;histogram(Cmag,length(ar));set(gca,'YScale','log')
title('Please Select M_C','FontSize',14);xlabel('M','FontSize',14),ylabel('Log_1_0N','FontSize',14)
% Select events above Mc
[Mc,N]=ginput(1);Mc=floor(10*Mc)/10;close(fig_Mc);

disp(['Mc: ',num2str(Mc)])

                                                                            % elseif strcmp(answer,'No')
                                                                            % Ctime=Catalog(id_time).val;Cmag=Ctime;Mc=-20;
                                                                            % end

cou=1;


for i=1:length(s1)
    x=Catalog(s1(i)).val;x=x(Cmag>=Mc);
    index=isnan(x)==0;
    x=x(isnan(x)==0);
    Data(cou).field=Catalog(s1(i)).field;
    Data(cou).fieldType=Catalog(s1(i)).fieldType;
    Data(cou).val=nan(size(index)); Data(cou).val(index)=x;
    cou=cou+1;
end

Ctime=Ctime(Cmag>=Mc);Cmag=Cmag(Cmag>=Mc);

n=length(Ctime);
disp(['number of events: ',num2str(n)]) 

end