function rlookit(data, config, beamnum, reflrange);
% rlookit(data, config, beamnum, reflrange);
% beamnum 1-4
% show vel, sw, amp and measured refl in reflrange (bins)
%
% eg: dd = read(nb,..)
%     [data, config] = restruct(nb, dd);
%     rlookit(data, config, 1, [3 5])

if (nargin ~=4)
   help rlookit
   error('must specify beamnum and refl range')
end

if ~(exist('reflrange'))
   reflrange = [3 8];
end


if (isfield(data,'corr_dday'))
   data.mins = 24*60*(data.corr_dday - data.corr_dday(1));
   dday = data.corr_dday;
   date_str = 'corrected';
else
   data.mins = 24*60*(data.dday - data.dday(1));
   dday = data.dday;
   date_str = 'uncorrected';
end
   
   
config.abc_name = 'mins';
config.xlim = [data.mins(1) data.mins(end)];

reflrange = unique(reflrange);

f1;

%plot velocities
numplots = 4;
clg;whitebg('w')
cfg =aplotit(data, config, 'cur_ax', subplot(numplots,1,1), ...
             'fn', sprintf('vel%d', beamnum));
cfg =aplotit(data, config, 'cur_ax', subplot(numplots,1,2), ...
             'fn', sprintf('amp%d', beamnum));

if (isfield(data,sprintf('sw%d', beamnum)))
   cfg =aplotit(data, config, 'cur_ax', subplot(numplots,1,3), ...
                'fn', sprintf('sw%d', beamnum));
elseif (isfield(data,sprintf('cor%d', beamnum)))
   cfg =aplotit(data, config, 'cur_ax', subplot(numplots,1,3), ...
                'fn', sprintf('cor%d', beamnum));
end


eval(sprintf('vel = data.vel%d;', beamnum))
[vprofile,trefl] = refavg(vel, [reflrange(1):reflrange(2)],3);

ax = subplot(numplots, 1, 4);
h = plot(data.mins, trefl, 'k', 'linewidth', 1);
matchbox(ax, cfg.cur_ax, 'width')
xlabel('minutes')
ylabel('refl vel (m/s)')

date_it

if (length(reflrange) > 1)
   reflstr = sprintf('refl bins = [%d - %d]', reflrange(1), reflrange(2));
else
   reflstr = sprintf('refl bin = %d', reflrange(1));
end


subtitle_comment = ...
    sprintf('BEAM COORDS, raw data, %s, (%s dday %3.3f - %3.3f)',...
            reflstr, date_str, min(dday), max(dday));
subtitle(subtitle_comment)


f2
clf
[vprofile,trefl] = refavg(data.fmeas, [reflrange(1):reflrange(2)],3);
data.resid = data.fmeas - repmat(trefl,length(data.depth), 1);
cfg =aplotit(data, config, 'cur_ax', subplot(211), 'fn','resid');
title('velocity deviations from refavg vprofile')
xlabel('forward measured velocity')


subplot(212)
plot(trefl, data.fmeas(1,:) - trefl,'r.')
hold on
plot(trefl, data.fmeas(2,:) - trefl,'g.')
plot(trefl, data.fmeas(4,:) - trefl,'b.')
plot(trefl, data.fmeas(10,:) - trefl,'k.')
xlabel('forward measured velocity')
ylabel('shear, bin N - refl')
