function [piddat, pt] = replotHeights(piddat, pt, region, datum, varargin)
% function [piddat, pt] = replotHeights(piddat, pt, region, datum, ...
%                         [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:
%   piddat  name of point and datum (cell array)
%           1 pid (non-unique)
%           2 datum
%   pt      dimensions (#piddat x 3)
%           1-2 lat/long (deg)
%           3   height (m)
% input:
%   region          name of geographic region, see 'drawBoundaries'
%                     for list of regions
%   datum           requested datum (88, 29, or empty for all datums)
% optional input:
%   scale           scale factor for vectors (default: 1)
%   elimPtFile      file containing PIDs for eliminated points


% set path to helper plotting toolboxes
VERTCONpath;

% % 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

barmap = 'hsv';

% 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

% find the requested datum
switch num2str(datum)
    case '88'
        q = strcmp(piddat{2}, '88');
    case '29'
        q = strcmp(piddat{2}, '29');
    otherwise 
        error('must specify datum of 88 or 29');
        q = [1:length(piddat{2})];
end
n = length(find(q==1));

% plot the points
%plot(pt(q,2)-360, pt(q,1),'o');
scatter(pt(q,2)-360, pt(q,1),[],pt(q,3),'filled');
colorbar
%%linkdata on
axis equal
grid on
%title(fname);
xlabel('E long (deg)');
ylabel('N lat (deg)');
title(sprintf('DATUM %s', num2str(datum)));

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

% 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
