%function plotTiming(multi)
function plotTiming(multi)

if nargin,
	close all,
	d=dir('200*');
	if length(d) == 0,
		disp('No log directories found')
		return
	end
	for ii=1:length(d),
		cd(d(ii).name)
		if myPlotTiming, return, end
		cd ..
	end
else
	myPlotTiming;
end

%%%%%%%%%%%%%%%%%%%%%%
function res = myPlotTiming
res = 1;

jj = 1;
d = dir('*.mat');
minTime = inf;
for ii=1:length(d),
	s = load(d(ii).name);
	fields = fieldnames(s);
	str = getfield(s,fields{1});
	if isfield(str,'time'),
		timeCell{jj} = str.time;
		nameCell{jj} = [strtok(d(ii).name,'_.') '::time'];
		jj = jj+1;
	end
	if min(str.time) < minTime, minTime = min(str.time); end
end

[index,v] = listdlg('Name','Select logs:','ListString',nameCell);
if isempty(index), return, end

figure
for ii=1:length(index),
	subplot(2,1,1)
	t = timeCell{index(ii)};
	s = cm;
	h(ii) = plot(t-minTime,1:length(t),[s '.-']); hold on
	
	subplot(2,1,2)
	dt = diff(t);
	plot(t-minTime,[dt;0],[s '.-']), hold on
	
	legendCell{ii} = nameCell{index(ii)};
end

subplot(2,1,1)
grid on
title([strip(pwd,'\','/') ' \copyright Bluefin Robotics'])
ylabel('Log index')
xl = xlim;
h(end+1) = line([0 xl(end)],[0 5*xl(end)],'Color','k','LineStyle','--', ...
	'LineWidth',3);
legendCell{end+1} = '5 Hz';
legend(h,legendCell,2)

subplot(2,1,2)
xlabel(['Start time = ' num2str(minTime) ' (seconds)'])
ylabel('Delta time')
grid on
zoom yon
xl = xlim;
line([0 xl(end)],[0.2 0.2],'Color','k','LineStyle','--','LineWidth',2)

res = 0;