function apuv(data, config, topo_clev, mvec_scale, pfc)
% apuv(data, config, topo_clev, mvec_scale, pfc)
% it's a function so we don't pollute the colorbar

% a tool to plot lon and lat vs time; and cruise track with
% reference layer velocities

% Jules 2000/11/27

%if no flags defined, use no flags
if (~isfield(config, 'flagged'))
   config.flagged = zeros(size(data.umeas));
end

set(0, 'defaulttextinterpreter', 'tex')


toofast = 15;  %15m/s too fast ship speed

%try to filter positions a bit
badi = find(data.clmps > toofast);  %
if (~isempty(badi))
   warning('found potential bad navigation at:')
   fprintf('    dday                   lat                   lon\n')
   fprintf('%11.7f       %14.7fN     %14.7fE\n',...
                [data.dday(badi)', data.lat(badi)', data.lon(badi)'])
                data.lon(badi) = [];
                data.lat(badi) = [];
                data.dday(badi) = [];
                data.uabs_refl_sm(badi) = [];
                data.vabs_refl_sm(badi) = [];
                config.flagged(:,badi)=[];
end


%% replace old code with this:
%get the map ranges
[lonlims, latlims] = map_range(data.lon, data.lat);

clf
%add a positions
subplot(411)
plot(data.dday, data.lon)
lltick(gca, 'y', 'lon');
set(gca, 'xtick', [])
set(gca, 'ylim', lonlims);
text(mstdgap(data.dday), mstdgap(data.lon), 'LONGITUDE')


subplot(412)
plot(data.dday, data.lat)
lltick(gca, 'y', 'lat');
text(mstdgap(data.dday), mstdgap(data.lat), 'LATITUDE')
xlabel('dday')
set(gca, 'ylim', latlims);
pos = get(gca,'pos');
set(gca, 'pos', pos + [0 .03 0 0]); 


if (~exist('m_elev','file'))
   fprintf('cannot show topography')
   fprintf('please download m_map from Rich Pawlowicz page at\n')
   fprintf('http://www.ocgy.ubc.ca/~rich')
else
   subplot(212)

   %use sstopo if we're north of 70deg
   if ( (latlims(1) < -70) | (latlims(2) > 70) | ~exist('ss_block','file'))
      %see whether there's any topography
      [topog, top_lon, top_lat]=m_elev([ lonlims latlims]  + [-1 1 -1 1]);
      top_lon = top_lon(1,:);
      top_lat = top_lat(:,1)';
      % lon-clipping bug in m_map:
      [topog top_lon] = m_fixlon(top_lon, top_lat, topog, lonlims);  
   else %use ss_block if it exists and if we're inside +/- 70
      num_tpts = 32*diff(latlims)*32*diff(lonlims);
      if (num_tpts < 10000)
         nsub = 1;
      elseif (num_tpts < 30000)
         nsub = 3;
      else
         nsub = 9;
      end
      
      eval('[top_lon, top_lat, topog] = ss_block(lonlims + [-1 1] , latlims + [-1 1], nsub);')
      
   end
      
   %set up the colors
   topo_cmap = mk_cmap(length(topo_clev), 'topo');
   topo_irange =  [1 length(topo_cmap(:,1))]; % indices into topo_cmap
   colormap([topo_cmap])
   
   
   m_proj('lambert', 'long' ,lonlims, 'lat', latlims);
   m_contourf(top_lon, top_lat, topog,  topo_clev);
   m_grid('box','fancy','tickdir','in');
   %m_coast;
   
   notflagged = (config.flagged == 0);
   rlbins = config.rl_range(1) : config.rl_range(2);
   numgoodbins = sum(notflagged(rlbins,:));
   goodi = find(numgoodbins >= pfc.cfg.badpgrefl_nbins);
   
   
   if (~isempty(goodi))
      [hp,ht]=m_vec(mvec_scale,...
                    data.lon(goodi),data.lat(goodi),...
                    data.uabs_refl_sm(goodi),...
                    data.vabs_refl_sm(goodi),...
                    'shaftwidth',.1);
      set(hp,'facecolor','r')
      set(hp,'edgecolor','r')
   end
   
   
   %navtimes = NaN*data.lon;
   %m_track(data.lon, data.lat, navtimes, 'color', 'g', 'linewidth', 2);
   m_line(data.lon, data.lat, 'color', 'g', 'linewidth', 2);
   
   h_dcb = dcolbar( topo_clev/1000, 'vert', 'Depth (km)');
   h_dcbp = findobj(h_dcb,'Type','patch');
   cf_index(h_dcbp, topo_clev/1000, topo_irange);
end



date_it
subtitle(config.comment)
