%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% PURPOSE: Plot range vector, magnitude, and other stuff measured by the Usbl
% AUTHOR:  Rob McEwen
% DATE:    05/12/7
% MODS:
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
global titleStr;
global vehicleName;
titleStr = [' Data Set: ', DirName];

if( exist('usbllog') == 0), return, end

if( exist('fontsize') == 0), fontsize = 14; end
if( fontsize ==12 ), linewidth = .5;end
fontweight = 'normal';
 if(1)
   vehicleName = 'Docking';
   titleStr = [' Data Set: ', DirName];
   position = [4 32 815 658];
 end

winpos( position(1,:) );


if exist( 'usblFig' ) ~= 1
   usblFig = figure;
   figure( usblFig );
 else
   figure( usblFig );
 end

 set( gcf, 'name', [vehicleName,' Usbl'] );

title([ 'Usbl Range', titleStr ])
lstr = {};

subplot( 2, 1, 1 )
set(gca,'fontsize',fontsize,'fontweigh',fontweight)
stairs( usbllog(:,1), usbllog(:,[sonardyneRange sonardyneX:sonardyneZ]) )
lstr(length(lstr)+1:length(lstr)+4,1) = { 'Range','X','Y','Z'};
grid on
title([ 'Usbl Range', titleStr ]);
ylabel('Range, Meters')
legend(lstr);

subplot( 2, 1, 2 )
set(gca,'fontsize',fontsize,'fontweigh',fontweight)
stairs( usbllog(:,1), usbllog(:,sonardyneStatus) )
set(gca, 'ylim', [0 5] )
title('0=Undefined, 1=AllGood, 2=RangeOnly, 3=Stale')
ylabel('Status');
xlabel('Seconds');
zoom on
grid on


if exist( 'usblFig2' ) ~= 1
   usblFig2 = figure;
   figure( usblFig2 );
 else
   figure( usblFig2 );
 end


set( gcf, 'name', [vehicleName,' Usbl'] );


winpos( position(1,:) );
lstr = {};

subplot( 4, 1, 1 )
set(gca,'fontsize',fontsize,'fontweigh',fontweight)
stairs( usbllog(:,1), usbllog(:,[sonardyneSigLevel sonardyneDetectLevel]) )
lstr(length(lstr)+1:length(lstr)+2,1) = { 'Signal','S/N'};
title([ 'Signal Level and Signal-to-Noise Ratio', titleStr ])
ylabel('Decibels')
grid on

subplot( 4, 1, 2 )
set(gca,'fontsize',fontsize,'fontweigh',fontweight)
stairs( usbllog(:,1), usbllog(:,sonardyneQuality) )
title('Least Squares Residual Error')
ylabel('N/A')
grid on

subplot( 4, 1, 3 )
set(gca,'fontsize',fontsize,'fontweigh',fontweight)
stairs( usbllog(:,1), usbllog(:,sonardyneDoppler) )
title('Offset of Signal from Carrier Frequency')
ylabel('Hz')
grid on

subplot( 4, 1, 4 )
set(gca,'fontsize',fontsize,'fontweigh',fontweight)
stairs( usbllog(:,1), usbllog(:,sonardyneAcceptance) )
title('Number of Good Slices Through Pulse Signal')
ylabel('N/A')
xlabel('Seconds')
grid on
