function varargout = fnv_xyz2transect(varargin)
%FNV_READXYZ  Interpolate bathymetry (xyz) on jarkus transect
%
%   More detailed description goes here.
%
%   Syntax:
%   varargout = fnv_xyz2transect(varargin)
%
%   Input: For <keyword,value> pairs call fnv_xyz2transect() without arguments.
%   varargin  =
%
%   Output:
%   varargout =
%
%   Example
%   fnv_xyz2transect
%
%   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: 16 Sep 2014
% Created with Matlab version: 8.1.0.604 (R2013a)

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

%%
OPT = struct(...
    'fname', '../data/wadsea_2012.xyz',...
    'posup', -1,...
    'year', [],...
    'jarkus_url', 'http://opendap.deltares.nl/thredds/dodsC/opendap/rijkswaterstaat/jarkus/profiles/transect.nc',...
    'id', 3000500 ...
    );
% return defaults (aka introspection)
if nargin==0;
    varargout = {OPT};
    return
end
% overwrite defaults with user arguments
OPT = setproperty(OPT, varargin);

%% code
% read xyz file
xyz = load(OPT.fname);

% create interpolant
interpolant = scatteredInterpolant(xyz(:,1), xyz(:,2), xyz(:,3));

jtOPT = struct(...
    'url', OPT.jarkus_url,...
    'id', OPT.id,...
    'output', {{'id', 'x', 'y', 'cross_shore'}});
if ~isempty(OPT.year)
    jtOPT.year = OPT.year;
    jtOPT.output{end+1} = 'altitude';
    jtOPT.output{end+1} = 'time';
end
% retreive jarkus transect positions
args = struct2arg(jtOPT);
tr = jarkus_transects(args{:});

% interpolate bathymetry on transects
tr.z = OPT.posup * interpolant(tr.x, tr.y);

varargout = {tr};