function loadspk_chunk_old(fid_prefix,chunksize)

channel = [];
time = [];
threshold = [];
waveform = [];
k = 0;

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

tmp.time = [];
tmp.channel = [];
tmp.threshold = [];
tmp.waveform = [];
tmp.unit = [];

for i = 1:length(fidlist)
    clearvars -except i fidlist T0 fpath chunksize j channel time threshold waveform spath fid_prefix tmp k
    
    % get name of spike file
    fid = fidlist{i};
    
    % finding fid name based on location of underscores
    uscloc = strfind(fid,'_');
    if length(uscloc)==1
        fidsave = fid;
    else
        fidsave = fid(1:uscloc(2)-1);
    end

    % get start time for associated fid
    load([fid_prefix '\' fid(1:length(fid)-4),'_starttime.mat']);
    %set T0 as time of first file
    if i == 1
        T0 = T;
    end
    
    %load spike file
    if strfind(fid,'.spk')
        x = loadspk([fpath fid]);
    elseif strfind(fid,'.mat')
        x = load([fpath fid]);
    else
        disp([fid ' was not loaded.']);
    end
    
    keyboard;
    % adjust starting time
    starttime = etime(T,T0);
    x.time = x.time+starttime; %increments all times up by prior recordings opened so far
    x.time = [tmp.time; x.time];
    x.channel = [tmp.channel; x.channel];
    x.unit = [tmp.unit; x.unit];
    x.threshold = [tmp.threshold; x.threshold];
    x.waveform = [tmp.waveform x.waveform];
    
    keyboard;
    
    % save chunks of data of size specified by CHUNKSIZE
    for j = 1+k:ceil(max(x.time)/3600)+k
        if j == ceil(max(x.time)/3600)+k && i ~= length(fidlist)
            tmp.time = x.time(x.time<j*3600 & x.time>=(j-1)*3600);
            tmp.channel = x.channel(x.time<j*3600 & x.time>=(j-1)*3600);
            tmp.waveform = x.waveform(:,x.time<j*3600 & x.time>=(j-1)*3600);
            tmp.threshold = x.threshold(x.time<j*3600 & x.time>=(j-1)*3600);
            tmp.unit = x.unit(x.time<j*3600 & x.time>=(j-1)*3600);
            k = j-1;
        else
            time = x.time(x.time<j*3600 & x.time>=(j-1)*3600);
            channel = x.channel(x.time<j*3600 & x.time>=(j-1)*3600);
            waveform = x.waveform(:,x.time<j*3600 & x.time>=(j-1)*3600);
            threshold = x.threshold(x.time<j*3600 & x.time>=(j-1)*3600);
            unit = x.unit(x.time<j*3600 & x.time>=(j-1)*3600);
            %save([spath fidsave '_' num2str(chunksize*(j-1)) 'to' num2str(ceil(max(time)/3600)) 'hr' '.mat'],'channel','time','threshold','waveform');
        end
    end
end