% IRcurve by bootstrap

filename = 'C:\LevInfinite\Config\Molecules.ini';
fid = fopen(filename,'rt');
molfolder = fgetl(fid);
fclose(fid);

filename = 'C:\LevInfinite\Config\ToCalculate.ini';
fid = fopen(filename,'rt');
modelname = fgetl(fid);
fclose(fid);

modelfolder = strcat(molfolder,modelname);
modelfolder = strcat(modelfolder,'\');

% read model files
filename = strcat(modelfolder,'InfTable.txt');
fid = fopen(filename,'r');
InfTable = fscanf(fid,'%i',9);
fclose(fid);
nFreqs = InfTable(9);

filename = strcat(modelfolder,'FreqsInts.mat');
load(filename);
filename = strcat(modelfolder,'sigma.txt');
load(filename);

nB = size(freqsB,1);
Freqmin = round(min(min(freqsB)));
Freqmax = round(max(max(freqsB)));
% x = (Freqmin - 100):5:(Freqmax + 100);
x = 400:5:3200; % for butadiene-butane only
nx = length(x);
x = x';

hold on
Dy=zeros(nx,nFreqs);
yB = zeros(nB,nx); % bootstrap curves
for iB = 1:nB
    II = absintsB(iB,:)';
    for j=1:nFreqs
       Dy(:,j)=(II(j)/(2.5*sigma(j)))* ...
           exp(-(0.5/sigma(j)^2)*(x-freqsB(iB,j)).^2);
    end %j
    y=(sum(Dy'))';
    plot(x,y)
    yB(iB,:) = y';
end % iB

hold off 

% % for Butane 
% %niu = [980, 1380, 1470, 2850, 2905];
% % for Butadiene
% niu = [510, 905, 1395, 1600, 3095];
% Peaks = zeros(5, 5);
% for i = 1:5
%     k = find(x == niu(i));
%     hist(yB(:,k))
%     Peaks(i,1) = niu(i);
%     Peaks(i,2) = mean(yB(:,k));
%     Peaks(i,3) = std(yB(:,k));
%     Peaks(i,4) = min(yB(:,k));
%     Peaks(i,5) = max(yB(:,k));
% end %i 
