close all
clear all

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


BaseFolder = 'MonoChromaticRun';
ResultsFolder = 'latest_batch_results';
%ResultsFolder = 'batch_results_20230515210441';

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)
  mkdir(['../' BaseFolder '/' ResultsFolder '/' results_table.pblogFilename{i} '/../matlab']);
  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
