close all
clear all

addpath(genpath('../../MatlabProcessing')); % Add directory and sub-directories to path.


BaseFolder = 'MonoChromaticComparisons';
ResultsFolder = 'latest_batch_results';

result_folders = dir(['../' BaseFolder '/batch_results*']);

for k = 1:length(result_folders)
 ResultsFolder = result_folders(k).name
 results_table = readtable(['../' BaseFolder '/' ResultsFolder '/batch_runs.log']);
 table_size = size(results_table);

 for i = 1:table_size(1)
     matlab_folder = ['../' BaseFolder '/' ResultsFolder '/' results_table.pblogFilename{i} '/../matlab'];
  if (~exist(matlab_folder,'dir'))  % Only compute if matlab folder doesn't already exist
    mkdir(matlab_folder);
    copyfile(['../' BaseFolder '/' ResultsFolder '/' results_table.pblogFilename{i} '/*.csv'], ...
          ['../' BaseFolder '/' ResultsFolder '/' results_table.pblogFilename{i} '/../matlab/.']);
    files = dir(['../' BaseFolder '/' ResultsFolder '/' results_table.pblogFilename{i} '/../matlab/*.csv'])
    for j = 1:length(files);
        files(j).folder
        files(j).name(1:end-4)
      ConvertDataToMatlab([files(j).folder '\'],files(j).name(1:end-4));
      MakeQuickViewPlots([files(j).folder '\'],files(j).name(1:end-4));
    end

    delete(['../' BaseFolder '/' ResultsFolder '/' results_table.pblogFilename{i} '/../matlab/*.csv']);
  end

 end
end
