%% Function for extracting relevant information from formatted movie titles

function [firstFrame coh] = roachAnalyzeMovie(fileName)
%outputs first frame and cohort
load roachCohorts.mat
% load roachMask.mat

cohortList=unique(cohorts(:,2));
cohortHitList=zeros(size(cohortList));

for i=1:size(cohortList,1) % determine which cohort
    cohortHitList(i)= ~isempty(strfind(fileName,cohortList{i}));
end

if sum(cohortHitList)==0
    error('Cohort name could not be extracted from filename');
elseif sum(cohortHitList) >1
    error('Filename appears to contain more than one cohort');
else
    coh= cohortList{cohortHitList==1};
    disp(['Cohort extracted as: ' coh '...']);
end

ffStart=strfind(fileName,'ff'); %determine first frame for analysis;
firstFrame=fileName(ffStart+2:ffStart+5);
firstFrame=str2num(firstFrame);

if isempty(firstFrame)
   error('First frame could not be extracted from filename');
else
   disp(['First frame extracted as: ' num2str(firstFrame) '...']); 
end

