%function sum_coord.m
%

amount=[1];
in=spm_get(1,'*.txt','Choose a Talairach Daemon output file')
file=textread(in,'%s','delimiter','\n','whitespace','');
final={'Level1   ,Level2   ,Level3   ,Level4   ,Level5     '};
[k,l]=size(file);
for i=1:k
   tmp=char(file(i));
	commas=findstr(',',tmp);
	[n,m]=size(tmp);
   tmp2=tmp(commas(4)+1:m);
   %tmp2 is the important part of line 'i' of the 
   %input file
	bool=strcmp(final,tmp2);
   %this makes the comparison between the out file (final)
   %and the in final (tmp2)
if bool==0
   [o,p]=size(final);
   final{p+1}=tmp2;
   amount=[amount,1];
else
   position=find(bool);
   amount(position)=amount(position)+1;
end;
end
%slash=findstr('\',in);
%dot=findstr('.',in);
[PATH,NAME,EXT]=fileparts(in)


out=cat(2,'total_',NAME,'.txt')
fid=fopen(out,'a');

%UP to this point works!!!!
[m,n]=size(final);
for j=1:n
   temp=final{j};
   temp2=cat(2,temp,',',num2str(amount(j)));
   fprintf(fid,temp2);
   
   fprintf(fid,'\n');
end
status=fclose(fid);

clear
