function dataout=holearray(datain, zbegin, zend, dz);

% datout=holearray(datain, zbegin, zend, dz);
%
% This is a matlab tool to do an array with values corresponding - J. Escartin 20/2/05
%
% Input:
% datain: 3-column variable with 
%    1 depth of top of interval, mbsf
%    2 depth of bottom of interval, mbsf
%    3 intensity value
% zbegin, zend, dz - depths of desired profile and depth step
% dataout
%    1 Depth of middle of interval (starts at zbegin+dz/2 mbsf)
%    2 Mean for interval (NaN if no data)
%    3 STD for interval
%    4 % of 'described' in dz depth interval (proxy for recovery)
%
% This program creates a 1-cm strat column of values for the given depth
% interval that is then used to do the averages (brute force approach
% method)

P=datain;
% set up variables for arrays used in calculation
dz=.01; zb=zbegin; ze=zend;
z=zb:dz:ze;z=z';t=z*0./0;
i=find(finite(P(:,3)));
P=P(i,:);


% to maximize values measured in case of overlap (overwrite with higher
% value for a given interval
[junk,i]=sort(P(:,3));
P=P(i,:);

for i=1:length(P(:,1));
    ig=find(z>=P(i,1) & z<P(i,2));
    if length(ig)>0,
        v=ones(length(ig),1).*P(i,3);
        t(ig)=v;
    end
end

dataout=[z t];