%function origin = nav_quiver(navFile,whichMap,nSeconds)
%  origin is [east north]
function navQuiver(navFile,whichMap,nSeconds)
	global origin
	
if ~nargin, whichMap = 'utm'; end

if strcmp(whichMap,'utm'),

	if ( exist([navFile '.mat']) == 2 )
		load(navFile)
		if exist('renavigation'), navigation = renavigation; end
		if isempty(origin),
			origin = [navigation.mEastings(1),navigation.mNorthings(1)];
		end
	elseif ( exist([navFile '.m']) == 2 )
		eval(navFile)
		if exist('renavigation'), navigation = renavigation; end
		if isempty(origin),
			origin = [navigation.mEastings(1),navigation.mNorthings(1)];
		end
	else
		return
	end

	figure(gcf)
	plot(navigation.mEastings-origin(1),navigation.mNorthings-origin(2), ...
		'r-','LineWidth',2.5)
	grid on
	hold on

	if nargin < 3, nSeconds = 10; end

	ii = 1:nSeconds*5:length(navigation.time);
	x = navigation.mEastings(ii)-origin(1);
	y = navigation.mNorthings(ii)-origin(2);
	if ( isfield(navigation,'yaw') )
		u = sin(navigation.yaw(ii));
		v = cos(navigation.yaw(ii));
	elseif ( isfield(navigation,'mYaw') )
		u = sin(navigation.mYaw(ii));
		v = cos(navigation.mYaw(ii));		
	end
	
	quiver(x,y,u,v,0.25)
	hold off

elseif strcmp(whichMap,'geo'),

	origin = [];
	if ( exist([navFile '.mat']) == 2 )
		load(navFile)
		if exist('renavigation'), navigation = renavigation; end
	elseif ( exist([navFile '.m']) == 2 )
		eval(navFile)
		if exist('renavigation'), navigation = renavigation; end
	else
		return
	end

	figure(gcf)
	if ( isfield(navigation,'longitude') )
		plot(navigation.longitude,navigation.latitude, ...
			'r-','LineWidth',2.5)
	elseif ( isfield(navigation,'mLongitude') )
		plot(navigation.mLongitude,navigation.mLatitude, ...
			'r-','LineWidth',2.5)
	end
	grid on
	hold on

	if nargin < 3, nSeconds = 10; end

	i = 1:nSeconds*5:length(navigation.time);
	if ( isfield(navigation,'longitude') )
		x = navigation.longitude(i);
		y = navigation.latitude(i);
	elseif ( isfield(navigation,'mLongitude') )
		x = navigation.mLongitude(i);
		y = navigation.mLatitude(i);
	end
	if ( isfield(navigation,'yaw') )
		u = sin(navigation.yaw(i));
		v = cos(navigation.yaw(i));
	elseif ( isfield(navigation,'mYaw') )
		u = sin(navigation.mYaw(i));
		v = cos(navigation.mYaw(i));		
	end

	quiver(x,y,u,v,0.25)
	hold off

end