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

%% Copyright notice
%   --------------------------------------------------------------------
%   Copyright (C) 2013 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: 21 Feb 2013
% Created with Matlab version: 7.13.0.564 (R2011b)

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

%%
% OPT = struct(...
%     'year', 1926:year(now),...
%     'id', [9010713 7004075],...
%     'url', 'jarkus135_21-Feb-2013.nc');
%
% OPT = setproperty(OPT, varargin, 'onExtraField', 'silentIgnore');

OPT = struct(varargin{:});

nbatch = 50;

transectStruct = jarkus_createtransectstruct();
transectStruct = repmat(transectStruct, 1, 500);
n = 1;

tr = jarkus_transects('output', {'time', 'id', 'x', 'y', 'areaname', 'cross_shore'},...
    varargin{:});
tr.areaname = cellstr(tr.areaname);

b = round(linspace(0, length(tr.id), max(ceil(length(tr.id)/nbatch),2)));
it = 1;
for ii = 2:length(b)
    tri = struct(...
        'id', tr.id(it:b(ii)),...
        'x', tr.x(it:b(ii),:),...
        'y', tr.y(it:b(ii),:),...
        'areaname', {tr.areaname(it:b(ii))},...
        'cross_shore', tr.cross_shore);
    it = b(ii)+1;
    fprintf('transect %i\n', tri.id);
    
    trvk = jarkus_extend_with_vaklodingen(tri, OPT.year);
    
    for jj = 1:size(trvk.altitude,1) % time
        for kk = 1:size(trvk.altitude,2) % alongshore
            transectStruct(n).areaCode = floor(trvk.id(kk)/1e6);
            transectStruct(n).areaName = tri.areaname{kk};
            transectStruct(n).time = trvk.time(jj);
            transectStruct(n).alongshoreCoordinate = mod(trvk.id(kk), 1e6);
            transectStruct(n).year = year(trvk.time(kk)+datenum(1970,1,1));
            nnid = ~isnan(trvk.altitude(jj,kk,:));
            transectStruct(n).n = sum(nnid);
            transectStruct(n).origin = zeros(1, sum(nnid));
            transectStruct(n).crossShoreCoordinate = trvk.cross_shore(nnid);
            transectStruct(n).altitude = trvk.altitude(jj,kk,nnid);
            transectStruct(n).id = trvk.id(kk);
            transectStruct(n).timeTopo = 107;
            transectStruct(n).monthTopo = 7;
            transectStruct(n).dayTopo = 1;
            transectStruct(n).timeBathy = 107;
            transectStruct(n).monthBathy = 7;
            transectStruct(n).dayBathy = 1;
            transectStruct(n).timelims = [datenum(transectStruct(n).year,1,1); datenum(transectStruct(n).year,12,31)] - datenum(1970,1,1);
            n = n +1;
        end
    end
end
transectStruct(n:end) = [];