function time_chart = get_map_times(atlas)

%first get the time range
if (isfield(atlas.res(1),'scanmatch_res'))
    min_time = atlas.res(1).scanmatch_res(1,1);
elseif ~isempty(atlas.res(1).laserlines_res)
    min_time = atlas.res(1).laserlines_res(2,1);
else
    min_time = atlas.res(1).sonarline_res(2,1);
end
max_time = min_time;

numM = length(atlas.map);

for i=1:numM
    if (isfield(atlas.res(i),'scanmatch_res'))
        max_time_i = max(atlas.res(i).scanmatch_res(1,:));
    elseif ~isempty(atlas.res(1).laserlines_res)
        max_time_i = max(atlas.res(i).laserlines_res(2,:));
    else
        max_time_i = max(atlas.res(i).sonarline_res(2,:));
    end
    if length(max_time_i)
        max_time = max(max_time,max_time_i);
    end
end

disp (['Time range ' num2str((max_time-min_time)/60) ' minutes.'])

t = linspace(min_time-10,max_time+10,1000);
t = min_time-3:max_time+1;

time_chart = sparse(numM,length(t));

for i=1:numM
    if (isfield(atlas.res(i),'scanmatch_res'))
        ti = atlas.res(i).scanmatch_res(1,:);
    elseif ~isempty(atlas.res(1).laserlines_res)
        ti = atlas.res(i).laserlines_res(2,:);
    else
        ti = atlas.res(i).sonarline_res(2,:);
    end
    if ~isempty(ti)
        j = interp1(t,1:length(t), ti, 'nearest');
        time_chart(i,j) = 1;
    end
end

%subplot('position',[0 .25 .75 .75])
subplot(4,4,[1 2 3 5 6 7 9 10 11])
%spy(time_chart,6)
[j,i] = find(time_chart);
plot(i/60,j,'.')
axis tight
axis xy
ylabel('Map ID')

%subplot('position',[0 0 .75 .25])
subplot(4,4,[13 14 15])
s = sum(time_chart,1);
if (0) s(find(s>5)) = 5; end
bar((1:length(s))/60,s)
axis tight
xlabel('time (minutes)')
ylabel('# of hyps')

%subplot('position',[.75 .25 .25 .75])
subplot(4,4,[4 8 12])
barh(sum(time_chart,2)/60)
%axis ij
set(gca,'ylim',[0 numM+1])
xlabel('total activity time')

subplot(111)

return

print -depsc z:/my_papers/atlas_nav/map_times.eps

