close all
clear all

SampleNames{1} = 'Beach';
SampleNames{2} = 'Chaet';
SampleNames{3} = 'Dun';
SampleNames{4} = 'Iso';
SampleNames{5} = 'Nano';
SampleNames{6} = 'Paragon';


IFCB_filenames{1} = {'ifcb-pump-test\beach-pre.csv' ...  
                     'ifcb-pump-test\beach-post.csv' ... 
                     }; 
IFCB_filenames{2} =  {'ifcb-pump-test\chaet-pre.csv' ...
                      'ifcb-pump-test\chaet-post.csv' ...
                     };  
IFCB_filenames{3} = {'ifcb-pump-test\dun-pre.csv' ...
                      'ifcb-pump-test\dun-post.csv' ...
                     };  
IFCB_filenames{4} = {'ifcb-pump-test\iso-pre.csv' ...
                      'ifcb-pump-test\iso-post.csv' ...
                     };  
IFCB_filenames{5} = {'ifcb-pump-test\nano-pre.csv' ...
                      'ifcb-pump-test\nano-post.csv' ...
                     };  
IFCB_filenames{6} = {'ifcb-pump-test\para-pre.csv' ...
                      'ifcb-pump-test\para-post.csv' ...
                     };  
                 
FC_filenames{1} = {'fc-pump-test\beach-pre.mat' ...  
                     'fc-pump-test\beach-post.mat' ... 
                     }; 
FC_filenames{2} =  {'fc-pump-test\chaet-pre.mat' ...
                      'fc-pump-test\chaet-post.mat' ...
                     };  
FC_filenames{3} = {'fc-pump-test\dun-pre.mat' ...
                      'fc-pump-test\dun-post.mat' ...
                     };  
FC_filenames{4} = {'fc-pump-test\iso-pre.mat' ...
                      'fc-pump-test\iso-post.mat' ...
                     };  
FC_filenames{5} = {'fc-pump-test\nano-pre.mat' ...
                      'fc-pump-test\nano-post.mat' ...
                     };  
FC_filenames{6} = {'fc-pump-test\para-pre.mat' ...
                      'fc-pump-test\para-post.mat' ...
                     };  
                 
                 
                 
IFCB_PixelsPerMicron = 3.4;

for i = 1:length(IFCB_filenames)  %i = test number
    
    for j = 1:length(IFCB_filenames{i})  %pre(j=1) post(j=2)
    j
      [data, headertext] = xlsread(IFCB_filenames{i}{j});
    
      IFCB_ESD{i}{j} = data(:,9)/IFCB_PixelsPerMicron;
    
    end
    
    
    for j = 1:length(FC_filenames{i})  %j = stop number
      FC_LabData{i}{j} = load(FC_filenames{i}{j});        
    end
    
end

binsize = 5;
bins = (0:binsize:100)+binsize/2;  %This specifies the bin centers.

IFCB_VolumeAnalyzed = .4;  %ml

for i = 1:length(IFCB_filenames)  %i = species number 
  for j = 1:2  %pre(j=1)   post(j=2)
  idx = find(IFCB_ESD{i}{j} > 0);  %Skip zeros
  [nelements_IFCB_ESD{i}{j},centers_IFCB_ESD{i}{j}] = hist(IFCB_ESD{i}{j}(idx),bins);
  npartperml_IFCB_ESD{i}{j} = (nelements_IFCB_ESD{i}{j})/IFCB_VolumeAnalyzed;

  [nelements_FC_ESD{i}{j},centers_FC_ESD{i}{j}] = hist(FC_LabData{i}{j}.ESD,bins);
  npartperml_FC_ESD{i}{j} = nelements_FC_ESD{i}{j}*FC_LabData{i}{j}.Lab_PPml/sum(nelements_FC_ESD{i}{j});
  
  end
end

   maxsize(1) = 100;
   maxsize(2) = 50;
   maxsize(3) = 50;
   maxsize(4) = 50;
   maxsize(5) = 50;
   maxsize(6) = 100;

%Plot FC Results  
figure('Position', [705 72 1138 1426],'PaperSize',[11 17],'PaperOrientation','portrait','PaperPositionMode','auto','PaperPosition',[.5 .5 10.5 16.5])
for i = 1:6
ah = subplot(3,2,i);
set(ah,'FontSize',14);
h = bar(centers_FC_ESD{i}{j},[nelements_FC_ESD{i}{1}'  nelements_FC_ESD{i}{2}'],'grouped');
set(h(1),'facecolor','blue');
set(h(2),'facecolor','yellow');
ylabel('Particles per ml');
xlabel('Size (ESD - microns)');
lh = legend([SampleNames{i} '-Pre  '],[SampleNames{i} '-Post  ']);
set(lh,'FontSize',12);
xlim([0 maxsize(i)]);
title(['FC - ' SampleNames{i} ' size distributions  ' num2str(binsize) '\mum bins']);

end
print('-dpdf',['FC_PumpingComparisons']);  
   
   
%Plot IFCB Results  
figure('Position', [705 72 1138 1426],'PaperSize',[11 17],'PaperOrientation','portrait','PaperPositionMode','auto','PaperPosition',[.5 .5 10.5 16.5])
for i = 1:6
ah = subplot(3,2,i);
set(ah,'FontSize',14);
h = bar(centers_IFCB_ESD{i}{j},[nelements_IFCB_ESD{i}{1}'  nelements_IFCB_ESD{i}{2}'],'grouped');
set(h(1),'facecolor','blue');
set(h(2),'facecolor','yellow');
ylabel('Particles per ml');
xlabel('Size (ESD - microns)');
lh = legend([SampleNames{i} '-Pre  '],[SampleNames{i} '-Post  ']);
set(lh,'FontSize',12);
xlim([0 maxsize(i)]);
title(['IFCB - ' SampleNames{i} ' size distributions  ' num2str(binsize) '\mum bins']);

end
print('-dpdf',['IFCB_PumpingComparisons']);  




%Plot Comparisons in absolute terms
plots_per_page = 6;
plot_num = 0;
page_num = 1;
figure('Position',[779 88 1225 1417],'PaperSize',[11 17],'PaperOrientation','portrait','PaperPositionMode','auto','PaperPosition',[.5 .5 10.5 16.5])
for i = 1:length(IFCB_filenames)  %i = species number
  for j = 1:2  %pre(j=1)   post(j=2)
    plot_num = plot_num+1;
    if(plot_num > plots_per_page)
        print('-dpdf',['AbsoluteComparisonHistograms_pg' num2str(page_num)]);
        page_num = page_num+1;
        figure('Position',[779 88 1225 1417],'PaperSize',[11 17],'PaperOrientation','portrait','PaperPositionMode','auto','PaperPosition',[.5 .5 10.5 16.5])
        plot_num = 1;
    end
    subplot(3,2,plot_num)
      h = bar(centers_IFCB_ESD{i}{j}-2,[npartperml_IFCB_ESD{i}{j}'  npartperml_FC_ESD{i}{j}'],'grouped');
      set(h(1),'facecolor','blue');
      set(h(2),'facecolor','yellow');
      set(gca,'FontSize',13);
      xlim([0 maxsize(i)]);
      xlabel('ESD (microns)')
      ylabel('Particles per ml Observed');
      if(j == 1)
          title([SampleNames{i} '-pre  ' num2str(binsize) ' \mum bins']);
      end
      if(j == 2)
         title([SampleNames{i} '-post  ' num2str(binsize) ' \mum bins']);
      end  
      lh = legend(['IFCB Results - ' num2str(sum(npartperml_IFCB_ESD{i}{j})) ' Particles per ml'],['FlowCam Results - ' num2str(sum(npartperml_FC_ESD{i}{j})) ' Particles per ml'],'Location','NorthEast');
      %lh = legend(['IFCB Results'],['FlowCam Results'],'Location','NorthEast');
      set(lh,'FontSize',9);
  end
end
        print('-dpdf',['AbsoluteComparisonHistograms_pg' num2str(page_num)]);

        
%Plot Comparisons in relative terms
plots_per_page = 6;
plot_num = 0;
page_num = 1;
figure('Position',[779 88 1225 1417],'PaperSize',[11 17],'PaperOrientation','portrait','PaperPositionMode','auto','PaperPosition',[.5 .5 10.5 16.5])
for i = 1:length(IFCB_filenames)  %i = species number
  for j = 1:2  %pre(j=1)   post(j=2)
    plot_num = plot_num+1;
    if(plot_num > plots_per_page)
        print('-dpdf',['RelativeComparisonHistograms_pg' num2str(page_num)]);
        page_num = page_num+1;
        figure('Position',[779 88 1225 1417],'PaperSize',[11 17],'PaperOrientation','portrait','PaperPositionMode','auto','PaperPosition',[.5 .5 10.5 16.5])
        plot_num = 1;
    end
    subplot(3,2,plot_num)
      h = bar(centers_IFCB_ESD{i}{j}-2,100*[npartperml_IFCB_ESD{i}{j}'/sum(npartperml_IFCB_ESD{i}{j})  npartperml_FC_ESD{i}{j}'/sum(npartperml_FC_ESD{i}{j})],'grouped');
      set(h(1),'facecolor','blue');
      set(h(2),'facecolor','yellow');
      set(gca,'FontSize',13);
      xlim([0 maxsize(i)]);
      xlabel('ESD (microns)')
      ylabel('% of Total Observed');
      if(j == 1)
          title([SampleNames{i} '-pre  ' num2str(binsize) ' \mum bins']);
      end
      if(j == 2)
         title([SampleNames{i} '-post  ' num2str(binsize) ' \mum bins']);
      end  
      lh = legend(['IFCB Results - ' num2str(sum(npartperml_IFCB_ESD{i}{j})) ' Particles per ml'],['FlowCam Results - ' num2str(sum(npartperml_FC_ESD{i}{j})) ' Particles per ml'],'Location','NorthEast');
      %lh = legend(['IFCB Results'],['FlowCam Results'],'Location','NorthEast');
      set(lh,'FontSize',9);
  end
end
        print('-dpdf',['RelativeComparisonHistograms_pg' num2str(page_num)]);



