function varargout = decc_plot_sed_ero_time(varargin)
%DECC_PLOT_SED_ERO_TIME  One line description goes here.
%
%   More detailed description goes here.
%
%   Syntax:
%   varargout = decc_plot_sed_ero_time(varargin)
%
%   Input:
%   varargin  =
%
%   Output:
%   varargout =
%
%   Example
%   decc_plot_sed_ero_time
%
%   See also

%% Copyright notice
%   --------------------------------------------------------------------
%   Copyright (C) 2012 Delft University of Technology
%       Kees den Heijer
%
%       C.denHeijer@TUDelft.nl
%
%       Faculty of Civil Engineering and Geosciences
%       P.O. Box 5048
%       2600 GA Delft
%       The Netherlands
%
%   This library is free software: you can redistribute it and/or modify
%   it under the terms of the GNU General Public License as published by
%   the Free Software Foundation, either version 3 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 General Public License for more details.
%
%   You should have received a copy of the GNU General Public License
%   along with this library.  If not, see <http://www.gnu.org/licenses/>.
%   --------------------------------------------------------------------

% This tool is part of <a href="http://www.OpenEarth.eu">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: 07 Feb 2012
% Created with Matlab version: 7.12.0.635 (R2011a)

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

%%
OPT = struct(...
...    'maindir', 'p:\1002266-xbeach\coastal_curvature\simulations\00000000\xbeach\run26\',...
    'maindir', 'E:\Sources\OpenEarthModels\tudelft\dune_erosion_coastline_curvature\simulations\',...
    'angle', 45,...
    'regexp_select', 'run(26).*2714.*xb.*.nc',...
    'regexp_legend', 'run\d{2}.*?radius\d{4,5}(.*?rev\d{4}\D?)?',...
    'strrep_legend', {{{'\' '; '} {'s0' 's '} {'00' '00 m'}}},...
    'save', false ...
    );

OPT = setproperty(OPT, varargin);

%%
[dirs dircont files] = dirlisting(OPT.maindir);

fid = ~cellfun(@isempty, regexp(files, OPT.regexp_select));

ncfiles = files(fid);

%{
fprintf('%s\n', ncfiles{:});
%}

% calcdirs = dir(fullfile(OPT.maindir, 'radius*'));

for iradii = 1:length(ncfiles)
    ncfile = ncfiles{iradii};
%     ncfile = fullfile(OPT.maindir, calcdirs(iradii).name, 'xboutput.nc');
    [Ero(:,iradii) Sed(:,iradii) t(:,iradii)] = decc_ero_sed_time(...
        'ncfile', ncfile,...
        'angle', OPT.angle);
end

legendtxt = cellfun(@(x) regexp(x, OPT.regexp_legend, 'match'), ncfiles);
for ilegrep = 1:length(OPT.strrep_legend)
    legendtxt = cellfun(@(x) strrep(x, OPT.strrep_legend{ilegrep}{:}), legendtxt,...
        'UniformOutput', false);
end

%%
figure
subplot(2,1,1)
plot(t, -Ero)
title(sprintf('Erosion @ %i degrees', OPT.angle))
lh = legend(legendtxt{:});
set(lh, 'location', 'NorthWest')

subplot(2,1,2)
plot(t, Sed)
title(sprintf('Sedimentation @ %i degrees', OPT.angle))
lh = legend(legendtxt{:});
set(lh, 'location', 'NorthWest')