function [Like_Decision, Dislike_Decision] = Time_Exposure_Chris(dat)
% This program generates the time profile of the listening
% locked to the decision.

% Generate listening profile
Like_Decision = nan(20000,40,30);
Dislike_Decision = nan(20000,40,30);

for j=1:30
    temp1 = dat(j).dat1;
    temp2 = dat(j).dat2;
    index1 = 0;
    index2 = 0;
    for i=[3:42 45:84],
        overallTime = sum(temp2{i}(2:2:length(temp2{i})));
        if overallTime > 300 && overallTime < 20000,
            if temp1(i,4)==1
                index1 = index1 + 1;
                choice = temp1(i,6)-48;
                Like_Decision(:,index1,j) = sequence1(temp2{i},choice);
            else
                index2 = index2 + 1;
                choice = temp1(i,6)-48;
                Dislike_Decision(:,index2,j) = sequence1(temp2{i},choice);
            end
        end
    end
    disp(['C1: ' num2str(index1) ', C2: ' num2str(index2)]);
end

end

function time = sequence1(rt,choice)
% This program will convert the rt sequence
% to a sequenece of 1s and 0s where
% 1 = choice
% 0 = non-choice
% Additionally we will also clip any rt to 20000 ms

time=[];
for i = 1:2:length(rt)-1
    if rt(i) == choice
        time = cat(1,time,ones(rt(i+1),1));
    else
        time = [time;zeros(rt(i+1),1)];
    end
end

if length(time)>20000
    time = time(end-20000+1:end);
else
    time=cat(1,NaN(20000-length(time),1),time);
end
%time=downsample(time,5);
end