function [meshnodnew,bathynew]=putnodes(L,meshnod,bathy)
% [meshnodnew,bathynew]=putnodes(L,meshnod,bathy)
%  input a bunch of points with cursor
% terminate by clicking to too small an x
% L = min and max for x,y axis
% meshnod is  old data point array  [OPTIONAL]
%
disp(['putnodes:  Add extra nodes  Average nearby depths'])
disp(['click a spot and drop a point there'])


if nargin>1
x = meshnod(:,2);
y = meshnod(:,3);
bathynew = bathy;
else
x = [];
y = [];
bathynew = [];
end


clf
plot(x,y,'g*')
axis(L)
axis('equal')
grid
title('putpoints')

pbquit = uicontrol(gcf,'Style','radio','String','QUIT' ...
 ,'units','normalized','position',[.02 .045 .107 .047] );

xin = (L(1)+L(2))/2.;
hold on

while(1)
[xin,yin]=ginput(1);
drawnow
% get(pbquit,'value')

plot(xin,yin,'r*')

if get(pbquit,'value')
  disp('  QUIT movenod')
  break
end

% find average depth of nearbys
lx = length(x);
if lx<10
bin = -10;
else

d = (x-xin).^2+(y-yin).^2;
[ds,dl]=sort(d);
dl = dl(1:10);
d = 1 ./(d(dl));
d = d/sum(d);
bin = sum(d.*bathynew(dl,2));
end


x=[x; xin];
y = [y; yin];
lx = length(x);
bathynew(lx,1) = lx;
bathynew(lx,2) = bin;
end

hold off
meshnodnew = [[1:length(x)]' x y];
delete(pbquit)
