function [ualong, ucross]=along_cross(ws_inst,wd_inst,wd_mean);

beta=abs(wd_inst-wd_mean);
u_toward=find(beta < 90  | beta >= 270);
u_away=find(beta >= 90  & beta <270);
beta(u_away)=abs(beta(u_away)-180);
ualong(u_toward)=ws_inst(u_toward).*cos(deg2rad(beta(u_toward)));
ualong(u_away)=-ws_inst(u_away).*cos(deg2rad(beta(u_away)));
 u_toward=[];
 u_away=[];
 u_toward=find( beta <= 180);
u_away=find(beta  > 180 );
ucross(u_toward)=ws_inst(u_toward).*sin(deg2rad(beta(u_toward))); % This is assuming the framework (u_cross,u_along) if it's the inverse need to switch the sign of ucross and maybe ualong. should check
ucross(u_away)=-ws_inst(u_away).*sin(deg2rad(beta(u_away)));
