function barGrid4(fname, varargin)

% create bargraph from 'gridanalyzer4' output, written to "fname"
%
% default bin sizes [1-10 10-20 20-30 30+] with edges
%   [1 10 20 30 Inf]
% can be overridden by sending optional arg 'edg'

figure;
% set histogram bins
edg = [1 10 20 30 Inf]; 
if nargin>1
    edg = varargin{1};
end

% open file
fid = fopen(fname,'r');

% read in file;
% assumes header line "1.0      2.0      3.0      5.0      7.5     10.0     15.0     30.0     60.0"
% for columns 2-end
C = textscan(fid, '%d %d %d %d %d %d %d %d %d %d',...
    'headerlines',1);
fclose(fid);

% parse to variables
N = C{1};                   % number of points per cell
D = cell2mat(C(2:end));     % number of cells with that many points
g = [1 2 3 5 7.5 10 15 30 60]; % grid spacing

% cat into specified bins, and build bin labels
for i = 2:length(edg)
    q = find(N<=edg(i)-1 & N>=edg(i-1));
    B(i-1,:) = sum(D(q,:),1);
    binLbl{i-1} = sprintf('%d-%d', edg(i-1),edg(i)-1);
end

% plot histogram
bar(B')
set(gca,'XTickLabel',num2str(g'));
xlabel('grid size [minutes]')
ylabel('# of cells')
legend(binLbl)
ylim([0 500])


