function gridstats(fstr, trans, varargin)

% set grid and percentage sizes to be analyzed
grd = [60 120 180 300 450 600 900 1800]; % grid sizes
per = [30 25 20 15 10 5]/100;  % percentage cutoff
perL = {'30%','25%','20%','15%','10%','5%'}; % label for percentages

% this function generates a lot of plots, so close all open plots
close all;

% set plot scale for ddd vector plots
scl = 0;
if (nargin>2 & ~isempty(varargin))
    scl = varargin{1};
end

% 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,scl);
% OR
%[pid,pt] = plotVectors(fname,1);
ax(1) = gca;

% header for output table:
fprintf('%5s%10s%10s%10s%10s%10s%10s%10s\n','min','grid',perL{:});

% 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);
    
    %figure; histogram(v(:,4)); title(fname);
    
    N = length(v(:,4));
    for j = 1:length(per)
        %q = find(v(:,4)>per(j)*trans); % points > per(i)% 
                                    % of transformation size
        q = find(abs(v(:,4))>per(j)*abs(trans)); % 'abs' to account
                            % for vertical vector fields
        r(j,i) = (length(q)/N)*100;
    end
    fprintf('%5.1f%10d%10.1f%10.1f%10.1f%10.1f%10.1f%10.1f\n',...
        grd(i)/60, grd(i),r(:,i));
    
    % plot vector field
    [pid,pt] = plotVectors(fname,scl);
    orient landscape
    print('-dpdf',sprintf('ddd_%d.pdf',grd(i)));
    ax(i+1) = gca;
end

linkaxes(ax,'xy');

%warning('on')
figure
bar(r);
set(gca,'XTickLabel',perL)
legend(num2str(grd'./60),'location','northwest')
grid on
xlabel('% of median transformation size')
ylabel('% of dd vectors exceeding that level')
