% Peplot.m is used to generate the master files.
clear all;
%To run this, start with the name of the first subject according to the list 
 child={'Alina','Angela','Anton','Bob','Carly','Edward','Evan','Joanna','Latisha','Laura','Miguel','Norene','Shauna','Teddy','Tony'};

% After that on line 8, start with m=1, and keep incrementing by 1 on every
% subsequent iteration of the program till m=15 (when all 15 subjects have 
% been included).

vow=['@' 'A' 'E' 'I' 'O' 'R' 'U' 'W' 'Y' 'a' 'c' 'e' 'i' 'o' 'u'];
cons=['C' 'D' 'G' 'H' 'J' 'S' 'T' 'Z' 'b' 'd' 'f' 'g' 'h' 'k' 'L' 'm' 'n' 'p' 'r' 's' 't' 'v' 'w' 'y' 'z'];

%raw=DataNSCM_Tony;
%m=15;

% initialize using this in the begining. Only to be used when m=1 and
% raw=DataNSCM_Alina

mastconf=zeros(15,50);
mastconb=zeros(15,50);
mastvowf=zeros(15,30);
mastvowb=zeros(15,30);

for m=1:15 %loop over children

sname=child{m};
aname=['DataNSCM_',sname];
fname=['DataNSCM/DataNSCM_',sname];
disp(sprintf('Filename= %s',fname))

%Read in the raw data
x=struct2cell(load(fname,aname));
raw = x{1}; %dereference the 1x1 cell array
clear x sname aname fname

for i=2:length(raw)
    
   ind=strfind(cons,raw{i,4}(1));
   
   if isempty(ind)
       % Vowel front and consonant back
       indv=strfind(vow,raw{i,4}(1));
       indc=strfind(cons,raw{i,4}(2));
       
       % Increase N of respective consonant and vowel
       mastvowf(m,15+indv)= mastvowf(m,15+indv)+1;
       mastconb(m,25+indc)= mastconb(m,25+indc)+1;
       
       if ~isempty(strfind(raw{i,5},raw{i,4}(1)))
           mastvowf(m,indv)= mastvowf(m,indv)+1;
           
       elseif  ~isempty(strfind(raw{i,6},raw{i,4}(1))) 
           mastvowf(m,indv)= mastvowf(m,indv)+1;
           
       elseif  ~isempty(strfind(raw{i,7},raw{i,4}(1)))
           mastvowf(m,indv)= mastvowf(m,indv)+1;
           
       elseif  ~isempty(strfind(raw{i,8},raw{i,4}(1)))
           mastvowf(m,indv)= mastvowf(m,indv)+1;
          
       end 
       
       if ~isempty(strfind(raw{i,5},raw{i,4}(2)))
           mastconb(m,indc)= mastconb(m,indc)+1;
           
       elseif  ~isempty(strfind(raw{i,6},raw{i,4}(2))) 
           mastconb(m,indc)= mastconb(m,indc)+1;
           
       elseif  ~isempty(strfind(raw{i,7},raw{i,4}(2)))
           mastconb(m,indc)= mastconb(m,indc)+1;
           
       elseif  ~isempty(strfind(raw{i,8},raw{i,4}(2)))
           mastconb(m,indc)= mastconb(m,indc)+1;
          
       end 
       
   else 
       
       % Vowel back Consonant front
       indv=strfind(vow,raw{i,4}(2));
       indc=strfind(cons,raw{i,4}(1));
       
       mastvowb(m,15+indv)= mastvowb(m,15+indv)+1;
       mastconf(m,25+indc)= mastconf(m,25+indc)+1;
       
       if ~isempty(strfind(raw{i,5},raw{i,4}(1)))
           mastconf(m,indc)= mastconf(m,indc)+1;
           
       elseif  ~isempty(strfind(raw{i,6},raw{i,4}(1))) 
           mastconf(m,indc)= mastconf(m,indc)+1;
           
       elseif  ~isempty(strfind(raw{i,7},raw{i,4}(1)))
           mastconf(m,indc)= mastconf(m,indc)+1;
           
       elseif  ~isempty(strfind(raw{i,8},raw{i,4}(1)))
           mastconf(m,indc)= mastconf(m,indc)+1;
          
       end 
       
       if ~isempty(strfind(raw{i,5},raw{i,4}(2)))
           mastvowb(m,indv)= mastvowb(m,indv)+1;
           
       elseif  ~isempty(strfind(raw{i,6},raw{i,4}(2))) 
           mastvowb(m,indv)= mastvowb(m,indv)+1;
           
       elseif  ~isempty(strfind(raw{i,7},raw{i,4}(2)))
           mastvowb(m,indv)= mastvowb(m,indv)+1;
           
       elseif  ~isempty(strfind(raw{i,8},raw{i,4}(2)))
           mastvowb(m,indv)= mastvowb(m,indv)+1;
          
       end 
       
   end    
       
       
       
       
end    


end %for m=1:15 %loop over children
clear raw child cons i ind indc incv m vow indv
%Now save the data in the mat files
save DataNSCM\mastvowf mastvowf
save DataNSCM\mastvowb mastvowb
save DataNSCM\mastconf mastconf
save DataNSCM\mastconb mastconb
