global T

%valLambda = 0.5;

cd('database');
D = dir;

reference = {'eight1.mat'};
%reference = {'three8.mat' 'g3.mat' 'seven1.mat' 'U6.mat' 'one3.mat'};
%reference = {'two9.mat' 'small-b9.mat'  'eight1.mat' 'V1.mat' 'six5.mat' };
%reference = {'averages/yAvg.mat'};
%'averages/eightAvg1.mat'
    
for i=1:size(reference,2),

	name1 = char(reference(i));
	load(name1);
	curve1 = curve;

    length1 = size(name1,2);
    outFileName = sprintf('%stxt',name1(1:length1-3));
    FID = fopen(outFileName, 'wt');
	% filenames start at 3
	for j=3:size(D,1),
        name2 = D(j).name;
        length = size(name2,2);
        % check file type
        if(strcmp(name2(length-3:length), '.mat')==0)
            continue;
        end
        load(name2);
        curve2 = curve;
        disp(sprintf('processing %s and %s...', name1, name2));
        % get T values
%        processShapeContexts;
%        processShapeContNonSquareGrid;
%        processCurvNonSquareGrid;
        processCurvature;
        [m, n] = size(T); 
%        distance = T(end, end) - valLambda*sqrt(m*m + n*n) + abs(1 - min(m,n)/max(m,n))
        curve_distance = T(end, end);
        diag_integral = valLambda*sqrt(m*m + n*n);
		distance = curve_distance - diag_integral + abs(1 - min(m,n)/max(m,n));
        fprintf(FID, '%s \t %s \t %f \n', name1, name2, distance);
	end
	%end
	fclose(FID);

end

cd ..
