function dig=dig_grid(x,y)
%function [dig]=dig_grid(x,y)
% DIG_GRID allows digitization of 4 boundary segments to use with
%        the curvilinear orthogonal grid generation 
%        program NCARGRID.  
%
%        x,y are the coastline coordinates
%        dig are the returned digitized points  (with the corners
%            denoted by a "1" in the third column)
%
%    
% USAGE: press first mouse button to digitize a point on the boundary
%        press second mouse button to digitize a corner
%        press third mouse button to quit (the program will quit
%        automatically after 4 points have been entered).
%
% NOTES: the "corners" are defined at the END of the boundary
%        segment.  You should try to make the corners fairly 
%        orthogonal, or you might not get convergence when you
%        run NCARGRID.
%
mbi=1;
plot(x,y);
i=0;
hold on;
k=0;
while mbi~=3,
    i=i+1;
    [xa,ya,mbi]=ginput(1);
    if(mbi==3),hold off;return,end
    dig(i,1)=xa;
    dig(i,2)=ya;
    dig(i,3)=mbi-1;
    if (mbi==1),
      plot(xa,ya,'gx')
    elseif (mbi==2),
      plot(xa,ya,'wo')
      k=k+1;
      if(k==4),mbi=3;hold off;return,end
   end
end
