
%
% umecallback.m
%
% this m-file script is envoked whenever the editnum gui value is changed
% in umebrowser.m
%

% get available colors and select one
co = get(gca,'ColorOrder');
l=length(co);coi=index-l*fix(index/l)+1;

%% update figure 1: spectra screen
figure(1)
xextval = get(gca,'XLim');xminval=xextval(1);xmaxval=xextval(2);
yextval = get(gca,'YLim');yminval=yextval(1);ymaxval=yextval(2);
plot(his.freq,his.bt(index,:),'Color',co(coi,:));
set(gca,'Position',[.13 .2 .775 .70]);grid on;
set(gca,'XLim',[xminval xmaxval]);set(gca,'YLim',[yminval ymaxval]);
set(gca,'FontWeight','b');
xlabel('wavenumber [cm^{-1}]');
ylabel('T_b [K]');
title(['record # ' num2str(his.record_number(index)) ' : ' datestr(dn(his.nss1970(index)),0) ' UTC']);
g=get(gca,'Title');set(g,'FontSize',12,'FontWeight','b','Color',co(coi,:));


% get current status of hold for figure 1
hflag = get(gca,'NextPlot');


% if figure 2 still exists, update it
if max(findobj('Type','figure') == 2) == 1
  figure(2)

  hi = his.record_number(index);

  % get handles for plots in figure 2 and adjust them as necessary
  % the axes and text guis are identified by the 'tags' defined previously in umebrowser.m
  
  % adjust mean radiance vs. record number plots
  h = findobj('Tag','1');
    set(gcf,'CurrentAxes',h);deleter;hold on
    ind1 = find(his.freq >= his.wnbr1(1) & his.freq <= his.wnbr2(1));
    ind2 = find(his.freq >= his.wnbr1(2) & his.freq <= his.wnbr2(2));
    plot(hi,mean(his.bt(index,ind1)'),'.',...
         hi,mean(his.bt(index,ind2)'),'.','Color',co(coi,:),'MarkerSize',10,'LineWidth',1);

  % adjust BB T vs. record number plots
  h = findobj('Tag','3');
    set(gcf,'CurrentAxes',h);deleter;hold on
    plot(hi,his.hbb_temp(index),'.',...
         hi,his.cbb_temp(index),'.','Color',co(coi,:),'MarkerSize',10,'LineWidth',1)

  % adjust flags vs. record number plots
  h = findobj('Tag','5');
    set(gcf,'CurrentAxes',h);deleter;hold on
    plot(hi,his.bad_flag(index),'.',...
         hi,his.noise_flag(index),'.',...
	 hi,his.qc_flag(index),'.','Color',co(coi,:),'MarkerSize',10,'LineWidth',1)

  % adjust dc levels + phase vs. record number plots
  h = findobj('Tag','7');
    set(gcf,'CurrentAxes',h);deleter;hold on
    plot(hi,his.std_phase(index),'.',...
         hi,his.dc_ch1(index),'.',...
         hi,his.dc_ch2(index),'.',...
         hi,his.dc_ch3(index),'.','Color',co(coi,:),'MarkerSize',10,'LineWidth',1)

  % adjust altitude vs. time plot
  h = findobj('Tag','6');
    set(gcf,'CurrentAxes',h);deleter;hold on
    plot(dn(his.nss1970(index)),his.aircraft_alt(index)/1e3,'.',...
	'Color',co(coi,:),'MarkerSize',10,'LineWidth',1)

  % adjust lat vs. lon plot
  h = findobj('Tag','8');
    set(gcf,'CurrentAxes',h);deleter;hold on
    plot(his.aircraft_lon(index),his.aircraft_lat(index),'.',...
	'Color',co(coi,:),'MarkerSize',10,'LineWidth',1)

  % adjust record number text gui
  h = findobj('Tag','t1');
  set(h,'String',['record # ' num2str(his.record_number(index))],'ForegroundColor',co(coi,:));

  % adjust date gui
  h = findobj('Tag','t2');
  set(h,'String',datestr(dn(his.nss1970(1)),0),'ForegroundColor',co(coi,:));

  drawnow

end  % on if figure 2 still exists

