function loadRepeatRecord_chunk2(fid_prefix,chunksize)

channel = [];
time = [];
threshold = [];
waveform = [];
j = 1;

if nargin<2
    chunksize = 1; %in hours
end

fpath = ['C:\Users\USER\Documents\mingfaifong\' fid_prefix '\spkfiles\'];
spath = ['C:\Users\USER\Documents\mingfaifong\' fid_prefix '\matfiles\']; mkdir(spath);
fpath_info = dir(fpath);      %get info about contents of directory
isfile = ~[fpath_info.isdir]; %get index for files only
fidlist = {fpath_info(isfile).name}; %create list of files

for i = 1:length(fidlist)
    clearvars -except i fidlist T0 fpath chunksize j channel time threshold waveform spath fid_prefix
    fid = fidlist{i};

    %determine time at beginning of file based on location of dashes in filename
    dashloc = strfind(fid,'-');
    %uscloc = strfind(fid,'_');

    T = [str2double(fid(dashloc(length(dashloc)-5)+1:dashloc(length(dashloc)-4)-1)),... %year
        str2double(fid(dashloc(length(dashloc)-4)+1:dashloc(length(dashloc)-3)-1)),... %month
        str2double(fid(dashloc(length(dashloc)-3)+1:dashloc(length(dashloc)-2)-1)),... %day
        str2double(fid(dashloc(length(dashloc)-2)+1:dashloc(length(dashloc)-1)-1)),... %hour
        str2double(fid(dashloc(length(dashloc)-1)+1:dashloc(length(dashloc))-1)),... %minute
        str2double(fid(dashloc(length(dashloc))+1:length(fid)-4))]; %second

    %set T0 as time of first file
    if i == 1
        T0 = T;
    end
    
    %load spike file and adjust time
    if strfind(fid,'.spk')
        x = loadspike([fpath fid]);
    elseif strfind(fid,'.mat')
        x = load([fpath fid]);
    else
        disp([fid ' was not loaded.']);
    end
    starttime = etime(T,T0);
    x.time = x.time+starttime; %increments all times up by prior recordings opened so far

    [maxval maxvalind] = max(x.time); %defines the length of the entire recording so far in seconds
    minval = min(x.time); %defines time of first spike in the newly-appended recording in seconds

    %--for case where the first spike of the new recording exceeds the max
    %file length--%
    if minval > chunksize*j*3600
        %fid_prefix = fid(1:dashloc(length(dashloc)-5)-1);
        save([spath fid_prefix '_' num2str(chunksize*(j-1)) 'to' num2str(chunksize*j) 'hr' '.mat'],'channel','time','threshold','waveform');
        channel = [];
        time = [];
        threshold = [];
        waveform = [];
        while minval > chunksize*j*3600
            j = j+1;
        end
    end
    
    %--for case where end of entire recording (including newly-appended recording) exceeds maximum chunk size--%
    if maxval >= chunksize*j*3600
        highind = find(x.time >= chunksize*j*3600);
        channel = [channel; x.channel(1:highind(1)-1)];
        time = [time; x.time(1:highind(1)-1)];
        threshold = [threshold; x.threshold(1:highind(1)-1)];
        waveform = [waveform, x.waveform(:,1:highind(1)-1)];
        %fid_prefix = fid(1:dashloc(length(dashloc)-5)-1);
        %fid_prefix = fid(1:uscloc(1));
        save([spath fid_prefix '_' num2str(chunksize*(j-1)) 'to' num2str(chunksize*j) 'hr' '.mat'],'channel','time','threshold','waveform');
        clear channel time threshold waveform
        channel = x.channel(highind);
        time = x.time(highind);
        waveform = x.waveform(:,highind);
        threshold = x.threshold(highind);
        j = j+1;
    %--for case where end of entire recording (including newly-appending
    %recording) is less than value of maximum chunk size--%
    else
        channel = [channel; x.channel];
        time = [time; x.time];
        threshold = [threshold; x.threshold];
        waveform = [waveform, x.waveform];
    end

end

%fid_prefix = fid(1:dashloc(length(dashloc)-5)-1);
%fid_prefix = fid(1:uscloc(1));
save([spath fid_prefix '_' num2str(chunksize*(j-1)) 'to' num2str(ceil(max(time)/3600)) 'hr' '.mat'],'channel','time','threshold','waveform');