function [gps] = get_gps_avg(gps)
% convert speed, heading to east, north, average, 
% convert back
 addpath([matlabroot '\work\structures']);
 
%  subplot(2,1,1)
%  plot(gps.mday,gps.speed); hold on
%   subplot(2,1,2)
%  plot(gps.mday,gps.heading); hold on
 
torad=pi/180;
gps.north=gps.speed.*cos(gps.heading * torad);   %ship to N
gps.east=gps.speed.*sin(gps.heading * torad);    %ship to E 
gps=rmfield(gps,'heading');

% get the hourly average
gps=get_str_avg(gps);

[gps.speed, gps.heading] = vect2md(gps.east,gps.north);
ij = find(gps.heading > 360) ;
if ~ isempty(ij) > 0,
   gps.heading(ij) =gps.heading(ij) - 360;
end
%  subplot(2,1,1)
%  plot(gps.mday,gps.speed,'r.'); ylabel('spd');
%   subplot(2,1,2)
%  plot(gps.mday,gps.heading,'r'); ylabel('hdg')
 
