% test convert ship rel wind to true wind
jd = scsm(:,1);
wspd = scsm(:,9);
wdir = scsm(:,10);
rwspd = scsm(:,12);
rwdir = scsm(:,13);
sog = scsm(:,6);
cog = scsm(:,5);
hed = scsm(:,4);

rdcon = pi/180;

[U, V] = pol2cart(rwdir*rdcon, rwspd);      % relative wind components
U = -U;                                     % +U to N like sonic



[SOGn, SOGe] = pol2cart(cog*rdcon, sog);    % ship velocity components
                                            % dir is 'toward' N & E
                                            
[hedn, hede] = pol2cart(hed*rdcon, 1);      % heading components

Un_rel = U.*hedn + V.*hede;                 % rel wind components, earth ref
Ue_rel = U.*hede - V.*hedn;

Un = Un_rel + SOGn;                         % true wind components
Ue = Ue_rel + SOGe;

wspd2 = sqrt(Un.*Un + Ue.*Ue);
wdir2 = mod(atan2(-Ue,-Un)/rdcon + 360, 360);

figure; plot(jd, wspd,'b',jd,wspd2,'r');
figure; plot(jd,wdir,'b',jd,wdir2,'r'); ylim([0 360]);


