function shiftTSeries(vw,shift,scanList)
%
% function shiftTSeries(view,[shift],[scanList])
%
% Shifts the time series (circular shift), to advance the phase of the response.
% This is useful for approximately compensating for the hemodynamic delay before
% averaging across scans, especially for CW and CCW retinotopies.
%
% scanList: vector of scan numbers to flip. Default: prompt user.
% shift: number of frames to shift. Default: 1.
%
% If you change this function make parallel changes in:
%    flipTSeries
% 
% djh, 6/2001
if ieNotDefined('scanList'),  scanList = er_selectScans(vw); end
if ieNotDefined('shift'),     shift = 1;                       end

waitHandle = mrvWaitbar(0,'Shifting tSeries.  Please wait...');

for iScan=1:length(scanList)

    scan = scanList(iScan);
    tSeriesFull = [];
    dimNum = 0;
    for slice=sliceList(vw,scan);
        tSeries = loadtSeries(vw,scan,slice);
        tSeries = circularShift(tSeries,0,-shift);
        dimNum = numel(size(tSeries));
        tSeriesFull = cat(dimNum + 1, tSeriesFull, tSeries); %Combine together
        mrvWaitbar(iScan/length(scanList))
    end
    
    if dimNum == 3
        tSeriesFull = reshape(tSeriesFull,[1,2,4,3]);
    end %if
    
    savetSeries(tSeriesFull,vw,scan);
end

close(waitHandle);

if length(scanList)==1
    fprintf('Shifted tSeries for scan %i by %i frames.\n',scanList,shift);
else
    fprintf('Shifted tSeries for scans %s by %i frames.\n',...
        num2str(scanList),shift);
end    

return
