%process the calibration sittings into pds and produce dark corrected
%bandpass filtered spectra

dfiles=dir('Dark*');
sfiles=dir('pam*');

pp=gcp('nocreate');
if isempty(pp)
    parpool
end

tic

for i=1:length(dfiles)
    s=load(sfiles(i).name);
    d=load(dfiles(i).name);
    if s(5,9)>2
        s=s(:,9:264);
    else
        s=s(:,10:265);
    end

    if d(5,9)<1.258
        d=d(:,9:264);
    else
        d=d(:,10:265);
    end

    sd=s-ones(size(s,1),1)*mean(d(3:end,:));
    clear s d
    [pds,~,sdf]=signaltopds(sd,400,10.24,6,0.5,7.5);
    save(['sit',num2str(i,'%03.0f')],'pds','sdf','sd','sfiles','dfiles')
    clear pds sdf sd
    toc
end
cd ..
cd 20231203_02
dfiles=dir('Dark*');
sfiles=dir('pam*');
for i=1:length(dfiles)
    s=load(sfiles(i).name);
    d=load(dfiles(i).name);
    if s(5,9)>2
        s=s(:,9:264);
    else
        s=s(:,10:265);
    end

    if d(5,9)<1.258
        d=d(:,9:264);
    else
        d=d(:,10:265);
    end

    sd=s-ones(size(s,1),1)*mean(d(3:end,:));
    clear s d
    [pds,~,sdf]=signaltopds(sd,400,10.24,6,0.5,7.5);
    save(['sit',num2str(i,'%03.0f')],'pds','sdf','sd','sfiles','dfiles')
    clear pds sdf sd
    toc
end
