function [R, yyyy] = calc_Rt_trda2006(varargin)
%CALC_RT_TRDA2006  calculate R vs t according to the trda 2006 method.
%
%   More detailed description goes here.
%
%   Syntax:
%   varargout = calc_Rt_trda2006(varargin)
%
%   Input: For <keyword,value> pairs call calc_Rt_trda2006() without arguments.
%   varargin  =
%
%   Output:
%   varargout =
%
%   Example
%   calc_Rt_trda2006
%
%   See also

%% Copyright notice
%   --------------------------------------------------------------------
%   Copyright (C) 2014 Deltares
%       Kees den Heijer
%
%       Kees.denHeijer@deltares.nl
%
%       Deltares
%       P.O. Box 177
%       2600 MH 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: 25 Mar 2014
% Created with Matlab version: 8.1.0.604 (R2013a)

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

%%
OPT = struct(...
    'AdditionalErosion', true, ...
    'id', 7004325,...
    'url', 'http://dtvirt5.deltares.nl:8080/thredds/dodsC/opendap/rijkswaterstaat/jarkus/profiles/transect_r2013_filled.nc', ... 'http://dtvirt5.deltares.nl:8080/thredds/dodsC/opendap/rijkswaterstaat/jarkus/profiles/transect_r2013_filled.nc',...
    'plot', false);

OPT = setproperty(OPT, varargin);

%%
t = datevec(nc_cf_time(OPT.url, 'time'));
yyyy = t(:,1);

tr = jarkus_transects(...
    'url', OPT.url,...
    'id', OPT.id);

bc = get_hr_boundaryconditions(...
    'id', OPT.id,...
    'datadir', fullfile(fileparts(mfilename('fullpath')), '..', 'data'));

DuneErosionSettings('set',...
    'AdditionalErosion', OPT.AdditionalErosion,...
    'AdditionalVolume', '0.25*Volume', ...
    'BoundaryProfile', false);

nnid = ~isnan(tr.altitude);
aidx = 1;

for iy = 1:length(yyyy)
    crid = squeeze(nnid(iy,aidx,:));
    z = squeeze(tr.altitude(iy,aidx,crid));
    x = tr.cross_shore(crid);
    if ~isempty(z)
        result = DUROS(x(:),z(:),'D50', bc.D50, 'WL_t', bc.Rp, 'Tp_t', bc.Tp, 'Hsig_t', bc.Hs);
        if ~isempty(result(1).VTVinfo.Xr) && ~OPT.AdditionalErosion
            R(iy) = result(1).VTVinfo.Xr;
        elseif ~isempty(result(3).VTVinfo.Xr) && OPT.AdditionalErosion
            R(iy) = result(3).VTVinfo.Xr;
        else
            R(iy) = NaN;
        end
    else
        R(iy) = NaN;
    end
end

if OPT.plot
    plot(yyyy, R, 'o')
end