function adcp_deep(dataDirectory, outDirectory, siteA, siteB)
%
%   adcp_deep(dataDirectory, outDirectory, siteA, siteB)
%
%   Function which will go through the ADCP data and create a table of the
%   deepest bin for each station (along with mooring number, deployment
%   date, and recovery date).

%Soupy Alexander, 11/4/03

aData = [];
bData = [];

%Load in the site data
siteArchive = siteA;
for indexFile = 1:length(siteArchive)
    fileName = siteArchive(indexFile).fileList;
    if isempty(strfind(fileName, 'adc'))
        continue
    end
    moorNumber = fileName(1:4);
    fileStart = siteArchive(indexFile).startTime;
    fileEnd = siteArchive(indexFile).endTime;
    instDepth = siteArchive(indexFile).instDepth;
    
    fileData = [str2num(moorNumber) fileStart fileEnd instDepth];
    aData = [aData; fileData];
end

siteArchive = siteB;
for indexFile = 1:length(siteArchive)
    fileName = siteArchive(indexFile).fileList;
    if isempty(strfind(fileName, 'adc'))
        continue
    end
    moorNumber = fileName(1:4);
    fileStart = siteArchive(indexFile).startTime;
    fileEnd = siteArchive(indexFile).endTime;
    instDepth = siteArchive(indexFile).instDepth;
    
    fileData = [str2num(moorNumber) fileStart fileEnd instDepth];
    bData = [bData; fileData];
end

%Check for repeats
[junk, I] = unique(aData(:,1));
aData = aData(I, :);
[junk, I] = unique(bData(:,1));
bData = bData(I,:);

%Print out the table
fID = fopen(fullfile(outDirectory, 'adcp_deep.txt'), 'w');
fprintf(fID, 'Site A\n')
fprintf(fID, 'Mooring\tStart Time\tEnd Time\tDeepest Bin\n')
for indexI = 1:size(aData, 1)
    fprintf(fID, [num2str(aData(indexI,1), '%.0f') '\t' ...
            datestr(julian2datenum(aData(indexI,2)), 1) '\t' ...
            datestr(julian2datenum(aData(indexI,3)), 1) '\t' ...
            num2str(aData(indexI, 4), '%.0f') '\n']);
end
fprintf(fID, '\n\nSite B\n')
fprintf(fID, 'Mooring\tStart Time\tEnd Time\tDeepest Bin\n')
for indexI = 1:size(bData, 1)
    fprintf(fID, [num2str(bData(indexI,1), '%.0f') '\t' ...
            datestr(julian2datenum(bData(indexI,2)), 1) '\t' ...
            datestr(julian2datenum(bData(indexI,3)), 1) '\t' ...
            num2str(bData(indexI, 4), '%.0f') '\n']);
end

fclose('all')