glu=[datenum(string(readcell('Clarity_Export_GRATA_PAMELA_2024-01-22_141716',...
    'Range','B3467:B3563'))),readmatrix('Clarity_Export_GRATA_PAMELA_2024-01-22_141716','Range','H3467:H3563')];
fs=[datenum([2024 01 21 10 22 00;...
    2024 01 21 10 53 00;...
    2024 01 21 11 19 00;...
    2024 01 21 11 41 00;...
    2024 01 21 12 03 00;...
    2024 01 21 12 24 00;...
    2024 01 21 12 46 00;...
    2024 01 21 13 09 00;...
    2024 01 21 13 30 00;...
    2024 01 21 13 51 00;...
    2024 01 21 14 14 00;...
    2024 01 21 14 34 00;...
    2024 01 21 14 57 00;...
    2024 01 21 15 17 00;...
    2024 01 21 15 42 00;...
    2024 01 21 16 01 00]),...
    [95;92;150;189;230;276;285;286;278;216;207;148;130;110;97;81]];

tnom=-30+5.12/2:.0025:-5.12/2;
p=dir('pam*');

for i=1:length(p)
    filets(i)=datenum(str2num(p(i).name(5:8)),...
        str2num(p(i).name(10:11)),...
        str2num(p(i).name(13:14)),...
        str2num(p(i).name(16:17)),...
        str2num(p(i).name(19:20)),...
        str2num(p(i).name(22:23)));
    spects(i,:)=filets(i)+tnom/24/3600;
end

t=spects';
glufit=t(:);
glufit(:,2)=splinapp([glu(:,1)-15/24/60;fs(:,1)],[glu(:,2);fs(:,2)],ones(size(glu,1)+size(fs,1),1)*8e6,glufit(:,1));
f3=splinapp(fs(:,1),fs(:,2),ones(size(fs,1),1)*5e6,fs(:,1));
glufit(:,3)=splinapp(fs(:,1),fs(:,2),ones(size(fs,1),1)*5e6,glufit(:,1));
p2p=max(glufit(:,2))-min(glufit(:,2));
glufit(:,4)=(glufit(:,2)-p2p)*1.1+p2p-11;
plot(glu(:,1)-15/24/60,glu(:,2),'o:',fs(:,1),fs(:,2),'o:',glufit(:,1),glufit(:,4),glufit(:,1),glufit(:,3));grid;legend('Dex','FS','DexFit','FSFit');shg
save glu glu fs filets spects glufit f3
