function runexp(block)


%stream pattern
global ITEMPRESENT ITEMOFF RANDOMBGCOLOR ONTIMINGVARIATION OFFTIMINGVARIATION ITEMS SIZES LOCATIONSX LOCATIONSY COLORS BACKCOLORS FRAMECOLOR ITEMSETS 
%stream structure
global PREITEMS POSTITEMS MINRSVPLENGTH P1BLANKPERCENTAGE M1BLANKPERCENTAGE MAXTARGETS MINTARGETS SKELETAL STARTVARIANCE LAGS NUMSTREAMS

%frame parameters

global Axeshandle ITEMPools Setsize  Fixcross

%thisstream

global Targpos Targlag Streamlength Stream Streamnum Stream2 Streamnum2 Targnum Events Dpos Dnum Time Numtargs Eventscopy Trialnum

%user data

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

%screens
global window woff wblank centerx centery wsize Userinput2

global keycount keyspressed NUMSTREAMS s_lname

%addpath 'C:\Documents and Settings\bw5\model\presenter'
load PARMFILE
setup

if(NUMSTREAMS < 50)
	'PRACTICE'
end


hidecursor





Explags = 0;
Expstreams = 0;
Expstreamnums = 0;
Exptime = 0
ExpEvents = 0;
Userinput = 0;
Expkeyspressed = 0;
Expkeycount = 0;

%sprintf('Going to run %d streams of %d on and %d off for SOA of %d',Numstreams,ITEMPRESENT*1000,ITEMOFF*1000,(ITEMPRESENT+ITEMOFF)*1000)
%Expdata = zeros(7,Numstreams);


preparescreen    


ExpEvents = 0;    
Expstreams = 0;
Expmiscflag = 0;
ExpThiscondition = 0;    

s = sprintf('Press Enter To Continue')
SCREEN(window,'DrawText',s,10,200,[10,10,10]);

a = GetChar;
Screen('CopyWindow',wblank,window);

ExpCondition = Condition;

for(s = 1:NUMSTREAMS)
    sprintf('Trial %d',s)
    Trialnum = s;
    
    priorcondition = Condition;
    
    basicpreparestream;
    showstream
    Thiscondition
    a = size(Events,1);
	% Events(:,1) =    Events(:,1)  - 99999; 
    ExpEvents(s,1:a,1:7) = reshape( Eventscopy,[1,a,7]);
    Userinput(s,1:length(In1)) = In1;
	Userinput2(s,1:length(In2)) = In2;
    Explags(s,1:length(Targlag)) = Targlag;
    Expstreams(s,1:Streamlength) = Stream;
    Expstreamnums(s,1:Streamlength) = Streamnum;     

	
	Expkeyspressed(s,1:10,1:2) = reshape(keyspressed(1:10,1:2),[10,2]);
	
	Expkeycount(s,1) = keycount;
    
	
	if(size(Miscflag,1) > 0)
        Expmiscflag(s,1) = Miscflag;
	else
        Expmiscflag(s,1) = 1;
	end

    ExpThiscondition(1:6,s) = priorcondition(1:6,Thiscondition)
	a = length(Time)-1;
       Exptime(s,1:a) = Time(1:a);

	if(5*ceil(s/5) ==s)	
		save('tempdata','Expkeyspressed','Expkeycount','Userinput','Expstreams','Explags','Expstreamnums','ExpEvents','Exptime','ExpCondition', 'Expmiscflag','ExpThiscondition','ITEMS');
	end

end

showcursor

Screen(window,'Close')
clear Screen
name = sprintf('%s%d',s_lname,block);

if(NUMSTREAMS > 50)
	save(name,'Expkeyspressed','Userinput2','Expkeycount','Userinput','Expstreams','Explags','Expstreamnums','ExpEvents','Exptime','ExpCondition', 'Expmiscflag','ExpThiscondition','ITEMS');
else
	save('practice','Expkeyspressed','Userinput2','Expkeycount','Userinput','Expstreams','Explags','Expstreamnums','ExpEvents','Exptime','ExpCondition', 'Expmiscflag','ExpThiscondition','ITEMS');
end


