function sed_trap_2(maxYear, dataDirectory, plotDirectory)
%
%   sed_trap_2(maxYear, dataDirectory, plotDirectory)
%
%   Function to create plots of the sediment trapping rate of all traps at all times.
%   Plots are named SITE_sed2.

%Soupy Alexander, 11/13/03

%Sediment trap data
[theNums, theText] = xlsread(fullfile(dataDirectory, 'all_traps.xls'), ...
    'LNB Traps');
theNums = [repmat(NaN, 1, size(theNums, 2)); theNums];
trapType = theText(:,19);
for index = 1:length(trapType)
    if isempty(trapType{index})
        trapType(index) = {' '};
    end
end
theTubes = find(strcmp('tube', deblank(lower(trapType))));

tubeNums = theNums(theTubes,:);
tubeText = theText(theTubes,:);

tubeStart = tubeNums(:,4) + datenum('30-Dec-1899');
tubeEnd = tubeNums(:, 6) + datenum('30-Dec-1899');
tubeDepths = tubeNums(:,22);
poisonType = tubeText(:,20);
tubeFlux = tubeNums(:, 28);

for index = 1:length(poisonType)
    if isempty(poisonType{index})
        poisonType(index) = {' '};
    end
end

plotSym = cell(size(poisonType));
theForms = strmatch('form', lower(deblank(poisonType)));
theForms = [theForms(:); strmatch('f', lower(deblank(poisonType)), 'exact')];
theAzides = strmatch('azi', lower(deblank(poisonType)));
theNone = strmatch('n', lower(deblank(poisonType)));
theNone = [theNone(:); strmatch('ff', lower(deblank(poisonType)))];  
theNone = [theNone(:); strmatch('?', lower(deblank(poisonType)))];
plotSym(theForms) = {'r'};
plotSym(theAzides) = {'b'};
plotSym(theNone) = {'k'};
    
targDepths = {[0 2]; [2.1 5]; [5.1 8]; [15 17]};
plotPosition = [1 2 4 5]; 
yRanges = {[0 300]; [0 150]; [0 60]; [0 60]};

gregYears = gregorian(datenum2julian(tubeEnd));

yearList = [1990:1:maxYear];
theTicks = [];
for indexYear = 1:length(yearList)
    theTicks = [theTicks(:); datenum(yearList(indexYear), 1, 1)];
end

figure, orient landscape, hold on

for index = 1:length(targDepths)
    subplot(5, 1, plotPosition(index)), hold on
    hitDepth = targDepths{index};
    theIns = find(tubeDepths >= hitDepth(1) & tubeDepths <= hitDepth(2));
    plotX = tubeEnd(theIns);
    plotY = tubeFlux(theIns);
    toPlot = plotSym(theIns);
    for index2 = 1:length(plotX)
        plot(plotX(index2), plotY(index2), [toPlot{index2} '*']);
    end
    
    set(gca, 'xtick', theTicks)
    xlim([datenum(1990, 1, 1) datenum(maxYear, 12, 31)])
    datetick('x', 10, 'keeplimits', 'keepticks')
    ylim(yRanges{index})
    ylabel('g/m^2/day')
    box('on')
    title(['Average Sediment Flux, Tube Traps, ' num2str(hitDepth(1), '%.0f') ...
            '-' num2str(hitDepth(2), '%.0f') ' mab'])
    set(gca, 'fontsize', 8)
    
end

%%%%%%%%%%%%%%%
theHonjos = find(strcmp('honjo', deblank(lower(trapType))));

honjoNums = theNums(theHonjos,:);
honjoText = theText(theHonjos,:);


honjoStart = honjoNums(:,4) + datenum('30-Dec-1899');
honjoEnd = honjoNums(:, 6) + datenum('30-Dec-1899');
honjoDepths = honjoNums(:,22);
poisonType = honjoText(:,20);
honjoFlux = honjoNums(:, 28);
honjoDeploy = honjoText(:,2);

for index = 1:length(poisonType)
    if isempty(poisonType{index})
        poisonType(index) = {' '};
    end
end

[cruiseList, I, J] = unique(honjoDeploy);

for indexCruise = 1:length(cruiseList)
    thisCruise = find(J == indexCruise);
    totalStart(indexCruise) = min(honjoStart(thisCruise));
    totalEnd(indexCruise) = max(honjoEnd(thisCruise));
    totalPoison(indexCruise) = lower(poisonType(thisCruise(1)));
    totalFlux(indexCruise) = nanmean(honjoFlux(thisCruise));
end
    

plotSym = cell(size(totalPoison));
theForms = strmatch('form', lower(deblank(totalPoison)));
theForms = [theForms(:); strmatch('f', lower(deblank(totalPoison)), 'exact')];
theAzides = strmatch('azi', lower(deblank(totalPoison)));
theNone = strmatch('n', lower(deblank(totalPoison)));
theNone = [theNone(:); strmatch('ff', lower(deblank(totalPoison)))];  
theNone = [theNone(:); strmatch('?', lower(deblank(totalPoison)))];
plotSym(theForms) = {'r'};
plotSym(theAzides) = {'b'};
plotSym(theNone) = {'k'}; 

gregYears = gregorian(datenum2julian(totalEnd));

subplot(5, 1, 3), hold on
plotX = totalEnd;
plotY = totalFlux;
toPlot = plotSym;
for index2 = 1:length(plotX)
    plot(plotX(index2), plotY(index2), [toPlot{index2} '*']);
end

set(gca, 'xtick', theTicks)
xlim([datenum(1990, 1, 1) datenum(maxYear, 12, 31)])
datetick('x', 10, 'keeplimits', 'keepticks')
ylim([0 30])
ylabel('g/m^2/day')
box('on')
title(['Average Sediment Flux, Honjo Traps, 4 mab'])
set(gca, 'fontsize', 8)

suptitle(['Site A Sediment Traps'])

subplot('position', [0.13 0.01 0.77 0.08]), hold on
plot(5, 3, 'r*')
plot(5, 2, 'b*')
plot(5, 1, 'k*')
text(5.5, 3, 'Formalin', 'fontsize', 8);
text(5.5, 2, 'Azide', 'fontsize', 8);
text(5.5, 1, 'No Poison', 'fontsize', 8);
axis([0 12 0 4])
axis('off')

printTitle = ['a_sed2'];
print('-dpdf', fullfile(plotDirectory, printTitle))
close

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Sediment trap data
[theNums, theText] = xlsread(fullfile(dataDirectory, 'all_traps.xls'), ...
    'Scituate Traps');
theNums = [repmat(NaN, 1, size(theNums, 2)); theNums];
trapType = theText(:,19);
for index = 1:length(trapType)
    if isempty(trapType{index})
        trapType(index) = {' '};
    end
end
theTubes = find(strcmp('tube', deblank(lower(trapType))));

tubeNums = theNums(theTubes,:);
tubeText = theText(theTubes,:);

tubeStart = tubeNums(:,1) + datenum('30-Dec-1899');
tubeEnd = tubeNums(:, 3) + datenum('30-Dec-1899');
tubeDepths = tubeNums(:,20);
poisonType = tubeText(:,20);
tubeFlux = tubeNums(:, 43);

for index = 1:length(poisonType)
    if isempty(poisonType{index})
        poisonType(index) = {' '};
    end
end

plotSym = cell(size(poisonType));
theForms = strmatch('form', lower(deblank(poisonType)));
theForms = [theForms(:); strmatch('f', lower(deblank(poisonType)), 'exact')];
theAzides = strmatch('azi', lower(deblank(poisonType)));
theNone = strmatch('n', lower(deblank(poisonType)));
theNone = [theNone(:); strmatch('ff', lower(deblank(poisonType)))];  
theNone = [theNone(:); strmatch('?', lower(deblank(poisonType)))];
plotSym(theForms) = {'r'};
plotSym(theAzides) = {'b'};
plotSym(theNone) = {'k'};
    
targDepths = {[0 2]; [2.1 5]; [5.1 8]};
plotPosition = [1 2 4]; 
yRanges = {[0 300]; [0 150]; [0 60]};

gregYears = gregorian(datenum2julian(tubeEnd));

yearList = [1998:1:maxYear];
theTicks = [];
for indexYear = 1:length(yearList)
    theTicks = [theTicks(:); datenum(yearList(indexYear), 1, 1)];
end

figure, orient landscape, hold on


for index = 1:length(targDepths)
    subplot(4, 1, plotPosition(index)), hold on
    hitDepth = targDepths{index};
    theIns = find(tubeDepths >= hitDepth(1) & tubeDepths <= hitDepth(2));
    plotX = tubeEnd(theIns);
    plotY = tubeFlux(theIns);
    toPlot = plotSym(theIns);
    for index2 = 1:length(plotX)
        plot(plotX(index2), plotY(index2), [toPlot{index2} '*']);
    end
    
    set(gca, 'xtick', theTicks)
    xlim([datenum(1998, 1, 1) datenum(maxYear, 12, 31)])
    datetick('x', 10, 'keeplimits', 'keepticks')
    ylim(yRanges{index})
    ylabel('g/m^2/day')
    box('on')
    title(['Average Sediment Flux, Tube Traps, ' num2str(hitDepth(1), '%.0f') ...
            '-' num2str(hitDepth(2), '%.0f') ' mab'])
    set(gca, 'fontsize', 8)
    
end
%%%%%%%%%%%%%%%
theHonjos = find(strcmp('honjo', deblank(lower(trapType))));

honjoNums = theNums(theHonjos,:);
honjoText = theText(theHonjos,:);


honjoStart = honjoNums(:,1) + datenum('30-Dec-1899');
honjoEnd = honjoNums(:, 3) + datenum('30-Dec-1899');
honjoDepths = honjoNums(:,20);
poisonType = honjoText(:,20);
honjoFlux = honjoNums(:, 43);
honjoDeploy = honjoText(:,3);

for index = 1:length(poisonType)
    if isempty(poisonType{index})
        poisonType(index) = {' '};
    end
end

[cruiseList, I, J] = unique(honjoDeploy);

for indexCruise = 1:length(cruiseList)
    thisCruise = find(J == indexCruise);
    totalStart(indexCruise) = min(honjoStart(thisCruise));
    totalEnd(indexCruise) = max(honjoEnd(thisCruise));
    totalPoison(indexCruise) = lower(poisonType(thisCruise(1)));
    totalFlux(indexCruise) = nanmean(honjoFlux(thisCruise));
end
    

plotSym = cell(size(totalPoison));
theForms = strmatch('form', lower(deblank(totalPoison)));
theForms = [theForms(:); strmatch('f', lower(deblank(totalPoison)), 'exact')];
theAzides = strmatch('azi', lower(deblank(totalPoison)));
theNone = strmatch('n', lower(deblank(totalPoison)));
theNone = [theNone(:); strmatch('ff', lower(deblank(totalPoison)))];  
theNone = [theNone(:); strmatch('?', lower(deblank(totalPoison)))];
plotSym(theForms) = {'r'};
plotSym(theAzides) = {'b'};
plotSym(theNone) = {'k'}; 

gregYears = gregorian(datenum2julian(totalEnd));

subplot(4, 1, 3), hold on
plotX = totalEnd;
plotY = totalFlux;
toPlot = plotSym;
for index2 = 1:length(plotX)
    plot(plotX(index2), plotY(index2), [toPlot{index2} '*']);
end

set(gca, 'xtick', theTicks)
xlim([datenum(1998, 1, 1) datenum(maxYear, 12, 31)])
datetick('x', 10, 'keeplimits', 'keepticks')
ylim([0 30])
ylabel('g/m^2/day')
box('on')
title(['Average Sediment Flux, Honjo Traps, 4 mab'])
set(gca, 'fontsize', 8)


suptitle(['Site B Sediment Traps'])

subplot('position', [0.13 0.01 0.77 0.08]), hold on
plot(5, 3, 'r*')
plot(5, 2, 'b*')
plot(5, 1, 'k*')
text(5.5, 3, 'Formalin', 'fontsize', 8);
text(5.5, 2, 'Azide', 'fontsize', 8);
text(5.5, 1, 'No Poison', 'fontsize', 8);
axis([0 12 0 4])
axis('off')

printTitle = ['b_sed2'];
print('-dpdf', fullfile(plotDirectory, printTitle))
close

