%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% PURPOSE: Plot items related to MbTrnRecv
% AUTHORS: 1. rsm 26 June 2018.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
  if( exist('MbTrn') ~= 1 ) return, end

  str = [' ',titleStr,' Plotted on ',myDate];

%
  
if( exist('MbTrn') == 1 )
  lstr={};
  if exist( 'MbTrnRealFigPtr' ) ~= 1
    MbTrnRealFigPtr= figure;
    set( MbTrnRealFigPtr, 'Name', 'MbTrnRecv', 'DeleteFcn', 'clear MbTrnRealFigPtr' );
    set(gcf,'position',position)
    if(exist('fontsize')) 
      MbTrnFontsize=fontsize;
    else
      MbTrnFontsize=20;
    end
    MbTrnFontweight='normal';
    set(gca,'fontsize',MbTrnFontsize,'fontweigh',MbTrnFontweight)
    set(gcf,'defaultaxesfontsize',MbTrnFontsize,'defaulttextfontsize', ...
	    MbTrnFontsize)
    MbTrnAxesPtr = gca;
    
    PauseButton_h = uicontrol('Style', 'pushbutton',...
                              'String', 'Click to Pause','FontSize',16,...
                              'BackgroundColor','g',...
                              'Position', [20 20 180 50 ],...
                              'Callback',@pause_Callback);
    QuitButton_h  = uicontrol('Style', 'pushbutton',...
                              'String', 'Quit','FontSize',16,...
                              'BackgroundColor','r',...
                              'Position', [300 20 180 50 ],...
                              'Callback',@quit_Callback);
    % 
    % Beware that the string 'Click to Pause' is also the state.  If you change
    % this string, you must also change it in pause_Callback.m
    % and in the waitfor() below.
  else
    figure(MbTrnRealFigPtr);
  end

  
  mbtrnRh1 = plot(MbTrn.data(1,MbTrn.cross_0:4:MbTrn.cross_10), MbTrn.data(1,MbTrn.vert_0:4:MbTrn.vert_10),'-x');
  set(gca,'ydir','reverse')
  set(gca,'xlim',[-100 100])
  set(gca,'ylim',[0 100])
  grid on;
  xlabel('Cross Track, Meters');
  ylabel('Altitude, Meters');
  title(['Received from mbTrnPre',str]);
  hTxt=text(-80,90,sprintf('Time = %.1f',MbTrn.data(1,1)));

  
  for(i = 2:length(MbTrn.data))
    mbtrnRh1.XData = MbTrn.data(i,MbTrn.cross_0:4:MbTrn.cross_10);
    mbtrnRh1.YData = MbTrn.data(i,MbTrn.vert_0:4:MbTrn.vert_10);
    hTxt.String=sprintf('Time = %.1f',MbTrn.data(i,1));
    drawnow update
    pause(0.1);
    waitfor( PauseButton_h, 'String','Click to Pause' );
    if( ~strcmp(QuitButton_h.String,'Quit') )
      break;
    end
    if( ~mod(i,10) ) fprintf('i = %d\n',i); end
  end
end
