files = {'SS_walking1.anc', 'slow_walking_75_1.anc', 'slow_walking_50_1.anc', 'fast_walking_1.anc'};
static_file = 'Static1.anc';

offsets = zeros(length(files), 12);
for i=1:length(files)
	[q, o] = process_grf(files{i},'','',1);
	offsets(i,:) = [o(1).meanF o(1).meanM o(2).meanF o(2).meanM];
	disp(sprintf('FILE = %s', files{i}));
	%disp(sprintf('meanF: [1] = %f %f %f', o(1).meanF(1), o(1).meanF(2), o(1).meanF(3)));
	%disp(sprintf('       [2] = %f %f %f', o(2).meanF(1), o(2).meanF(2), o(2).meanF(3)));
	%disp(sprintf('meanM: [1] = %f %f %f', o(1).meanM(1), o(1).meanM(2), o(1).meanM(3)));
	%disp(sprintf('       [2] = %f %f %f', o(2).meanM(1), o(2).meanM(2), o(2).meanM(3)));
end

mean_offsets = mean(offsets);
range_offsets = range(offsets);

static = read_anc(static_file, delaware_lcs);

for fp=1:2
	if fp==1
		off = 0;
	else
		off = 6;
	end

	disp(sprintf('Force plate %d',fp));
	disp(sprintf('meanF: %f (%f), %f (%f), %f (%f)', ...
						mean_offsets(off+1), range_offsets(off+1), ...
						mean_offsets(off+2), range_offsets(off+2), ...
						mean_offsets(off+3), range_offsets(off+3)));
	disp(sprintf('meanM: %f (%f), %f (%f), %f (%f)', ...
						mean_offsets(off+4), range_offsets(off+4), ...
						mean_offsets(off+5), range_offsets(off+5), ...
						mean_offsets(off+6), range_offsets(off+6)));

	static_meanF = mean(static.data(fp).F);
	static_meanM = mean(static.data(fp).M);

	disp(sprintf('Static forces before applying offsets'));
	disp(sprintf('Mean F = %f, %f, %f', static_meanF(1), static_meanF(2), static_meanF(3)));
	disp(sprintf('Mean M = %f, %f, %f', static_meanM(1), static_meanM(2), static_meanM(3)));

	static_meanF = static_meanF - mean_offsets(off+(1:3));
	static_meanM = static_meanM - mean_offsets(off+(4:6));
	disp(sprintf('Static forces after applying offsets'));
	disp(sprintf('Mean F = %f, %f, %f', static_meanF(1), static_meanF(2), static_meanF(3)));
	disp(sprintf('Mean M = %f, %f, %f', static_meanM(1), static_meanM(2), static_meanM(3)));
end
