function [A,B,hits]=dobin(cdf1,u1,v1,cdf2,u2,v2) 
%function [A,B,hits]=dobin(cdf1,u1,v1,cdf2,u2,v2) 
% DOBIN script
% DO a BINsort of current meter velocity on the east and north wind
% components.
%
%cdf1='3391-a1hlp.cdf';              % 3391 winter upper, 3392 winter lower
%cdf2='44013s-alp.cdf';              % wind record
xbins=[-4:1:4];
ybins=[-4:1:4];
axlim=[-4 4 -4 4];
%
% get start and stop times from overlap
%
[start_time,stop_time]=overlap(cdf1,cdf2);
%
% find start and end cycles based on start and stop times
%
[icyc,ncyc]=mctime(cdf1,start_time,stop_time);
wu=mcvgt(cdf1,u1,icyc,ncyc);
wv=mcvgt(cdf1,v1,icyc,ncyc);
wu=plfilt(wu);
wv=plfilt(wv);
%
[icyc,ncyc]=mctime(cdf2,start_time,stop_time);
u=mcvgt(cdf2,u2,icyc,ncyc);
v=mcvgt(cdf2,v2,icyc,ncyc);
u=plfilt(u);
v=plfilt(v);
%
[A,hits,xc,yc]=binsort(wu,wv,u,xbins,ybins);
[B,hits,xc,yc]=binsort(wu,wv,v,xbins,ybins);
%
% PLOTTING STUFF
%
hold off
axis('square')
axis(axlim)
[xx,yy]=meshdom(xc,yc);
%arrows(xx(:),yy(:),A(:),B(:),.1,.1,'g-')
%grid
%xlabel('u wind (dyn/cm2)')
%ylabel('v wind (dyn/cm2)')
% title('Water velocity sorted on wind');
% text(0.70,0.25,file_lbl(cdf2),'sc');
% text(0.70,0.21,date_lbl(start_time,stop_time),'sc');
% text(0.70,0.17,depth_lbl(cdf2,'east'),'sc');
%if (exist('bin.met')~=2),
%   meta bin
%else
%   meta
%end
 showvar(xx(:),yy(:),hits(:))
 grid
 xlabel('u wind (dyn/cm2)')
 ylabel('v wind (dyn/cm2)')
 title(['Hits per bin ' cdf2(1:4)])
 if (exist('hit.met')~=2),
    meta hit
 else
    meta
 end
