load /j2/data/mvp/hawaii_test/matfmt/raw0020

% the following from mvp_vel2_hawaii_test.m

Vx=-(Vab+Vef)/(2.*.707);
Vy=(Vab-Vef)/(2.*.707);
Vz1=Vx-Vgh/.707;
Vz2=-Vx+Vcd/.707;

%now select the vertical velocity channel that is "upstream"

avevz=mean(Vz1);
if(avevz<0);
Vz=Vz1;
else
Vz=Vz2;
end

% below change aHz to aHy
Imag=sqrt(aHx.*aHx+aHy.*aHy);
aIx=aHx./Imag;
aIy=aHy./Imag;
mvpdir_a=atan2(-aIx,-aIy);

% this from john at sea after looking at spin test data
mvpdir_b=atan2(-aHy,aHx)+1.2172;

%new lines here to account for 180-degree rotation of ACM pressure case
   %mvpdir=mvpdir+pi;
   %cosd=cos(mvpdir);
   %sind=sin(mvpdir);
   %mvpdir=atan2(sind,cosd);
%end new lines




mvpdir_b=mvpdir_b+mag_dev;
speed=sqrt(Vx.*Vx+Vy.*Vy);
reldir=atan2(Vy,Vx);
trudir=mvpdir_b+reldir;
Veast=speed.*cos(trudir);
Vnorth=speed.*sin(trudir);

%then I do the following to get diff(dir)/dt to be same scale as Vy
xxx=diff(mvpdir_b);
yyy=xxx.*100;
 plot(yyy,'b'); 
hold on; grid on; zoom on;
plot(Vy,'r');  
xlabel('scan #');
ylabel('Vy = (Vab-Vef)/(2.*.707)(100) = red  mvpdir=atan2(-aHy,aHx)+1.2172 = blue');
title('MMP profile 20 hawaii_test');
 
