%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% PURPOSE: Plot raw CTD data from dual CTDs
% AUTHOR:  Initial; rsm; nst
% DATE:    01/07/12
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Units and Fundamental Constants:
  units


  str = [' ',titleStr, ' ',myDate];
  PaperPosn = [.5 .5 3.75 2.5];
  FigurePosn = [5 30 815 760];
  i = 0;
  if exist( 'ipsFig1' ) ~= 1
      ipsFig1 = figure;
  else 
      figure( ipsFig1 ); 
  end
    
  set( ipsFig1, 'name', 'IPS Range & Pressure', ...
       'DeleteFcn', 'clear ipsFig1' );
  set(gcf,'position',position)
  clf

    subplot(3,1,1)
%    [xx,yy] = stairs( ips4log(:,m_present_time), ips4log(:,ipsRange));
%    plot(xx,yy);
    plot( ips4log(:,m_present_time), ips4log(:,ipsRange));
    ylabel('m')
    title(['Range',str]);
    grid on
    zoom on

    subplot(3,1,2)
    [xx,yy] = stairs( ips4log(:,m_present_time), ips4log(:,ipsPressure));
    plot(xx,yy);
    set( gca, 'ydir', 'reverse' );
    ylabel('decibars')
    title(['Pressure',str]);
    grid on
    zoom on

    subplot(3,1,3)
 if ( exist('dataNav') == 1 )
    [xx,yy] = stairs( dataNav(:,m_present_time), dataNav(:,mDepth));
    plot(xx,yy);
 end
    set( gca, 'ydir', 'reverse' );
    ylabel('Meters')
    title(['Depth',str]);
    grid on
    zoom on
        
    
  if exist( 'ipsFig2' ) ~= 1
      ipsFig2 = figure;
  else 
      figure( ipsFig2 ); 
  end
    
  set( ipsFig2, 'name', 'IPS Tilt', ...
       'DeleteFcn', 'clear ipsFig2' );
  set(gcf,'position',position)
  clf

    subplot(4,1,1)
    [xx,yy] = stairs( ips4log(:,m_present_time), ips4log(:,ipsTiltX));
    plot(xx,yy);
    ylabel('Degrees')
    title(['Tilt X',str]);
    grid on
    zoom on

    subplot(4,1,2)
    [xx,yy] = stairs( ips4log(:,m_present_time), ips4log(:,ipsTiltY));
    plot(xx,yy);
    ylabel('Degrees')
    title(['Tilt Y',str]);
    grid on
    zoom on
    
    subplot(4,1,3)
 if ( exist('dataNav') == 1 )
    [xx,yy]   = stairs( dataNav(:,m_present_time), dataNav(:,mPhi)/d2r);
    plot(xx, yy);
    if exist('dataCB') == 1,
      [xx1,yy1] = stairs( dataCB(:,m_present_time),  dataCB(:,mRollCB));
      line(xx1, yy1,'Color','g');
      legend('Nav','Ahrs')
    end
    if 0
    if exist('dvlRoll') == 1,
      [xx1,yy1] = stairs( dataDvl(:,m_present_time),  dataDvl(:,dvlRoll)/d2r);
      line(xx1, yy1,'Color','r');
      legend('Nav','Ahrs','Dvl')
    end
    end
    if exist('dataO') == 1,
      [xx2,yy2] = stairs( dataO(:,m_present_time),  dataO(:,mRollO));
      line(xx2, yy2,'Color','r');
      legend('Nav','CrossBow','Octans')
    end
 end
    ylabel('Degrees')
    title(['Roll, Degrees',str]);
    grid on
    zoom on
    
    
    subplot(4,1,4)
 if ( exist('dataNav') == 1 )
    [xx,yy]   = stairs( dataNav(:,m_present_time), dataNav(:,mTheta)/d2r);
    plot(xx, yy);
    if exist('dataCB') == 1,
      [xx1,yy1] = stairs( dataCB(:,m_present_time),  dataCB(:,mPitchCB));
      line(xx1, yy1,'Color','g');
      legend('Nav','Ahrs')
    end
    if exist('dvlPitch') == 1,
      [xx1,yy1] = stairs( dataDvl(:,m_present_time),  dataDvl(:,dvlPitch)/d2r);
      line(xx1, yy1,'Color','r');
      legend('Nav','Ahrs','Dvl')
    end
    if exist('dataO') == 1,
      [xx2,yy2] = stairs( dataO(:,m_present_time),  dataO(:,mPitchO));
      line(xx2, yy2,'Color','r');
      legend('Nav','CrossBow','Octans')
    end
 end
    ylabel('Degrees')
    title(['Pitch, Degrees',str]);
    grid on
    zoom on
    
    
    
  if exist( 'ipsFig3' ) ~= 1
      ipsFig3 = figure;
  else 
      figure( ipsFig3 ); 
  end
    
  set( ipsFig3, 'name', 'IPS Signal Stats', ...
       'DeleteFcn', 'clear ipsFig3' );
  set(gcf,'position',position)
  clf

    subplot(3,1,1)
    [xx,yy] = stairs( ips4log(:,m_present_time), ips4log(:,ipsAmplitude));
    plot(xx,yy);
    ylabel('Counts (0-255)')
    title(['Amplitude',str]);
    grid on
    zoom on

    subplot(3,1,2)
    [xx,yy] = stairs( ips4log(:,m_present_time), ips4log(:,ipsPersistence));
    plot(xx,yy);
    ylabel('ms')
    title(['Persistence',str]);
    grid on
    zoom on

    subplot(3,1,3)
    [xx,yy] = stairs( ips4log(:,m_present_time), ips4log(:,ipsTravelTime));
    plot(xx,yy);
    ylabel('s')
    title(['Travel Time',str]);
    grid on
    zoom on
       
        
  if exist( 'ipsFig4' ) ~= 1
      ipsFig4 = figure;
  else 
      figure( ipsFig4 ); 
  end
    
  set( ipsFig4, 'name', 'IPS Draft', ...
       'DeleteFcn', 'clear ipsFig4' );
  set(gcf,'position',position)
  clf

    subplot(2,1,1)
    [xx,yy] = stairs( ips4log(:,m_present_time), ips4log(:,ipsDraft));
    plot(xx,yy);
    ylabel('m')
    title(['Draft',str]);
    grid on
    zoom on

