function varargout = getKustlijn(secTrans,year,gathered,varargin)
%getKustlijn  Get the values for the given coastlijn ordering number.
%
%   Get the values for the given coastlijn ordering number.
%
%   Syntax:
%   varargout  = getKustlijn(secTrans,year,gathered,varargin)
%
%   Input:
%   secTrans   = the combination array of section and transect,
%                section*10^6 + transect
%   year       = available years
%   gathered   = gathering of coast lines
%                index 1: year
%                      2: section
%                      3: transect
%                   rest: values according to ordering number
%   varargin   = the coastline ordering numbers in gathered
%
%   Output:
%   varargout  = the coast line values as asked for, equals the number of
%                varargins
%
%   Example
%
%   See also 

%% Copyright notice
%   --------------------------------------------------------------------
%   Copyright (C) 2010 <COMPANY>
%       Lou Verhage
%
%       <EMAIL>	
%
%       <ADDRESS>
%
%   This library is free software: you can redistribute it and/or
%   modify it under the terms of the GNU Lesser General Public
%   License as published by the Free Software Foundation, either
%   version 2.1 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
%   Lesser General Public License for more details.
%
%   You should have received a copy of the GNU Lesser General Public
%   License along with this library. If not, see <http://www.gnu.org/licenses/>.
%   --------------------------------------------------------------------

% This tool is part of <a href="http://OpenEarth.nl">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: 02 Mar 2010
% Created with Matlab version: 7.8.0.347 (R2009a)

% $Id: getKustlijn.m 4926 2011-04-18 13:00:40Z verhage $
% $Date: 2011-04-18 15:00:40 +0200 (Mon, 18 Apr 2011) $
% $Author: verhage $
% $Revision: 4926 $
% $HeadURL: https://svn.oss.deltares.nl/repos/openearthrawdata/trunk/rijkswaterstaat/kustlijnkaartenboek/scripts/getKustlijn.m $
% $Keywords: $

%%
for n = 1 : nargin-3
    varargout{n} = ones(length(secTrans),length(year))*nan;
end

sz = size(gathered);
for sT = 1 : length(secTrans)
    disp(['secTrans nr=' num2str(sT)]);
    sec   = floor(secTrans(sT) / 1.e6);
    Trans = secTrans(sT) - sec * 1.e6;
    for y = 1 : length(year)
        ind = find(gathered(:,1) == year(y) & gathered(:,2) == sec & gathered(:,3) == Trans);
        if ~isempty(ind)
            for n = 1 : nargin-3
                varargout{n}(sT,y) = gathered(ind,varargin{n});
            end
        end
    end
end

return

