function gridstats2(fstr, varargin)

% set grid sizes to be analyzed
grd = [60 120 180 300 450 600 900 1800]; % grid sizes

% plot all vectors and link with subsequent plots
b = strsplit(fstr,'.');
fname = [fileparts(fstr) '/vmacd' sprintf('%s.%s.%s.%s',...
    b{1}(end-2:end),b{2:4})]
[pid,pt] = plotVectors(fname,1);

% set bins for vector length histogram
ll = [min(pt(:,4)) max(pt(:,4))];
B = [-Inf ll(1):(diff(ll))/6:ll(2) Inf]; % horizontal
if (nargin>2 & ~isempty(varargin))
    B = varargin{1};
end

% loop through grids; plot and generate/output stats
%warning('off');
for i = 1:length(grd)
    fname = sprintf('%s.%d',fstr,grd(i));
    [p,v] = readVectorFile(fname);
    % print out names of points 
%     fprintf('%8d%10d  ',grd(i),length(p));
%     fprintf('%s,',p{:});
%     fprintf('\n');
    % print out number of points in lat range
    q = find(v(:,2)<16);
    fprintf('%8d%8d\n',grd(i),length(q));
% print out names of points north of 16 deg lat
% q = find(v(:,2)>16);
% [s,ii] = sort(v(q,2));
% fprintf('>>>> grid %d , %d points\n',grd(i),length(q));
% for j = 1:length(q)
%     fprintf('%10.2f',v(q(ii(j)),2));
%     fprintf('%10s\n',p{q(ii(j))});
% end
    if i==1
        ll = [min(v(:,4)) max(v(:,4))];
        B = [-Inf ll(1):(diff(ll))/6:ll(2) Inf]; % horizontal
        if (nargin>1 & ~isempty(varargin))
            B = varargin{1};
        end
    end
    L = length(p);
    [N,edg] = histcounts(v(:,4),B);
    %r(i,:) = N./L*100; % percentage of all vectors
    r(i,:) = N; % counts
end

%warning('on')
% figure
% bar(r');
% set(gca,'XTickLabel',B(1:end-1))
% legend(num2str(grd'),'location','northeast')
% grid on
% xlabel('mm')
% ylabel('% of (t/d)dd vectors of that size')

% figure
% bar(r);
% set(gca,'XTickLabel',grd)
% legend(num2str(B(1:end-1)'),'location','northeast')
% grid on
% xlabel('grid size (seconds)')
% ylabel('% of (t/d)dd vectors of that size')

figure
bar(r);
set(gca,'XTickLabel',grd)
for i = 1:length(B)-1
    lbl{i} = sprintf('%.3f',B(i));
end
legend(lbl,'location','northeast')
grid on
xlabel('grid size (seconds)')
ylabel('# of (t/d)dd vectors of that size')
title(strrep(fstr,'_','\_'))

