function [mystr] = get_avg_wdirs(mystr,spdname,dirname)
% average to 1 hour, first convert spdname,dirname to e,n
% then 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;
eval (['myspd=mystr.' spdname ';']);
eval(['mydir=mystr.' dirname ';']);
mystr.mynorth= myspd.*cos(mydir * torad);   % to N
mystr.myeast=myspd.*sin(mydir * torad);    % to E 

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

% convert back
[myspd, mydir]= vect2md(mystr.myeast,mystr.mynorth);
ij = find(mydir > 360) ;
if ~ isempty(ij) > 0,
   mydir(ij) = mydir(ij) - 360;
end
eval (['mystr.' spdname ' = myspd;']);
eval(['mystr.' dirname ' = mydir;']);

 
