function [height,gaplist,sdrlist] = getdetlist(data,D,filename,plotoption)

currpath = cd;
%parse file name
[name rem]=strtok(filename,'.');
[dummy rem] = strtok(rem,'.');
[sysname rem] = strtok(rem,'.');
[dummy sslope]= strtok(rem,'.');
sslope = sslope(2:length(sslope)); %get rid of the dot in the beginning of the number
slope = sscanf(sslope,'%f');

cd([currpath '\' name]);

fid = fopen(filename,'r');

cd(currpath);

detlist = [];
height = [];
gaplist = [];
ind = 1;
s = fgets(fid);
do1(1:509,1:50) = 0;
do2(1:509,1:50) = 0;
do3(1:509,1:50) = 0;
totspikes = 509;
sdrlist(1:26,1:3) = 0;
while (s~= -1)
   [token,rem] = strtok(s,' ');
   [token,rem] = strtok(rem,' ');
   [token,rem] = strtok(rem,' ');
   height = [height; sscanf(rem,'%f')];
   fgets(fid);
   pinmlist = [];
   for j=1:509
      day(1:3) = 0;
      s = fgets(fid);
      [token,rem] = strtok(s,' ');
      A = sscanf(rem,'%d %d');
      pinmlist = [pinmlist; A(1)];
      fgets(fid);
      for k = 1:3
         s = fgets(fid);
         [token,rem] = strtok(s,' ');
         A = sscanf(rem,'%d %f');
         sigma = A(2);
         if sigma > 3
           day(k) = 1;
         end;
         sdrlist(ind,k)=sdrlist(ind,k)+max(day(1:k));
      end;
      do1(j,ind) = day(1);
      do2(j,ind) = max(day(1:2));
      do3(j,ind) = max(day(1:3));
      if sum(day) < 3
          gaplist = [gaplist; ind j sum(day) day];
      end;
%      detlist = [detlist;j day];
   end;
   s = fgets(fid);
   ind = ind + 1;
end; 
sdrlist = sdrlist/509;

if plotoption == 'p'
    figure;
    subplot(4,1,1);
    plot(pinmlist,data(pinmlist),'black');
    xlim([pinmlist(1) pinmlist(length(pinmlist))]);
    title([name ' Dataset. System ' upper(sysname) '. Spike slope ' slope]);
    set(gca,'XTick',pinmlist(1):60:length(pinmlist));
	set(gca,'XTickLabel',num2str(D(pinmlist(1):60:pinmlist(length(pinmlist)),1:8)));
    set(gca,'XGrid','on');

	%colormap('gray');
	subplot(4,1,2);
	bar(do1,'stack');   
	title('Detected on day 1');
	xlim([1 509]);
	ylim([0 ind]);
	set(gca,'XTick',1:60:509);
	set(gca,'XTickLabel',num2str(D(pinmlist(1):60:pinmlist(length(pinmlist)),1:8)));
	grid on
	
	%colormap('gray');
	subplot(4,1,3);
	bar(do2,'stack');
	title('Detected on day 2');
	xlim([1 509]);
	ylim([0 ind]);
	set(gca,'XTick',1:60:509);
	set(gca,'XTickLabel',num2str(D(pinmlist(1):60:pinmlist(length(pinmlist)),1:8)));
	grid on
	
	%colormap('gray');
	subplot(4,1,4);
	bar(do3,'stack');
	title('Detected on day 3');
	xlim([1 509]);
	ylim([0 ind]);
	%colorbar('vert');
	set(gca,'XTick',1:60:509);
	set(gca,'XTickLabel',num2str(D(pinmlist(1):60:pinmlist(length(pinmlist)),1:8)));
	grid on
end;