function h = tb_V3AMean(dims,zb,dirs)
%tb_V3AMean:Plot the development of the mean DeltaR* in time.
%
%   Plot the development of the mean A in time. The mean is
%   calculated from the A in the comparison stretches.
%
%   Syntax:
%   h = tb_V3AMean(dims,zb)
%
%   Input:      XBeach structure with dimensions & bottom data
%   Output:     Figure of time development of mean A (h)
%
%   Example
%   h = tb_V3AMean(dims,xb.data(1,2).value)
%
%   See also

%% Copyright notice
%   --------------------------------------------------------------------
%   Copyright (C) 2011 <COMPANY>
%       Bram de Vries
%
%       <EMAIL>	
%
%       <ADDRESS>
%
%   This library is free software: you can redistribute it and/or
%   modify it under the terms of the GNU Lesser General Public
%   License as published by the Free Software Foundation, either
%   version 2.1 of the License, or (at your option) any later version.
%
%   This library is distributed in the hope that it will be useful,
%   but WITHOUT ANY WARRANTY; without even the implied warranty of
%   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
%   Lesser General Public License for more details.
%
%   You should have received a copy of the GNU Lesser General Public
%   License along with this library. If not, see <http://www.gnu.org/licenses/>.
%   --------------------------------------------------------------------

% This tool is part of <a href="http://OpenEarth.nl">OpenEarthTools</a>.
% OpenEarthTools is an online collaboration to share and manage data and 
% programming tools in an open source, version controlled environment.
% Sign up to recieve regular updates of this function, and to contribute 
% your own tools.

%% Version <http://svnbook.red-bean.com/en/1.5/svn.advanced.props.special.keywords.html>
% Created: 13 May 2011
% Created with Matlab version: 7.9.1.705 (R2009b) Service Pack 1

% $Id$
% $Date$
% $Author$
% $Revision$
% $HeadURL$
% $Keywords: $


%% ===Settings=============================================================
OPT = struct(...
    'savedir',nan,...
    'width',13.8,...
    'height',6.5);

Time = [15 30 90];


%% ===Load statistics of measurements======================================
load(fullfile(dirs.data,'V3WHEELPROFILER_A_STATISTICS.mat'));
yin = [15.53 15.78 16.78 17.78 18.78 19.78 20.78 21.78 22.78 23.78];


%% ===Calculate statistics of XBeach output================================
%---Create structure with XBeach data of dune stretches D11----------------
ind(2*length(yin))=0; k=0;
for i=1:2:2*length(yin);
    k=k+1; a = dims.y(:,1)-yin(k);
    ind(i) = find(a<=0, 1, 'last');
    ind(i+1) = find(a>0, 1, 'first');
end

xb.D11.zb = zb(:,ind(1:20),:);
xb.D11.y = dims.y(ind(1:20),1);
xb.D11.A = tb_calc_A(dims,xb.D11.zb);

%---Interpolate A to profile measurement locations yin---------------------
for j=1:length(yin)
    for i=1:size(zb,1)
        xb.D11.Aint(j,i) = interp1(xb.D11.y,xb.D11.A(i,:),yin(j));
    end
end

%---Calculate mean & standard deviation of A-------------------------------
for t=1:size(zb,1)
    xb.mean(t)=mean(xb.D11.Aint(:,t));
    xb.std(t)=std(xb.D11.Aint(:,t));
end


%% ===Plot statistics======================================================
h = figure; set(h,'units','centimeters'); set(h,'position',[0 0 OPT.width OPT.height]);
haxes = axes('Parent',h); set(haxes,'units','centimeters'); 
set(haxes,'position',[1.5 1 11.8 5]);

    plot(Time,db.mean,'k','Marker','o','MarkerSize',3,'LineStyle','none',...
        'MarkerFaceColor','k'); hold on;
    errorbar(Time,db.mean,db.std,'k','LineStyle','none'); hold on;
    
    plot((dims.t-dims.t(1))/60,xb.mean,'r','LineWidth',0.5); hold on;
    plot((dims.t-dims.t(1))/60,xb.mean-xb.std,'--r',...
        'LineWidth',0.5); hold on;
    plot((dims.t-dims.t(1))/60,xb.mean+xb.std,'--r',...
        'LineWidth',0.5);

    xlim([0 93]); ylim([0 0.08]); xlabel('Time [min]');
    ylabel('$\overline{\textrm{A}}$ [m$^{3}$/m]','Interpreter','latex');
    set(haxes,'YTick',[0.01 0.03 0.05 0.07])
    
xb_write_plot(gcf,dirs.output,'V3MeanA')