function timeresp(src,r)
%FREQRESP  Updates @timedata objects.
%  Author(s):  
%  Copyright 1986-2002 The MathWorks, Inc.
%  $Revision: 1.1.6.1 $ $Date: 2004/12/26 21:43:36 $
 
%% Look for visible+cleared responses in response array
if isempty(r.Data.Amplitude) && strcmp(r.View.Visible,'on')
  % Find the conversion factor from the @timeseries time units to
  % the view units
  timeunitconv = tsunitconv(r.Parent.TimeUnits,src.Timeseries.TimeInfo.Units);

 % Update the time (relative or absolute) 
  if strcmp(r.Parent.Absolutetime,'on') % Absolute time vector displayed
      % If this response has no absolute time reference do not draw
      if isempty(src.Timeseries.TimeInfo.StartDate)
         return 
      end
      % If the @timeplot startdate has not been added set it to the
      % startdate for this response. This will happen if the @timeseries
      % has been converted to an absolute time vector from the @tsnode
      % panel
      if isempty(r.Parent.StartDate)
          r.Parent.StartDate = src.Timeseries.TimeInfo.StartDate;
      end
      refdateshift = tsunitconv(r.Parent.TimeUnits,'days')*...
              (datenum(src.Timeseries.TimeInfo.StartDate)-datenum(r.Parent.StartDate));
  else % Relative time only
      refdateshift = 0;
  end
  r.Data.Time = refdateshift+src.Timeseries.Time*timeunitconv;
  
  % Update the data
  set(r.Data,'Amplitude',src.Timeseries.Data);
  
  % Update the focus - prevent trivial intervals or the @plot axes will not
  % display correctly     
  xfocus = [src.Timeseries.TimeInfo.Start*timeunitconv,src.Timeseries.TimeInfo.End*timeunitconv];
  if strcmp(r.Parent.Absolutetime,'on') % Adjust for differences in start data between ts and view
      xfocus = tsunitconv(r.Parent.TimeUnits,'days')*(-datenum(r.Parent.StartDate)+...
          datenum(src.Timeseries.TimeInfo.StartDate))+xfocus;
  end 
  if xfocus(2)-xfocus(1)>eps  
      set(r.Data,'Focus',xfocus)
  else
      set(r.Data,'Focus',[xfocus(1) - 1e-6, xfocus(1) + 1e-6])
  end
    
  % Update the list of eventChars in case the events attached to this time
  % series have changed
  localRefreshEventChar(r)
end

%% The response name should match the time series name
r.Name = src.Timeseries.Name;

function localRefreshEventChar(wf)

%% If the list of events has changed in the time series shown by this wave,
%% then this function will refresh the event characteristics
if ~isempty(wf.Characteristics)
    c = wf.Characteristics(strcmp('events',get(wf.Characteristics,{'Identifier'})));
else
    c =[];
end
currentEventNames = cell(length(c),1);
for k=1:length(c)
    currentEventNames{k} = c(k).Data.Event.Name;
end
newEventNames = get(wf.DataSrc.Timeseries.Events,{'Name'});

%% Identify chars for deleted events
[junk,deletedEventPos] = setdiff(currentEventNames,newEventNames);
deletedChars = c(deletedEventPos);

%% Create new chars for new events
[junk,newEventPos] = setdiff(newEventNames,currentEventNames);
newChar = [];
for k=1:length(newEventPos)
    newChar = [newChar(:); ...
        wf.addchar('events','tsguis.eventCharData','tsguis.eventCharView')];
    newChar(end).Data.Event = wf.DataSrc.Timeseries.Events(newEventPos(k));
end

%% Remove and delete chars marked for deletion
[junk,I] = ismember(wf.Characteristics,deletedChars);
I = find(I>0);
if ~isempty(I)
   wf.Characteristics(I) = [];
   delete(deletedChars);
end