%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% PURPOSE: Plot Temperature and Humidity from the Fan Card.
% AUTHORS: (1) Rob McEwen, First submission, 2004/4/9.
%          (2)
% 
% NOTES: 
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
  if exist('dataEnv') ~= 1, return, end

  if exist('titleStr') ~= 1
    titleStr = ['; Data Set: ', DirName];
    position = [7    55   834   639];
  end
  
  if exist('startTime') == 1
    envTime = dataEnv(:,1);
  else
    envTime = dataEnv(:,1)-dataEnv(1,1);
  end
  

  str = [' ',titleStr,' Plotted on ',myDate];
  PaperPosn = [.5 .5 3.75 2.5];
  FigurePosn = [5 30 815 760];
  i = 0;

  if exist( 'envFig' ) ~= 1
    envFig = figure;
    figure(envFig);
%   winpos( position(1,:) );
  else
    figure(envFig);
  end
  set( envFig, 'Name', 'Env Sphere Sensor Plot', 'DeleteFcn', 'clear envFig' );
  set(gcf,'position',position)

  [indx,tempfan]  = stairs( envTime, cel2far(dataEnv(:,TempFan)   ) );
  [indx,temppower]= stairs( envTime, cel2far(dataEnv(:,TempPower) ) );
  [indx,tempsht1x]= stairs( envTime, cel2far(dataEnv(:,TempSHT1x) ) );
  [indx,humidity] = stairs( envTime, dataEnv(:,Humidity) );
  [indx,pressure] = stairs( envTime, dataEnv(:,Pressure) );

  nstrips = 3;
  %subplot(row dim, column dim, current plot number)
  subplot(nstrips,1,1)
%  plot( indx, [tempfan temppower tempsht1x])
  plot( indx, [tempfan tempsht1x])
  ylabel('Fahrenheit')
  title(['MVC Temperature and Humidity ',str]);
  grid on
  zoom on
  YEMax = 110;  %Prevent autoscaling to outliers
  YEMin = 32;
  Ylim = get(gca,'YLim');
  Ylim(1) = max([Ylim(1) YEMin]);
  Ylim(2) = min([Ylim(2) YEMax]);
  set(gca,'YLim',Ylim)
%  legend('Fan Card DS1620','Power Board DS1620','Fan Card SHT1x')
  legend('Fan Card DS1620','Fan Card SHT1x')

  subplot(nstrips,1,2)
  plot( indx, humidity)
  ylabel('Relative Percent')
  grid on
  zoom on
  if 0
  YEMax = 100;  %Prevent autoscaling to outliers
  YEMin = 0;
  Ylim = get(gca,'YLim');
  Ylim(1) = max([Ylim(1) YEMin]);
  Ylim(2) = min([Ylim(2) YEMax]);
  set(gca,'YLim',Ylim)
  end

  subplot(nstrips,1,3)
  plot( indx, pressure)
  ylabel('kPa')
  xlabel('Seconds')
  grid on
  zoom on
  if 0
  YEMax = 100;  %Prevent autoscaling to outliers
  YEMin = 0;
  Ylim = get(gca,'YLim');
  Ylim(1) = max([Ylim(1) YEMin]);
  Ylim(2) = min([Ylim(2) YEMax]);
  set(gca,'YLim',Ylim)
  end
  return
  
