%function [dist,az] = measure();
%function [dist,az] = measure(whichUnits);
function [dist,az] = measure(whichUnits);

if ~nargin, whichUnits = 'utm'; end

% get inputs
[x1,y1] = ginput(1);
if length(x1) < 1, return, end
[x2,y2] = ginput(1);
if length(x2) < 1, return, end

x = [x1 x2];
y = [y1 y2];
	
if strcmp(whichUnits,'utm'),
	dist = sqrt((x(1)-x(2))^2 + (y(1)-y(2))^2);
	az = mod(360+90-rad2deg(atan2(diff(y),diff(x))),360);
elseif strcmp(whichUnits,'geo')
	geoid = selectGeoid;
	dist = distance('rh',y(1),x(1),y(2),x(2),geoid);
	az = azimuth('rh',y(1),x(1),y(2),x(2),geoid);
else
	uiwait(msgbox('Bad units in measure.m','modal'))
	return
end

%measureLineHandle = line(x,y,'Color','b','Marker','o');
try,
	h = findobj(get(gca, 'Children'), 'Tag','measureLine');
	if ~isempty(h),
		set(h,'XData',x,'YData',y);
	else
		line(x,y,'Color','b','Marker','o','Tag','measureLine')
	end
catch, end