%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% PURPOSE: Plot Modtronix data.
% AUTHOR:  Rob McEwen
% DATE:    2015/6/17
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  

  if exist('ModtronixLog') ~= 1, return, end

  startDateTime = datetime(startTime,'convertfrom','posixtime');
  
  if( exist('thisTitleStr') ~= 1 )
    thisTitleStr = ['; Data Set: ', DirName];
    startStr = sprintf(';  Start time = %.1f (Sec Unix) = %s Z', startTime, ...
                       datestr(startDateTime));
    thisTitleStr = [thisTitleStr,startStr]
  end

  if( exist( 'ModTronFig' ) ~= 1 )
      ModTronFig = figure;
      figure(ModTronFig);
      set(gcf,'position',position)
  else 
      figure( ModTronFig ); 
  end
  set( ModTronFig, 'name', ...
      'Temp, Humidity, fStop',...
      'DeleteFcn', 'clear ModTronFig')
  %     'paperorientation','landscape','paperposition',[.25 .25 10.5 8.0]);
  clf
  modTron1=subplot(3,1,1);
  plot( datenum(datetime(ModtronixLog.data(:,end),'convertfrom','posixtime')), ...
        ModtronixLog.data(:,12:13) );
  grid on
  set(gca,'fontsize',15)
  legend('Humidity, %','Temperature, C');
  title(['Environment and fstop',thisTitleStr]);
  ylabel('Humidity, %; Temperature, C');
  set(gca,'xminorgrid','on','xminortick','on');
  datetick('x',13)
  
  modTron2=subplot(3,1,2);
  %plot( ModtronixLog.data(:,end), ...
  plot( datenum(datetime(ModtronixLog.data(:,end),'convertfrom','posixtime')), ...
        ModtronixLog.data(:,ModtronixLog.motor_position) );
  grid on
  set(gca,'fontsize',15)
  ylabel('Motor Counts')
  set(gca,'xminorgrid','on','xminortick','on');
  datetick('x',13)
  
  modTron3=subplot(3,1,3);
  plot( datenum(datetime(ModtronixLog.data(:,end),'convertfrom','posixtime')), ...
        ModtronixLog.data(:,ModtronixLog.video_mean:ModtronixLog.video_max) );
  grid on
  set(gca,'fontsize',15)
  xlabel('Hours:Minutes:Seconds Zulu');
  ylabel('Video Mean and Max; Counts??')
  set(gca,'xminorgrid','on','xminortick','on');
  datetick('x',13)
  legend('Mean','Max')
    
  linkaxes(get(gcf,'children'),'x')
