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


cou=1;
for i=1:length(Catalog)
    if strcmp(Catalog(i).field,'Depth')==1
        C(cou).field=Catalog(i).field;cou=cou+1;
    end
end

if cou==1;error('MyComponent:incorrectType',...
'No Depth column detected!! Please check: Depth field must be noted as "Depth"');end

id=findfield(Catalog,C(cou-1).field);
Cdep=Catalog(id).val;


save('Cdep.mat','Cdep')
out2=ZDepth1;




  prompt = {'Enter MIN Depth:','Enter MAX Depth:'};
  dlgtitle = 'Depth Range';
  dims = [1 35];
  definput = {num2str(min(Cdep)),num2str(max(Cdep))};
  answer = inputdlg(prompt,dlgtitle,dims,definput);
  
  a1=str2double(answer(1));  a2=str2double(answer(2));
  

cou=1;
for i=1:length(s1)
    x=Catalog(s1(i)).val;x=x(Cdep>=a1 & Cdep<=a2);
    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(Cdep>=a1 & Cdep<=a2);
  Cmag=Cmag(Cdep>=a1 & Cdep<=a2);Mc=min(Cmag);
  Cdep=Cdep(Cdep>=a1 & Cdep<=a2);


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


