function run_all_calcZ(root_github_dir)
%%%%%%%% USER SET - ROOT DIRS
if nargin == 0,
    root_github_dir = '/Users/dlogan/github/CP_projects/ilastik_CP_AssayDev';
end
root_dir_save = fullfile(root_github_dir,'Analysis','Saved_figs','Seeding');
%%%%%%%%

% Turn off warning about variable names being modified if you use readtable() to read in column headers that have spaces in them.
% "Warning: Variable names were modified to make them valid MATLAB identifiers."
warning('off', 'MATLAB:codetools:ModifiedVarnames');

% Close all open figures
close('all','hidden')

%% MAIN LOOPS
% agg_method = {'per_image','per_well'}; %% We are not using 'per_image' aggregation 
agg_method = {'per_well'};
expt_type = {'CP_CPA','ilastik_CP'};
for i = 1:length(agg_method)
    for j = 1:length(expt_type)
        CalcZ(root_github_dir,agg_method{i},expt_type{j});
        save_all_figures_to_directory(fullfile(root_dir_save),'png',agg_method{i},expt_type{j})
        save_all_figures_to_directory(fullfile(root_dir_save),'fig',agg_method{i},expt_type{j})
    end
end
end

function save_all_figures_to_directory(dir_name, figtype,agg_method,expt_type)
figlist=findobj('type','figure');  %% FIND ALL OPEN FIGURES
for i=1:numel(figlist)
    if isprop(figlist(i),'Number'), fignum = figlist(i).Number; else fignum = figlist(i); end % 'Number' property added with R2014b
    save_to_file = fullfile(dir_name,[agg_method '_' expt_type '_figure' num2str(fignum) '.' figtype]);
    saveas(figlist(i),save_to_file);
    disp(['Saving to ' save_to_file])
end
end