function varargout = fnv_plot_wadsea_transects(varargin)
%FNV_PLOT_WADSEA_TRANSECTS  One line description goes here.
%
%   More detailed description goes here.
%
%   Syntax:
%   varargout = fnv_plot_wadsea_transects(varargin)
%
%   Input: For <keyword,value> pairs call fnv_plot_wadsea_transects() without arguments.
%   varargin  =
%
%   Output:
%   varargout =
%
%   Example
%   fnv_plot_wadsea_transects
%
%   See also

%% Copyright notice
%   --------------------------------------------------------------------
%   Copyright (C) 2014 Deltares
%       Joost den Bieman
%
%       joost.denbieman@deltares.nl
%
%       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: 29 Sep 2014
% Created with Matlab version: 8.2.0.701 (R2013b)

% $Id: fnv_plot_wadsea_transects.m 592 2014-09-30 12:16:29Z heijer $
% $Date: 2014-09-30 14:16:29 +0200 (Tue, 30 Sep 2014) $
% $Author: heijer $
% $Revision: 592 $
% $HeadURL: https://svn.oss.deltares.nl/repos/openearthmodels/trunk/deltares/future_nourishment_volumes/scripts/fnv_plot_wadsea_transects.m $
% $Keywords: $

%% Settings
OPT = struct(   ...
    'jarkus_url', 'http://opendap.deltares.nl/thredds/dodsC/opendap/rijkswaterstaat/jarkus/profiles/transect.nc',...
    'JarkusID',     []  ...
);

OPT = setproperty(OPT, varargin{:});

%% Get IDs
ids             = nc_varget(OPT.jarkus_url,'id');
DeltaFilter    = ids > 12000000 & ids < 18000000;

dateFcn = @(s) datenum( regexp(s,'(?<=kzd)\d{4}(?=\.xyz)','match'), 'yyyy');

fname0 = fnv_transects2nc('fname', '../data/kzd2006.xyz','id',ids(DeltaFilter), 'year', 2006, 'dateFcn', dateFcn);
fname1 = fnv_transects2nc('fname', '../data/kzd2035.xyz','id',ids(DeltaFilter), 'year', 2006, 'dateFcn', dateFcn);
fname2 = fnv_transects2nc('fname', '../data/kzd2100.xyz','id',ids(DeltaFilter), 'year', 2006, 'dateFcn', dateFcn);

alt0 = nc_varget(fname0, 'altitude');
altm0 = nc_varget(fname0, 'altitude_model');
id0 = nc_varget(fname0, 'id');
lat = nc_varget(fname0, 'rsp_lat');
lon = nc_varget(fname0, 'rsp_lon');

alt1 = nc_varget(fname1, 'altitude');
altm1 = nc_varget(fname1, 'altitude_model');
id1 = nc_varget(fname1, 'id');

alt2 = nc_varget(fname2, 'altitude');
altm2 = nc_varget(fname2, 'altitude_model');
id2 = nc_varget(fname2, 'id');
dz = squeeze(altm1(end,:,:) - altm0);

figure(1)
plot(max(abs(dz),[], 2))
threshold = 3;
hold on
hline(threshold);
idx = max(abs(dz),[], 2) > threshold;

dzmax = max(abs(dz),[], 2);

labels = cellfun(@(i) sprintf('%i', i), num2cell(id0(idx)), 'UniformOutput', false);
KMLscatter(lat(idx), lon(idx), dzmax(idx),...
    'fileName', 'test.kml',...
    'name',labels)

figure(2)
pcolor(squeeze(dz));
shading interp