function [Ctime,Cmag,Data,Mc]=FiltTime(Ctime,Cmag,Catalog,PROD_Data,s1)
clc

title('Select time period for analysis','FontSize',14,'FontWeight','bold');hold on
 plot(Ctime,1:length(Ctime),'-','LineWidth',2);ylabel('Events','FontSize',14);hold on
if isempty(PROD_Data)==0;
    yyaxis right; plot(PROD_Data(1).val,PROD_Data(2).val,'-','LineWidth',2);ylabel(PROD_Data(2).field,'FontSize',14,'Interpreter','none');
end
datetick('x',20);xlabel('Date','FontSize',14);xlim([min(Ctime)-1,max(Ctime)+1])

[T,N]=ginput(2);



  
  cou=1;
for i=1:length(s1)
    x=Catalog(s1(i)).val;x=x(Ctime>=T(1) & Ctime<=T(2));
    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

Cmag=Cmag(Ctime>=T(1) & Ctime<=T(2));Mc=min(Cmag);
Ctime=Ctime(Ctime>=T(1) & Ctime<=T(2));

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