function dune=find_dune(altb,hx,hy)
% DUNE=FIND_DUNE(ALT,X,Y)
%    Finds the exact contour of a dune defined by an inside point (X,Y) in
%    a topography ALT.

lydune=size(altb,1);
lxdune=size(altb,2);
%hx
%hy
%altb
not_finished=1;
dune=zeros(lydune,lxdune);
dune(hy,hx)=1;
np=0;
while not_finished
    n=0;
    for x=1:lxdune
        for y=1:lydune
            if dune(y,x)
                % west exploration
                if x>1 && altb(y,x-1) && ~dune(y,x-1)
                    dune(y,x-1)=1;
                    n=n+1;
                end
                % east exploration
                if x<lxdune && altb(y,x+1) && ~dune(y,x+1)
                    dune(y,x+1)=1;
                    n=n+1;
                end
                % south exploration
                if y>1 && altb(y-1,x) && ~dune(y-1,x)
                    dune(y-1,x)=1;
                    n=n+1;
                end
                % north exploration
                if y<lydune && altb(y+1,x) && ~dune(y+1,x)
                    dune(y+1,x)=1;
                    n=n+1;
                end
            end
        end
    end
    not_finished=n;
    %np=np+1
    %n
end

return;

