clear; 

mex Ctransform.c; 
mex CMax1.c; 
mex CSum2.c; 
mex CMax2.c; 
mex CSum3.c; 
mex CBackMax2.c
mex CBackMax1.c

load 'model';

getS1M1; 

nbasis = 2; 

MmAll = zeros(nbasis, length(Mi)); 
Mm1All = zeros(nbasis, length(Mi)); 
MxAll = zeros(nbasis, length(Mi)); 
MyAll = zeros(nbasis, length(Mi)); 
MiAll = zeros(nbasis, length(Mi)); 
sxAll = zeros(1, nbasis); syAll = zeros(1, nbasis); 
cxAll = zeros(1, nbasis); cyAll = zeros(1, nbasis); 

showon = 0; 
splits = 20:15:(sy-20);
M3All = zeros(1, length(splits));
isplit = 0; 
for midY = splits; 
    isplit=isplit+1;
    disp(['----> computing Sum-Max maps for split number ' num2str(isplit)]);
    getSubTemplates; 
    getS2M2; 
    getS3M3; 
    getBackAndSketch; 
    M3All(isplit) = M3score;  
end
    
figure; h1=plot(M3All); 
title('Alignment score vs Split point'); xlabel('Split point'); ylabel('Score');
set(gca,'FontSize',16); % adjust the display format and save the plot
set(get(gca,'XLabel'),'FontSize',18);
set(get(gca,'YLabel'),'FontSize',18);
set(get(gca,'Title'),'FontSize',20);
set(h1,'Linewidth',3);
set(gcf, 'PaperPositionMode', 'auto');
print('-depsc', ['ex7_Splitscore' '.eps']);

[M3Max splitMax] = max(M3All);  
showon = 1; 
midY = splits(splitMax); 
    getSubTemplates; 
    getS2M2; 
    getS3M3; 
    getBackAndSketch; 
    


