function [pid, pt] = replotVectors(pid, pt, region, varargin)
% function [pid, pt] = replotVectors(pid, pt, region, [scale], [elimPtFile])
% 
% when datafile has been previously read in,
% use this function to plot vectors onto
% regional basemap; activates tooltip window to describe
% point information (PID, lat/lon, etc)
% 
% pid and pt are both input and output because 'pt' may be
% altered by inclusion of elimPtFile
% 
% input/output:
%   pid           name of points (PIDs)
%   pt            dimensions (#PID x 4)
%                   1-2 lat/long (deg)
%                   3   azimuth (deg)
%                   4   vector length (m)
% input:
%   region          name of geographic region, see 'drawBoundaries'
%                     for list of regions
% optional input:
%   scale           scale factor for vectors (default: 1)
%   elimPtFile      file containing PIDs for eliminated points


%close all; % close all open windows
NADCONpath; % supplement path with toolboxes needed for NADCON

% set vector scale
scl = 1;
if (nargin>3 & ~isempty(varargin{1}))
    scl = varargin{1};
end

% delete points already eliminated
if (nargin>4)
    ptB = elimPoints(pt, pid, varargin{2});
    pt=ptB;
end

% plot the vectors
figure

%fprintf 'Dru, inside of replotVectors, here is region: '
%disp(region);

r = drawBoundaries(region);
if ~isempty(r)
    pt = [pt; [r(1) r(2) 90 1]]; % 1-meter reference vector, for plot
end
v = [pt(:,4).*sind(pt(:,3)) pt(:,4).*cosd(pt(:,3))];
quiver(pt(:,1)-360, pt(:,2), v(:,1),v(:,2), scl)
%%linkdata on
axis equal
grid on
%title(fname);
xlabel('E long (deg)');
ylabel('N lat (deg)');

% turn on PID labels using datacursor
hdt = datacursormode;
set(hdt,'DisplayStyle','window');
% Declare a custom datatip update function 
% to display PID:
set(hdt,'UpdateFcn',{@labelPIDv,[pt(:,1)-360, pt(:,2:4)],pid})

% http://www.mathworks.com/matlabcentral/answers/95968-how-can-i-set-the-text-font-style-of-a-data-cursor-object
% alldatacursors = findall(gcf,'type','hggroup');
% set(alldatacursors, 'fontsize',14);

return
