% 2021-02-09
% Takes in list of file paths pointing to (denoised) summit data structs,
% goes through and finds all cadaver ROIs, returns list of these along with
% corresponding data file and survival data files

function [cadArray, localTime] = returnCadROIs(convFiles)

    % Initialize cell array for cadaver info:
        % 1 - ROI number
        % 2 - data file
        % 3 - survivor data file
    cadArray = cell(3,length(convFiles)*96); % this is the maximum number of cadavers you could expect from a typical board
    cadCt = 0;
    localTime = cell(2,length(convFiles));
    
    for i=1:length(convFiles)
        % Load in .mat file with expmt struct
        load(convFiles{i});
        
        spFile = split(convFiles{i},'\');
        expFile = spFile{length(spFile)};
        spFile{length(spFile)} = '';
        
        expDir = join(spFile(1:length(spFile)),'\');
        expDir = expDir{1};

        % Pull experiment start date and time from file name using CNE functions
        expDate = returnExpDate(string(expFile));
        startHour = returnExpStartTime(string(expFile)); 
    
        % Automatically determine filename for survival Excel sheet
        survivalFile = strcat(expDir,expDate,"-survival_data.xlsx");
        
        localTime{1,i} = convertToLocalTime(expmt, startHour);
        localTime{2,i} = survivalFile;
        
        % Load Excel sheet
        survival = readtable(survivalFile);

        roi_max = expmt.nTracks;

        for roi = (1:roi_max) 
            if strcmp(classifyROI(survival,roi),'Cadaver')
                cadCt = cadCt + 1;
                cadArray{1,cadCt} = roi;
                cadArray{2,cadCt} = convFiles{i};
                cadArray{3,cadCt} = survivalFile;
            end
        end
    end
    
    % Remove empty cells from array
    cadArray = cadArray(:,1:cadCt);
    
end