function settime(h,t,varargin)

%% Method to set the time vector of the internal time series to a value
%% which may be different from its currrent length. used by the "Apply"
%% button on the @tsnode panel to reset the time vector

%% Create transaction
T = tsguis.transaction;
recorder = tsguis.recorder;
        
        
if h.Timeseries.getGridSize(1)<length(t) % Add zeros to make up the data length    
   msg = sprintf('The specified time vector (length %d) is longer than the current ordinate data (length %d). ',...
       length(t),h.Timeseries.getGridSize(1));
   if ~isempty(h.Timeseries.Quality)
       msg = sprintf('%s%s%s', msg, 'Data status information will will be removed. ');
   end
   msg = sprintf('%s%s%s', msg, ...
       'Additional zero data will be added to make up the difference.',...
       'Do you wish to continue?'); 
   ButtonName = questdlg(msg, 'Time Series Tools', 'OK','Cancel','OK');
   drawnow expose% Prevents the questdlg from remaining open during computation 
   if strcmp(ButtonName,'Cancel') 
       return
   end
   tsData = h.Timeseries.Data;
    % Data recording
   if strcmp(recorder.Recording,'on')
        T.addbuffer(['tsData = ' h.Timeseries.Name '.Data;']);
        T.addbuffer(['tsData = [tsData; zeros([' sprintf('%d',length(t)-h.Timeseries.getGridSize(1)) ',' ...
            sprintf('%d',size(tsData,2)) '])];']);
        T.addbuffer(['tsTime = [' sprintf('%f',t(1)) ':' ...
            sprintf('%f',t(2)-t(1)) ':' sprintf('%f',t(end)) ']'';']);
        T.addbuffer([h.Timeseries.Name '.init(tsData,tsTime);'],h.Timeseries);
   end 
   % Extend the data
   h.Timeseries.init([tsData;zeros( ...
        [length(t)-h.Timeseries.getGridSize(1),size(tsData,2)])],t);   
 
elseif h.Timeseries.getGridSize(1)>length(t) % Truncate the data to match the new time
   msg = sprintf('The specified time vector (length %d) is shorter than the current ordinate data (length %d). ',...
       length(t),h.Timeseries.getGridSize(1));
   if ~isempty(h.Timeseries.Quality)
       msg = sprintf('%s%s%s', msg, 'Data status information will will be removed. ');
   end
   msg = sprintf('%s%s%s', msg, ...
       'Data will be removed from the end of the time series to accommodate the truncation. ',...
       'Do you wish to continue?'); 
   ButtonName = questdlg(msg, 'Time Series Tools', 'OK','Cancel','OK');
   if strcmp(ButtonName,'Cancel') 
       return
   end
  
   % Data recording
   if strcmp(recorder.Recording,'on')
        T.addbuffer(['tsData = ' h.Timeseries.Name '.Data(1:' sprintf('%d',length(t)) ',:);']); 
        T.addbuffer(['tsTime = [' sprintf('%f',t(1)) ':' ...
            sprintf('%f',t(2)-t(1)) ':' sprintf('%f',t(end)) ']'';']);
        T.addbuffer([h.Timeseries.Name '.init(tsData,tsTime);'],h.Timeseries);
   end  
   
   % Truncate the data
   h.Timeseries.init(h.Timeseries.Data(1:length(t),:),t);
else
   h.Timeseries.Time = t;
   % Data recording
   if strcmp(recorder.Recording,'on')
        T.addbuffer(['tsTime = [' sprintf('%f',t(1)) ':' ...
            sprintf('%f',t(2)-t(1)) ':' sprintf('%f',t(end)) ']'';']);
        T.addbuffer([h.Timeseries.Name '.Time = tsTime;'],h.Timeseries);
   end 
end

%% Store transaction
T.commit;
recorder.pushundo(T);