function h = tb_V4Fullpage(dims,zb,dirs)
%UNTITLED  Created a spatial overview of DeltaR & A at t = 90 min
%
%   Syntax:
%   h = tb_V4Fullpage(dims,zb)
%
%   Input:      XBeach structure with dimensions & initial and final 
%               bottom data
%   Output:     Spatial overview (h)%
%
%   Example
%   tb_V4Fullpage(dims,[xb.data(1,2).value(1,:,:); xb.data(1,2).value(end,:,:)]);
%
%   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',22.8,...
    'height',12.2);


%% ===Load measurements of DeltaR* & A=====================================
DBDR = load(fullfile(dirs.data,'V4ARGUS_DELTAR_FULL.mat'));
DBDRWP = load(fullfile(dirs.data,'V4WHEELPROFILER_DELTAR.mat'));

yin = [3.78 4.03 4.53 4.78 5.28 5.78 6.03 6.53 6.78 15.53 15.78 16.78 17.78 18.78 19.78 20.78 21.78 22.78 23.78];
load(fullfile(dirs.data,'V4WHEELPROFILER_A.mat'));


%% ===Calculate DeltaR* & A from XBeach output=============================
%---Find y-indices of begin & end y-coordinate of structures---------------
Ind_Dune = [find(dims.y(:,1)==15.28) find(dims.y(:,1)==25.42)];
Ind_DuneRev = [find(dims.y(:,1)==3.53) find(dims.y(:,1)==7.03)];
Ind_Breach = [find(dims.y(:,1)==5.03) find(dims.y(:,1)==5.53)];

%---Calculate DeltaR* & A--------------------------------------------------
XBDR = tb_calc_DeltaR(dims,zb);
XBA = tb_calc_A(dims,zb);


%% ===Plot spatial overview================================================
h = figure; set(h,'units','centimeters'); set(h,'position',[0 0 OPT.width OPT.height]);

h(1) = subplot(2,1,1); set(h(1),'units','centimeters'); set(h(1),'position',[1.8 7.5 20.1 4.1]);
hold(h(1),'on'); box on; grid on;

plot(dims.y(Ind_Dune(1):Ind_Dune(2),1),XBDR(end,Ind_Dune(1):Ind_Dune(2)),'r'); 
plot(DBDR.Y.Dune,DBDR.DeltaR(1,3).Dune(:,end),'b');
        
plot(dims.y(Ind_DuneRev(1):Ind_DuneRev(2),1),XBDR(end,Ind_DuneRev(1):Ind_DuneRev(2)),'r'); 
plot(DBDR.Y.DuneRev,DBDR.DeltaR(1,3).DuneRev(:,end),'b');

plot(yin,DBDRWP.DeltaR_WP(3,:),'k','Marker','o','LineStyle','none','MarkerFaceColor','k','MarkerSize',5);

xlim([0 26.42]); ylim([0 0.50]);
ylabel('$\Delta$R$^\textrm{*}$ [m]','Interpreter','latex');

% Structures
Faces = [1 2 3; 2 3 4; 5 6 7; 6 7 8; 9 10 11; 10 11 12;];
Verts = [0 min(ylim); 0 max(ylim); 3.53 min(ylim); 3.53 max(ylim); ...
         7.03 min(ylim); 7.03 max(ylim); 15.28 min(ylim); 15.28 max(ylim); ...         
         25.42 min(ylim); 25.42 max(ylim); 26.42 min(ylim); 26.42 max(ylim)];
    
ps = patch('Faces',Faces,'Vertices',Verts,'FaceAlpha',0.4,'LineWidth',1,...
    'FaceColor',[0 0 0],'EdgeColor','none');

%Removed data
Faces = [1 2 3; 2 3 4; 5 6 7; 6 7 8; 9 10 11; 10 11 12; 13 14 15; 14 15 16; 17 18 19; 18 19 20];
Verts = [3.53 min(ylim); 3.53 max(ylim); 3.58 min(ylim); 3.58 max(ylim); ...
         6.93 min(ylim); 6.93 max(ylim); 7.03 min(ylim); 7.03 max(ylim); ...
         15.28 min(ylim); 15.28 max(ylim); 15.48 min(ylim); 15.48 max(ylim); ...
         17.57 min(ylim); 17.57 max(ylim); 18.1 min(ylim); 18.1 max(ylim); ...
         24.18 min(ylim); 24.18 max(ylim); 25.42 min(ylim); 25.42 max(ylim)];
     
pr = patch('Faces',Faces,'Vertices',Verts,'FaceAlpha',0.4,'LineWidth',1,...
    'FaceColor',[0.7 0.7 0.7],'EdgeColor','none');

v2 = vline([3.53 5.03 5.53 7.03 15.28 25.42],'-k');

annotation(gcf,'textbox',[0.125 0.97 0.03 0.03],'String',{'H11'},'FitBoxToText','off','LineStyle','none','FontSize',8);
annotation(gcf,'textbox',[0.202 0.97 0.03 0.03],'String',{'DR11'},'FitBoxToText','off','LineStyle','none','FontSize',8);
annotation(gcf,'textbox',[0.238 0.97 0.03 0.03],'String',{'B11'},'FitBoxToText','off','LineStyle','none','FontSize',8);
annotation(gcf,'textbox',[0.266 0.97 0.03 0.03],'String',{'DR12'},'FitBoxToText','off','LineStyle','none','FontSize',8);
annotation(gcf,'textbox',[0.440 0.97 0.03 0.03],'String',{'H12'},'FitBoxToText','off','LineStyle','none','FontSize',8);
annotation(gcf,'textbox',[0.750 0.97 0.03 0.03],'String',{'D11'},'FitBoxToText','off','LineStyle','none','FontSize',8);
annotation(gcf,'textbox',[0.927 0.97 0.03 0.03],'String',{'R11'},'FitBoxToText','off','LineStyle','none','FontSize',8);


h(2) = subplot(2,1,2); set(h(2),'units','centimeters'); set(h(2),'position',[1.8 1.5 20.1 4.1]);
hold(h(2),'on'); box on; grid on;

plot(dims.y(Ind_Dune(1):Ind_Dune(2),1),XBA(end,Ind_Dune(1):Ind_Dune(2)),'r');
plot(dims.y(Ind_DuneRev(1):Ind_DuneRev(2),1),XBA(end,Ind_DuneRev(1):Ind_DuneRev(2)),'r');
plot(yin,ADB(3,:),'k','Marker','o','LineStyle','none','MarkerFaceColor','k','MarkerSize',5); 

xlim([0 26.42]); ylim([0 0.09]);
ylabel('A [m$^{3}$/m]','Interpreter','latex'); xlabel('y [m]');

% Structures
Faces = [1 2 3; 2 3 4; 5 6 7; 6 7 8; 9 10 11; 10 11 12;];
Verts = [0 min(ylim); 0 max(ylim); 3.53 min(ylim); 3.53 max(ylim); ...
         7.03 min(ylim); 7.03 max(ylim); 15.28 min(ylim); 15.28 max(ylim); ...         
         25.42 min(ylim); 25.42 max(ylim); 26.42 min(ylim); 26.42 max(ylim)];
    
ps = patch('Faces',Faces,'Vertices',Verts,'FaceAlpha',0.4,'LineWidth',1,...
    'FaceColor',[0 0 0],'EdgeColor','none');

%Removed data
Faces = [1 2 3; 2 3 4; 5 6 7; 6 7 8; 9 10 11; 10 11 12; 13 14 15; 14 15 16; 17 18 19; 18 19 20];
Verts = [3.53 min(ylim); 3.53 max(ylim); 3.58 min(ylim); 3.58 max(ylim); ...
         6.93 min(ylim); 6.93 max(ylim); 7.03 min(ylim); 7.03 max(ylim); ...
         15.28 min(ylim); 15.28 max(ylim); 15.48 min(ylim); 15.48 max(ylim); ...
         17.57 min(ylim); 17.57 max(ylim); 18.1 min(ylim); 18.1 max(ylim); ...
         24.18 min(ylim); 24.18 max(ylim); 25.42 min(ylim); 25.42 max(ylim)];
     
pr = patch('Faces',Faces,'Vertices',Verts,'FaceAlpha',0.4,'LineWidth',1,...
    'FaceColor',[0.7 0.7 0.7],'EdgeColor','none');

v2 = vline([3.53 5.03 5.53 7.03 15.28 25.42],'-k');

annotation(gcf,'textbox',[0.125 0.48 0.03 0.03],'String',{'H11'},'FitBoxToText','off','LineStyle','none','FontSize',8);
annotation(gcf,'textbox',[0.202 0.48 0.03 0.03],'String',{'DR11'},'FitBoxToText','off','LineStyle','none','FontSize',8);
annotation(gcf,'textbox',[0.238 0.48 0.03 0.03],'String',{'B11'},'FitBoxToText','off','LineStyle','none','FontSize',8);
annotation(gcf,'textbox',[0.266 0.48 0.03 0.03],'String',{'DR12'},'FitBoxToText','off','LineStyle','none','FontSize',8);
annotation(gcf,'textbox',[0.440 0.48 0.03 0.03],'String',{'H12'},'FitBoxToText','off','LineStyle','none','FontSize',8);
annotation(gcf,'textbox',[0.750 0.48 0.03 0.03],'String',{'D11'},'FitBoxToText','off','LineStyle','none','FontSize',8);
annotation(gcf,'textbox',[0.927 0.48 0.03 0.03],'String',{'R11'},'FitBoxToText','off','LineStyle','none','FontSize',8);

xb_write_plot(gcf,dirs.output,'V4SpatialOverview')