
%% detect folders
clear
Folders=dir(cd);
isub = [Folders(:).isdir]; %# returns logical vector
Folders(~isub)=[];
remove=[];
for i=1:length(Folders)
if Folders(i).name=="." | Folders(i).name==".."
remove=[remove i];
end
end
Folders(remove)=[];
clear isub remove i
%%

currentPath=cd;
for folderi=1: length(Folders)
folderi
cd (Folders(folderi).name)
if any(size(dir([ 'goodstims.mat' ]),1))
    Files=dir(['VariablesAt*.mat']);
    load([Files(end).name]);
    allVars(folderi).mean_T_rise=mean_T_rise;
    allVars(folderi).mean_T_rise_1=mean_T_rise_1;
    allVars(folderi).mean_T_rise_2=mean_T_rise_2;
    if contains(Folders(folderi).name,"min")
        allVars(folderi).power=Folders(folderi).name(7:13);
    else allVars(folderi).power=Folders(folderi).name(7:10);
    end
end
clearvars -except folderi allVars Folders currentPath
cd(currentPath)
end
 
save(['allVars.mat'],'allVars','-v7.3')
clear


%% plot
power_dbm=["min9dbm", "min7dbm","min5dbm","min3dbm","min1dbm","1dbm","3dbm","5dbm"];
power_W=[5.57 9.29 15.07 24.25 37.52 52.81 62.71 67.72];

for ii=1:length(allVars)
   if ~isempty(allVars(ii))
      allVars(ii).power_W=power_W(find(power_dbm==string(allVars(ii).power)));   
      allVars(ii).T_rise_1sec=allVars(ii).mean_T_rise/50;
   end
end

[x,idx]=sort([allVars.power_W]);
allVars=allVars(idx);

fig=figure();hold on;
plot([allVars.power_W],[allVars.T_rise_1sec],'-x','linewidth',2)
xlabel('Radiate Power (W)')
ylabel('1sec \Delta T (C)')
set(gca,'fontweight','bold','fontsize',12,'linewidth',1)
set(fig,'Renderer', 'painters')

saveas(gca,fullfile(cd,['1sTriseVSpower.svg']))
saveas(gca,fullfile(cd,['1sTriseVSpower.pdf']))

save(['allVars.mat'],'allVars','-v7.3')


%% save all variables
save(['VariablesAt' datestr(now,'mmddyyHHMMSS') '.mat'],'-v7.3')
