
function dates(flag)

%
% function dates(flag)
%
% dates produces a gui button for updating plots which 
% have an x-axis which is a matlab dat-number and produces
% which look like dates or times of the day in UTC.
%
% called with no arguments, the gui button is produced
% and the axis is updated.  
% called with an input, the gui is not produced but 
% the axis is till updated.

% id # of input arguments == 0, produce the push-button
if nargin == 0
  db  = uicontrol(...
     'Style','Pushbutton',...
     'Units','normalized',...
     'Position',[.92 .275 .07 .05],...
     'String','Dates',...
     'BackgroundColor',[.2 .7 .6],...
     'ForegroundColor',[0 0 0],...
     'FontWeight','b',...
     'Callback','dates(1)');
end

% get handles for each subplot
ah = sort(get(gcf,'Children'));
tp = get(ah,'Type');
ind = [];
for i = 1:length(ah)
  x = tp{i};
  if x(1) == 'a';
    ind = [ind i];
  end
end
ah = ah(ind);
ah = sort(ah);

% update each subplot and force equal x-limits
set(gcf,'CurrentAxes',ah(length(ah)));
datetick
xlimits = get(gca,'XLim');
xticks = get(gca,'XTick');
for i = 1:length(ah)
  set(ah(i),'XLim',xlimits,'XTick',xticks);  
end

