function [T,LIR]=alm008_deconv()

kB=0.69503476;
ImeFonta='Arial';
LegendFontSize=26;
FontSize=40;
Pozicija=[0 0 1000 800];

D=dlmread('/Users/zoranristic/OneDrive/alm008/alm008.csv',',');
lam=D(2:end,1);
T=D(1,2:end-1);
DATA=D(2:end,2:end-1);
clear D;
N=length(T);

try
    close 'Emission spectra vs T'
end
figure('Name','Emission spectra vs T','Position',Pozicija);
for i=1:N
    I=DATA(:,i);
    SPD=(lam<650)|((lam>830)&(lam<880))|(lam>930);
    A_range=[0 1 200];
    L0est=696.3+0.04822*T(i);
    L0_range=[L0est-1 L0est L0est+1];
    sgm_range=[0 500 5000];
    [LIRt,I1,I2,fit_param]=two_peak_deconvolution_LIR(lam,I,SPD,A_range,L0_range,sgm_range);

    A(i)=fit_param(1);
    L0(i)=fit_param(2);
    SGM(i)=fit_param(3);
    
    SPD2=(lam<700)|((lam>790)&(lam<820));
    A_range2=[0 1 200];
    L0_range2=[L0(i)-20 L0(i) L0(i)+20];
    sgm_range2=[0  SGM(i)/5  SGM(i)];
   [LIRt,I21,I22,fit_param2]=two_peak_deconvolution_LIR(lam,I2,SPD2,A_range2,L0_range2,sgm_range2);

   uslov=(lam>650)&(lam<820);
   LIR(i)=(sum(I)-sum(I22(uslov)))/sum(I22(uslov));
   Iup(i)=(sum(I)-sum(I22(uslov)));
   Idown(i)=sum(I22(uslov));

    if i==4 
    %plot(lam,DATA(:,i));
    plot(lam,I,'LineWidth',3,'LineStyle','-','Color',[0 0 0]);
    hold on;
    plot(lam,(I-I22),'LineWidth',3,'Color',[1 0 0]);
    plot(lam,(I1),'LineWidth',2,'Color',[1 0 0],'LineStyle','--');
    plot(lam,(I21),'LineWidth',2,'Color',[1 0 0],'LineStyle','--');
    plot(lam,I22,'LineWidth',3,'Color',[0 1 0]);
    hold off;
    xlabel('\lambda [nm]');
    ylabel('Intensity [arb. units]');
    xlim(gca,[580 920]);
    ylim(gca,[0 1800]);
    box(gca,'on');
    set(gca,'FontName',ImeFonta,'FontSize',FontSize,'LineWidth',2,'YMinorTick','on');
    hold off
    end
    %pause();
end


try
    close 'I vs T'
end
figure('Name','I vs T','Position',Pozicija);
plot(T,Iup,'Marker','^','MarkerSize',15,'LineWidth',3,'LineStyle','--','Color',[1 0 0]);
hold on;
plot(T,Idown,'Marker','v','MarkerSize',15,'LineWidth',3,'LineStyle','--','Color',[0 1 0]);
plot(T,(Idown+Iup),'Marker','diamond','MarkerSize',15,'LineWidth',3,'LineStyle','--','Color',[0 0 0]);

box(gca,'on');
xlim([T(1) T(N)]);
ylabel('Intensity [arb. units]');
xlabel('Temperature [K]');
set(gca,'FontName',ImeFonta,'FontSize',FontSize,'LineWidth',2,'YMinorTick','on');
hold off

iT=1000./T;
lnLIR=log(LIR);
[p,ERR]=polyfit(iT,lnLIR,1)
ERR
1 - (ERR.normr/norm(lnLIR - mean(lnLIR)))^2

iTfit=1.5:0.1:3.5;
Tf=1000./iTfit;
lnLIRfit=p(1)*iTfit+p(2);
Sa=abs(exp(lnLIRfit)*1000*p(1)./(Tf.^2)); Sr=100*abs(1000*p(1)./(Tf.^2));

DE=1000*kB*p(1)

try
    close 'LIR vs T'
end
figure('Name','LIR vs T','Position',Pozicija);
plot(iT,lnLIR,'Marker','diamond','MarkerSize',20,'LineWidth',3,'LineStyle','none',...
    'DisplayName','ln(LIR) - experimental data','Color',[0 0 0]);
hold on;
plot(iTfit,lnLIRfit,'LineWidth',3,'Color',[1 0 0],'LineStyle','--','DisplayName','ln(LIR)- linear fit');
%xlim([300 625]);
ylabel('ln(LIR)');
xlabel('1000/T [K^{-1}]');
box(gca,'on');
legend('show');
set(gca,'FontName',ImeFonta,'FontSize',FontSize,'LineWidth',2,'YMinorTick','on');
hold off



figurename5='Sa and Sr vs T'
try
    close(figurename5);
end

fg=figure('Name',figurename5,'Position',Pozicija);
yyaxis left
plot(Tf,Sr,'LineWidth',3,'Color',[0 0 0],'LineStyle','-');
ylabel('S_{r} [%K^{-1}]');
set(gca,'YColor',[0 0 0]);
yyaxis right
plot(Tf,Sa,'LineWidth',3,'Color',[0 0 0],'LineStyle',':');
ylabel('S_{a} [K^{-1}]');
set(gca,'YColor',[0.5 0.5 0.5]);
xlabel('Temperature [K]');

xlim([T(1) T(end)]);
box(gca,'on');
grid(gca,'on');
set(gca,'FontName',ImeFonta,'FontSize',FontSize);