global In1 Expkeyspressed Expkeycount Userinput Explags Expstreams Expstreamnums Expstreams2 Expstreamnums2 Exptime Condition ExpEvents Miscflag Expmiscflag Thiscondition ExpCondition ExpThiscondition priorcondition

global rt startrt rtlist dottime compact T1r T2r Trialcount Swap Both 



ExpCondition = ExpThiscondition;

%THE RT SECTION

rtcount = [0,0,0,0,0];

rtlist = 0;
startrt = zeros(300,1);
for(i=1: size(Expkeycount,1))		
	%	get the RT
	if(Expkeycount(i,1)==1)
		startrt(i) = Expkeyspressed(i,1,1);
	elseif(Expkeycount(i,1)==2)
		if(Expkeyspressed(i,1,2) ==37)  %The first key was enter!
			startrt(i) = Expkeyspressed(i,2,1);
		end				
	end

	%when was the dot
	[x ind] = max(abs(ExpEvents(i,:,4) ==2));
	dottime(i) = Exptime(i,ind);
	%THIS SUBTRACTION IS ONLY FOR MARK
	
	startrt(i);
	if(Expkeycount(i) > 0 & ExpCondition(6,i) ==0)
		rt(i) = startrt(i)-(dottime(i));%	-Exptime(i,1));
	else
		rt(i) = 0;
	end
	
	
	if(rt(i)>0 & rt(i) < 1)
		%& ExpCondition(6,i)==0		
		dotpos = 	ExpCondition(4,i);
		lag = ExpCondition(1,i);
		
		if ((dotpos ==0) &   ExpCondition(2,i) == ExpCondition(3,i))  %after T1, and same stream
			dott = 1;
		elseif ((dotpos ==0)  & ExpCondition(2,i) ~= ExpCondition(3,i))   %after T1 and diff stream
			dott =2;
		elseif (dotpos ==1 & lag ==2 & ExpCondition(2,i) == ExpCondition(3,i) )  %after T2 lag 2
			dott = 3;
		elseif  (dotpos ==1 & lag ==2 & ExpCondition(2,i) ~= ExpCondition(3,i) )
			dott=4;
		elseif(dotpos ==1 & lag ==6)  %after T2 lag 6
			dott = 5;	
		end
	

		rtcount(dott) = 		rtcount(dott) +1;
		rtlist(dott, rtcount(dott)) = rt(i);
	end
end

for(i = 1:5)
	means(i)=	mean(rtlist(i,1:rtcount(i)));
end

'The means for the 4 positions, in order, were'
means


Trialcount = zeros(2,1);
T1r = zeros(2,1);
T2r = zeros(2,1);
Swap= zeros(2,1);
Both = zeros(2,1);
%the accuracy BIT
for(i=1: size(Expkeycount,1))		
	
	if(ExpCondition(6,i) > 0 )   % was this a dot trial?
		t1s = 0;
		[x T1pos] = min(abs(Expstreams(i,:)-1));
		if(x~=0)
			[x T1pos] = min(abs(Expstreams2(i,:)-1));
			t1s= 1;
		end	
		t2s = 0;
		[x T2pos] = min(abs(Expstreams(i,:)-2));
		if(x~=0)
			[x T2pos] = min(abs(Expstreams2(i,:)-2));
			t2s = 1;
		end	
	
		%which event 
		t1e = (T1pos-1)*2+1+t1s;
		t2e = (T2pos-1)*2+1+t2s;
		
		T1set = ExpEvents(i,t1e,2);
		T2set = ExpEvents(i,t2e,2);
		if(~t1s)
			T1item = ITEMS(T1set,Expstreamnums(i,T1pos));   
		else
			T1item = ITEMS(T1set,Expstreamnums2(i,T1pos));   
		end
		if(~t2s)
			T2item = ITEMS(T2set,Expstreamnums(i,T2pos));   
		else
			T2item = ITEMS(T2set,Expstreamnums2(i,T2pos));   
		end
	
		lag = T2pos-T1pos;
		compact(i,2) = lag;
		compact(i,3) = T1item;
		compact(i,4) = T2item;
		
		
		
		
        if(Userinput(i,3) > 13)        %we have to trim some
            for(count = 1:size(Userinput,2))
                t = Userinput(i,count);
                if(t>97)
                    t = t - 32;
				end
                if(t ~= T1item & t ~=T2item)
                    for(count2 = count+1:size(Userinput,2))
                        Userinput(i,count2-1) = Userinput(i,count2);
                        
					end
				end
			end
		end
	
		compact(i,5) = Userinput(i,1);
        if(compact(i,5) > 96)
            compact(i,5) =             compact(i,5) - 32;  %lowercase
		end
        if(size(Userinput,2) >1)
            compact(i,6) = Userinput(i,2);
		else
            compact(i,6) = 0;
		end
	
        if(compact(i,6) > 96)
            compact(i,6) =             compact(i,6) - 32;  %lowercase
		end               
	
		if (lag ==2)
			lag =1; 
		else 
			lag = 2;
		end
		Trialcount(lag) = Trialcount(lag) +1;
		if(compact(i,3) == compact(i,5) |compact(i,3) == compact(i,6))
			T1r(lag) = T1r(lag)+1;	
		end
		if(compact(i,4) == compact(i,5) |compact(i,4) == compact(i,6))
			T2r(lag) = T2r(lag)+1;	
		end
	
		if(compact(i,3) == compact(i,6) &compact(i,4) == compact(i,5))		
			Swap(lag) = Swap(lag) + 1;
		end
	
		if((compact(i,3) == compact(i,5) |compact(i,3) == compact(i,6)) &(compact(i,4) == compact(i,5) |compact(i,4) == compact(i,6)))
			
			Both(lag) = Both(lag) + 1;
		end
	end
end

