function check_errors(subject, trial)
%subject='delaware3';
%trial='ss_walking1';
%trial='slow_walking_50_1';
%trial='fast_walking_1';

rra1dir='Results';
rra2dir='Results';
cmcdir='ResultsCMC';
forwarddir='ResultsForward';


file=sprintf('%s/%s_%s_ik_pErr.sto',rra1dir,subject,trial);
if ~exist(file,'file')
	file=sprintf('%s/%s_%s_RRA1_pErr.sto',rra1dir,subject,trial);
end
if exist(file,'file')
	disp('RRA 1');
	q1=read_motionFile(file);
	disp(sprintf('Max translation error (m) = %s', max_column_info(q1.labels,q1.data,2:4)));
	disp(sprintf('Max angle error (deg) = %s', max_column_info(q1.labels,q1.data,5:length(q1.labels),180/pi)));
end

file=sprintf('%s/%s_%s_ik_rra_pErr.sto',rra2dir,subject,trial);
if ~exist(file,'file')
	file=sprintf('%s/%s_%s_RRA2_pErr.sto',rra2dir,subject,trial);
end
if exist(file,'file')
	disp('RRA 2');
	q1=read_motionFile(file);
	disp(sprintf('Max translation error (m) = %s', max_column_info(q1.labels,q1.data,2:4)));
	disp(sprintf('Max angle error (deg) = %s', max_column_info(q1.labels,q1.data,5:length(q1.labels),180/pi)));
end

file1=sprintf('%s/%s_%s_ik_Kinematics_q.sto',rra1dir,subject,trial);
if ~exist(file1,'file')
	file1=sprintf('%s/%s_%s_RRA1_Kinematics_q.sto',rra1dir,subject,trial);
end
file2=sprintf('%s/%s_Kinematics_q.sto',cmcdir,subject);
if ~exist(file2,'file')
	file2=sprintf('%s/%s_%s_Kinematics_q.sto',cmcdir,subject,trial);
end
if exist(file1,'file') & exist(file2,'file')
	disp('CMC');
	q1=read_motionFile(file1);
	q2=read_motionFile(file2);
	tmin=max(q1.data(1,1),q2.data(1,1));
	tmax=min(q1.data(end,1),q2.data(end,1));
	T=tmin:0.0001:tmax;
	columns=1:length(q1.labels);
	d1=interp1(q1.data(:,1),q1.data(:,columns),T);
	d2=interp1(q2.data(:,1),q2.data(:,columns),T);
	d=abs(d1-d2);
	ignorelabels=find_columns_by_label(q1.labels,{'tib_pat','knee_l_t','knee_r_t'});
	disp(sprintf('Max translation error (m) = %s', max_column_info(q1.labels,d,2:4)));
	disp(sprintf('Max angle error (deg) = %s', max_column_info(q1.labels,d,setdiff(5:length(q1.labels),ignorelabels))));
end

file1=sprintf('%s/%s_Kinematics_q.sto',cmcdir,subject);
if ~exist(file1,'file')
	file1=sprintf('%s/%s_%s_Kinematics_q.sto',cmcdir,subject,trial);
end
file2=sprintf('%s/%s_Kinematics_q.sto',forwarddir,subject);
if ~exist(file2,'file')
	file2=sprintf('%s/%s_%s_Kinematics_q.sto',forwarddir,subject,trial);
end
if exist(file1,'file') & exist(file2,'file')
	disp('Forward');
	q1=read_motionFile(file1);
	q2=read_motionFile(file2);
	tmin=max(q1.data(1,1),q2.data(1,1));
	tmax=min(q1.data(end,1),q2.data(end,1));
	T=tmin:0.0001:tmax;
	columns=1:length(q1.labels);
	d1=interp1(q1.data(:,1),q1.data(:,columns),T);
	d2=interp1(q2.data(:,1),q2.data(:,columns),T);
	d=abs(d1-d2);
	ignorelabels=find_columns_by_label(q1.labels,{'tib_pat','knee_l_t','knee_r_t'});
	disp(sprintf('Max translation error (m) = %s', max_column_info(q1.labels,d,2:4)));
	disp(sprintf('Max angle error (deg) = %s', max_column_info(q1.labels,d,setdiff(5:length(q1.labels),ignorelabels))));
	for t=[1 1.5 1.8 1.9 1.95 2 2.5 T(end)]
		endindex=find(abs(T-t)<1e-8);
		if length(endindex)>0
			disp(sprintf('TIME = %f :: Max angle error (deg) = %s', t, max_column_info(q1.labels,d(1:find(abs(T-t)<1e-8),:),setdiff(5:length(q1.labels),ignorelabels))));
		end
	end
end
