function h = tb_V1AMean(dims,zb,dirs)
%tb_V1AMean: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_V1AMean(dims,zb)
%
%   Input:      XBeach structure with dimensions & bottom data
%   Output:     Figure of time development of mean A (h)
%
%   Example
%   h = tb_V1AMean(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,'V1WHEELPROFILER_A_STATISTICS.mat'));
yin = [2.53 4.03 4.78 5.03 5.28 19.53 19.78 20.03 20.78 22.28];


%% ===Calculate statistics of XBeach output================================
%---Create structure with XBeach data of dune stretches D1 & D2------------
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.D1.zb = zb(:,ind(1:10),:);
xb.D1.y = dims.y(ind(1:10),1);
xb.D1.A = tb_calc_A(dims,xb.D1.zb);

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

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

%---Calculate mean & standard deviation of A-------------------------------
for t=1:size(zb,1);
    xb.mean(t)=mean([xb.D1.Aint(:,t); xb.D2.Aint(:,t)]);
    xb.std(t)=std([xb.D1.Aint(:,t); xb.D2.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.075]); 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,'V1MeanA')