function roi_sizes( roi_regs, roitypes, subjects, suffix, root, froot, roidir, forcerun, plotit)


%% preparation

% prepare some handy variables, matrices and file name
nsubs   =   length( subjects);
nrois   =   length( roi_regs);
nvox    =   NaN( nsubs, nrois);
fpath   =   fullfile( froot, 'roi_vox.mat'); 

% create cell array with ROI names (and create 'all' roi if not existant)
rois        =   cell(  1,     nrois);
checkrois   =   zeros( nsubs, nrois);
for nroi = 1:nrois
    rois{nroi} = sprintf( '%s_%s_all%s.nii', roi_regs{nroi}, roitypes{nroi}, suffix);
    for s = 1:nsubs
        subj        =   sprintf( '%02g', subjects(s));
        sub_roi     =   fullfile( root, subj, roidir, rois{nroi});
        if ~exist( sub_roi, 'file')
            checkrois(s, nroi) = 1;
        end
    end
end

% create all 'all' rois, when missing any (just in case)
if any( checkrois(:))
    ROI_pipeline_subfunc( subjects, [], [], [], roidir(end), 1)
end


%% retrieve voxel counts 

% load data or retrieve voxel counts from ROIs
if exist( fpath, 'file') && ~forcerun
    
    % remember which ROIs were requested
    old_roi_regs = roi_regs;
    
    % load ROI info
    load( fpath); %#ok<LOAD>
    
    % keep only requested ROI names and data
    nvox        =   nvox(:,contains( roi_regs, old_roi_regs));
    roi_regs    =   roi_regs( contains( roi_regs, old_roi_regs));
    
else
    
    % get data from 'all' ROIs
    addpath( '/home/common/matlab/spm12');
    
    % iterate over participants
    for s = 1 : nsubs
        
        % set current subject directory, report progress
        subj        =   sprintf( '%02g', subjects(s));
        sub_root    =   fullfile( root, subj, roidir);
        
        if plotit
            fprintf( '\nParticipant %g/%g [%s], started at %s.\n', s, nsubs, subj, datestr( now, 'hh:MM:ss'));
        end
        
        % iterate over rois
        for r = 1 : nrois
            
            % report progress
            if plotit
                fprintf( '\t- ROI %g/%g [%s].\n', r, nrois, roi_regs{r});
            end
            
            % open roi
            hdr        =   spm_vol( fullfile( sub_root, rois{r}));
            vol        =   spm_read_vols( hdr);
            nvox(s,r)  =   sum( vol(:));
            clearvars   vol hdr
            
        end
    end
    
    % save data
    save( fpath, 'nvox', 'roi_regs', 'subjects', 'suffix')
    
end


%% plot results

if plotit
    
    % prepare figure
    close all; 
    figure('Name','Voxel count per ROI','NumberTitle','off'); 
    hold on
    
    % get max and min data
    nvox    =   nvox(subjects, :);
    maxdata =   max( nvox);
    mindata =   min( nvox);
    
    % plot settings
    xjit = 0.2;
    plot( [0 nrois+1], [0 0], 'k.:');
    
    % plot individual subject data per roi
    for r = 1 : nroi
        
        % set x values
        xvals = rand( 1, nsubs)*xjit*2 - xjit;
        
        % plot subjects and max
        plot( xvals+r, nvox(:,r)', 'o', 'MarkerFaceColor', [0.8 0.8 0.8], 'MarkerEdgeColor', [0.8 0.8 0.8])
        line( [-xjit xjit] + r, ones(1,2)*maxdata(r), 'Color', [1 0 0], 'LineWidth', 3)
        line( [-xjit xjit] + r, ones(1,2)*mindata(r), 'Color', [1 0 0], 'LineWidth', 3)
        text( r, maxdata(r), sprintf( '%g', maxdata(r)), 'HorizontalAlignment', 'center', 'VerticalAlignment', 'bottom');
        text( r, mindata(r), sprintf( '%g', mindata(r)), 'HorizontalAlignment', 'center', 'VerticalAlignment', 'top');
    end
    
    % plot means
    errorbar( 1:nrois, mean( nvox), std( nvox)/sqrt( nsubs), 'ko', 'MarkerFaceColor', 'k', 'MarkerSize', 10, 'CapSize', 15, 'LineWidth', 2);
    
    % pimp graph
    ymarg = max( maxdata).*0.05;
    ylim( [0-ymarg, max( maxdata)+ymarg]);
    xticks( 1:nrois)
    xticklabels( roi_regs)
    ylabel( 'N voxels');
    xlabel( 'ROI');
    title( 'Number of voxels per ROI');
    pbaspect([2 1 1]);
    hold off
    
end