function [pointLdb1,pointLdb2] = getDistance(ldb1,ldb2,buffer)
%GETDISTANCE  get the distances between points of two ldb's.
%
%   Get the distances between points of two ldb's.
%
%   Syntax:
%   [pointLdb1,pointLdb2] = getDistance(ldb1,ldb2,buffer)
%
%   Input:
%   ldb1,ldb2 = the two ldb's to be used
%   buffer    = the maximum distance two set the position of points to
%               equal
%
%   Output:
%   pointLdb1, pointLdb2 = the indices of ldb's that are within the asked
%                          distance
%
%   Example
%   getDistance
%
%   See also 

%% Copyright notice
%   --------------------------------------------------------------------
%   Copyright (C) 2010 Deltares
%       Lou Verhage
%
%       lou.verhage@deltares.nl	
%
%       Deltares
%       P.O. Box 177
%       2600MH Delft
%       Tel: +31 (0)88 335  8273
%       
%       Visiting adress:
%       Rotterdamseweg 185
%       2629 HD Delft
%       Tel: +31 (0)88 335  8276
%
%   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: 20 Dec 2010
% Created with Matlab version: 7.8.0.347 (R2009a)

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

%%

mm = ones(length(ldb1.x),length(ldb2.x),1)* NaN;

minimum = -1;
for n = 1 : length(ldb1.x)
    for m = 1 : length(ldb2.x)
        mm(n,m) = sqrt((ldb1.x(n)-ldb2.x(m))^2 +(ldb1.y(n)-ldb2.y(m))^2);
        if minimum < 0
            minimum = mm(n,m);
        else
            minimum = min(minimum,mm(n,m));
        end
    end
end
[pointLdb1,pointLdb2] = find (mm <= buffer);
