function addcoast( coastline, color )
%ADDCOAST    Add coastline to existing axes.
%    ADDCOAST( COASTLINE, COLOR ) draws filled polygons using the given
%    color (defaults to [.7 .5 .1]).  Coastline is an Mx2 element matrix of
%    either [north east] or [latitude longitude] connected points.  ADDCOAST
%    interprets a NaN in either coordinate as the beginning of the next
%    disjoint contour line.
%
%    B. A. Moran, 18-Nov-96

%    Copyright (C) 1995-1998
%    Massachussetts Institute of Technology
%    Sea Grant AUV Laboratory
%    $Id: addcoast.m,v 1.2 1998/10/21 21:43:34 bamoran Exp $	

if nargin < 2
    color = [.7 .5 .1];
end

ii = find( any(isnan(coastline'))' );

if isempty(ii)
    patch( coastline(:,2), coastline(:,1), color );
else
    if ii(1) ~= 1
	ii = [1 ii];			% ensure first element is NaN
    end
    for i = 1 : length(ii) - 1
	mask = ii(i) + 1 : ii(i+1) - 1;
	patch( coastline(mask,2), coastline(mask,1), color );
    end
end

%line( coastline(:,2), coastline(:,1), 'color', 'k' )
