function loadRepeatRecord_chunkMB(fid_prefix,chunksize)

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

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

fpath = ['C:\Users\USER\Documents\mingfaifong\frodo361\spkfiles\'];
spath = ['C:\Users\USER\Documents\mingfaifong\frodo361\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,'_');
    %keyboard
    
    T = [str2double(fid(dashloc(1)-4:dashloc(1)-1)),... %year
        str2double(fid(dashloc(2)-2:dashloc(2)-1)),... %month
        str2double(fid(dashloc(3)-2:dashloc(3)-1)),... %day
        str2double(fid(dashloc(4)-2:dashloc(4)-1)),... %hour
        str2double(fid(dashloc(4)+1:dashloc(4)+2)),... %minute
        0]; %second

    %set T0 as time of first file
%     if i == 1
%         T0 = T;
%     end
T0 = [2011 2 7 18 57 3];

    %load spike file and adjust time
    cd(fpath)
    if strfind(fid,'.spike')
        y = loadspike_MB(fid,2,25);
        %y = loadspike_MB(fid);
    elseif strfind(fid,'.mat')
        y = load([fpath fid]);
    else
        disp([fid ' was not loaded.']);
    end
    starttime = etime(T,T0);
    y.time = y.time+starttime;

    [maxval maxvalind] = max(y.time);
    minval = min(y.time);
    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
    if maxval >= chunksize*j*3600
        highind = find(y.time >= chunksize*j*3600);
        channel = [channel; y.channel(1:highind(1)-1)'];
        time = [time; y.time(1:highind(1)-1)'];
        threshold = [threshold; y.thresh(1:highind(1)-1)'];
        waveform = [waveform, y.context(:,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 = y.channel(highind)';
        time = y.time(highind)';
        threshold = y.thresh(highind)';
        waveform = y.context(:,highind);
        j = j+1;
    else
        channel = [channel; y.channel'];
        time = [time; y.time'];
        threshold = [threshold; y.thresh'];
        waveform = [waveform, y.context];
    end

    %keyboard;
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');