function uvd(lonorlat, bins, vofs)
%
% function uvd(lonorlat, bins, vofs)
% plots u & v at selected bins vs. lon or lat
%
% lonorlat = 1 for longitude on x-axis
%            any other value for latitude on x-axis
% bins = vector of bin numbers to select for plotting
% vofs = vertical offset used to stagger the plots
%
% Example:  uvd(1, [5:10:55], .1)
%           plots u & v at bins 5,15,25,35,45,55
%           with vertical offset .1 m/s
%
% Note:  the correspondence between the bin numbers and depths
%        depends on the ADCP configurations settings:
%
% depth of bin i = transducer_depth + blanking_length +
%                  1/2 (bin_length + pulse_length)    +
%                  (i - 1) * bin_length
%
 
global LONLAT NPRFS ABS_U ABS_V
 
if nargin < 3
  vofs = 0;
end
if nargin < 2
  bins = [5 10 20 30 35];
end
if (lonorlat == 1)
  x = LONLAT(1,:);
  xlab = 'Longitude';
else
  x = LONLAT(2,:);
  xlab = 'Latitude';
end
 
nbins = length(bins);
ofs = [0:nbins-1]' * (-vofs)  * ones(1,NPRFS);
imax = find(x == max(x(find(~isnan(x))))); % label position
 
figure(4)
clf
subplot(211)
plot(x, ABS_U(bins,:) + ofs);
ylabel('u (m/s)')
xlabel(xlab)
for (i = 1 : nbins)
  if (~isnan(ABS_U(bins(i),imax)))
    text(x(imax(1)), ofs(i,1)+ABS_U(bins(i),imax), ['bin ' int2str(bins(i))])
  else
    jmax = find(x == max(x(find(~isnan(ABS_U(bins(i),:))))));
    if (~isempty(jmax))
      text(x(imax(1)), ofs(i,1)+ABS_U(bins(i),jmax(1)), ['bin ' int2str(bins(i))])
    end
  end 
end
title(['Vertical Offset = ' num2str(vofs) ' m/s']);
 
subplot(212)
plot(x, ABS_V(bins,:) + ofs);
ylabel('v (m/s)')
xlabel(xlab)
for (i = 1 : nbins)
  if (~isnan(ABS_V(bins(i),imax)))
    text(x(imax(1)), ofs(i,1)+ABS_V(bins(i),imax), ['bin ' int2str(bins(i))])
  else
    jmax = find(x == max(x(find(~isnan(ABS_V(bins(i),:))))));
    if (~isempty(jmax))
      text(x(imax(1)), ofs(i,1)+ABS_V(bins(i),jmax(1)), ['bin ' int2str(bins(i))])
    end
  end 
end
 
print uvd.ps
