%Compares the Kongsberg and Crossbow motion units ont he Wband radar.

close all
clear all
%##########################################################################
%%%%%%%%%%%%%%%%%%%%%%%%% Cruise informations and parameters %%%%%%%%%%%%%%
%##########################################################################

cruise='GS_2014';             % Cruise name  
ship='GS';               % Research vessel

read_parameters_AtlanticTransect_2014;     %reads the parameters for the cruise.

graphformat='.png';  %select graphics format files
graphdevice='-dpng'; %select graphic device
prtit=true;  % for printing plots--ineffective unless plotit is also true going to a temp directory
prtit_hr=1;  %to save individual hourly graphs

%##########################################################################
%%%%  Starts reading and ourly plotting process %%%%%%%%%%%%%%%%%%%%%%%%%%%
%##########################################################################

% use known day/hour; prompt for it if unknown
if ~exist('ddd','var')
    ddds=input('Input yearday  ','s');
    ddd=str2double(ddds);
else
    ddds=sprintf('%03i',ddd);
end
[m,d]=yd2md(str2double(yyyy), ddd);
Vdate=[str2double(yyyy) m d];
if ~exist('shr','var')
    shrs=input('Input start hr  ','s');
    shr=str2double(shrs);
else
    shr=0;
end
if ~exist('ehr','var')
    ehrs=input('Input end hr  ','s');
    ehr=str2double(ehrs);
else % use hours 0-23 by default
    ehr=23;
end

pitchk=[];rollk=[];timek=[];
pitchX=[];rollX=[];timeX=[];pitchrateX=[];rollrateX=[];
for jam=shr:ehr
        hr=sprintf('%02i',jam);

    read_Wband_motion_AtlanticTransect_2014
        timek=[timek hhka];
        pitchk=[pitchk vkonsa(7,:)*(180/pi)];
        rollk=[rollk vkonsa(8,:)*(180/pi)];
    fm = [way_raw_motion_wband yyyy ddds hr '00Crossbow.txt'];    
    [Xtmotion, Xroll, Xpitch, Xrollrate, Xpitchrate]=read_Wband_crossbow(fm);
        timeX=[timeX Xtmotion];
        pitchX=[pitchX Xpitch];
        rollX=[rollX Xroll];
        pitchrateX=[pitchrateX Xpitchrate];
        rollrateX=[rollrateX Xrollrate];                
end    


figure(1); clf
    subplot(2,1,1);plot(timeX,pitchX,'b',timek,rollk,'g');grid;title('Roll angle (deg)');legend('Crossbow','Kongsberg','Location','Best')
    subplot(2,1,2);plot(timeX,rollX,'b',timek,pitchk,'g');grid;title('Pitch angle (deg)');legend('Crossbow','Kongsberg','Location','Best')

figure(2); clf
    subplot(2,1,1);plot(timeX,pitchrateX,'b');grid;title('Roll rate (deg/s)');%legend('Crossbow','Kongsberg','Location','Best')
    subplot(2,1,2);plot(timeX,rollrateX,'b');grid;title('Pitch rate (deg/s)');%legend('Crossbow','Kongsberg','Location','Best')
        
