function out = bbopbin(in, cfl, dww) % BBOPBIN - Bin bbop data % Bins the data in depth bins and returns the mean for each bin % % Use as: out = bbopbin(in, cfl, dww) % % Inputs: in = column oriented data (from GETPRRDATA) % cfl = configration data (from READCFL) % dww = depth window width (in m) % % The center of each depth bins start from the minimum depth rounded % towards zero to the maximum depth rounded towards infinity. The spacing % between each bin center is specified by dww. % Brian Schlining % 28 Jan 2000 %=================================== % Find the column containing depth %=================================== fields = lower(strvcat(cfl.info.description)); d = find(strcmp(lower({cfl.info.description}), 'depth')); depth = in(:,d); %=============================== % Create a vector of depth bins %=============================== minDepth = floor(nanmin(depth)); maxDepth = ceil(nanmax(depth)); binCenter = [minDepth:dww:maxDepth+dww]'; numBins = length(binCenter); [r c] = size(in); %================== % Initalize memory %================== out = ones(numBins, c)*NaN; %=============================== % Calculate a mean for each min %=============================== for i = 1:length(binCenter) top = binCenter(i) - dww/2; bottom = binCenter(i) + dww/2; good = find(depth > top & depth <= bottom); if isempty(good) out(i,:) = NaN; elseif length(good) == 1 out(i,:) = in(good,:); else out(i,:) = mean(in(good,:)); end end %================================================================= % Replace the depth column with the bins and remove rows of NaN's %================================================================= out(:,d) = binCenter; out = excise(out);