function  batrunanalysis(outlistname, resetanova)


global Userinput Expstreams Explags Expstreamnums ExpEvents Exptime numnames outlist outlist2

global rt startrt rtlist dottime compact T1r T2r T2rc T2rnc T1rc Trialcount Swap Both rtcount means ITEMS
global dotcount dotprofile samestream diffstream condcopy evcopy dotsatpos dotacc persubmeans Or ors

global numtrials subjfile4 cstringssubject reporder strings cstrings  cstringssubjectmax numallgood avgreporder subjfile3  filename temptop tempbottom





ft = fopen(outlistname,'r');

outlist = fscanf( ft ,'%s');

fclose(ft);

a = size(outlist,2);
sofar = 1
last = 1;
i = 1;

filename = 'Cond'

 subjfile3 = fopen(sprintf('dataout%s.txt',filename), 'w');

 filename = 'UnCond'
 subjfile4 = fopen(sprintf('dataout%s.txt',filename), 'w');


for(i=1:a-3)
    if(sum(outlist(i:i+3)== '.mat') == 4)

        outlist2{sofar} = outlist(last:i+3);
        last = i+4;
        sofar = sofar + 1;
    end
end

sofar = sofar - 1;
newone = 0;
oldname = 'xxx'
numnames = 0;
for i=1:sofar

    load(outlist2{i})
    if(i ==1)
        newanalyzedots(1,1)
    elseif(i/2 < ceil(i/2))   %newsub
        newanalyzedots(0,1)
    else
        newanalyzedots(0,0)
        subcstrings((i/2),1:6,1:6,1) = reshape(cstringssubject(:,:,:),[1,6,6,1]);   %end of a subject, compile his data
      
        subresp((i/2),1:6,1:6,1) = reshape(cstringssubjectmax(:,:,:),[1,6,6,1]);
       
        
        
        subtop((i/2),1:6,1:2) = reshape(temptop,[1,6,2]);
        subbottom((i/2),1:6,1:2) = reshape(tempbottom,[1,6,2]);
        
        avgsubtop((i/2),1,1:2) = reshape(sum(temptop,1),[1,1,2]);
          avgsubbottom((i/2),1,1:2) = reshape(sum(tempbottom,1),[1,1,2]);
        
    end


end


%T1r = T1r/Trialcount(1,1)


for(i = 1:size(reporder,1))
    for(j = 1:size(reporder,2))
        avgreporder(i,j,:,:) = reporder(i,j,:,:) /numallgood(i,j);
    end
end


subjfile = fopen('persubmeans.csv', 'w');

 
 for(j = 1:size(persubmeans,1))
     fprintf(subjfile, '%g, %g, %g, %g, %g, %g,,,,  ', subcstrings(j,:,1,1)/subresp(j,1,1,1));
     fprintf(subjfile, '%g, %g, %g, %g, %g, %g \n  ', subcstrings(j,:,2,1)/subresp(j,1,2,1));
  %   fprintf(subjfile, '%g, %g, %g, %g, %g, %g,,  ', subcstrings(j,:,3,1)/subresp(j,3,1));
  %   fprintf(subjfile, '%g, %g, %g, %g, %g, %g,,  ', subcstrings(j,:,4,1)/subresp(j,4,1));
  %   fprintf(subjfile, '%g, %g, %g, %g, %g, %g,,  ', subcstrings(j,:,5,1)/subresp(j,5,1));
  %   fprintf(subjfile, '%g, %g, %g, %g, %g, %g \n', subcstrings(j,:,6,1)/subresp(j,6,1));
 
 end
 
 

 
 

 
 %in the order analysis, numtop is the number of swaps that did occur
 %between ordered items
 
      fprintf(subjfile, '\n\n\nNumtop\n\n');
for(j = 1:size(persubmeans,1))
     fprintf(subjfile, '%g, %g, %g, %g, %g, %g,,',subtop(j,:,1));
     fprintf(subjfile, '%g, %g, %g, %g, %g, %g\n',subtop(j,:,2));
end

%numbottom is the potential number of swaps that could have occurred. 

 
fprintf(subjfile, '\n\n\nNumbottom\n\n');
for(j = 1:size(persubmeans,1))
     fprintf(subjfile, '%g, %g, %g, %g, %g, %g,,',subbottom(j,:,1));
     fprintf(subjfile, '%g, %g, %g, %g, %g, %g\n',subbottom(j,:,2));
end


fp= fopen('orderout.txt', 'w');
avg = 0;
for(j = 1:size(persubmeans,1))
     fprintf(fp, '%g\n',avgsubtop(j,:,1)/avgsubbottom(j,:,1));
     avg = avg + avgsubtop(j,:,1)/avgsubbottom(j,:,1);
end

  fprintf(fp, '\n%g\n\n\n',avg/size(persubmeans,1));


avg = 0;
for(j = 1:size(persubmeans,1))
     fprintf(fp, '%g\n',avgsubtop(j,:,2)/avgsubbottom(j,:,2));
      avg = avg + avgsubtop(j,:,2)/avgsubbottom(j,:,2);
end

  fprintf(fp, '\n%g\n\n\n',avg/size(persubmeans,1));




fclose(fp)
 

subjfile2 = fopen('dataoutavg.txt', 'w');

for(j = 1:size(persubmeans,1))
    for(pos = 1:6)
        for(soa = 1:2)
            for(idd = 1:1)
                              
                fprintf(subjfile2, '%d\t%d\t%d\t%d\t%.5g\n', j,pos,soa,idd,subcstrings(j,pos,soa,idd)/subresp(j,soa,idd));
            end
        end
    end
end




fclose(subjfile);
fclose(subjfile2);
fclose(subjfile3);

fclose(subjfile4);
showresults




