DATEYR = '2021-';
DAYNUM = '250' ;

%set the data file path name
%data_dir = strcat('K:\ify\sol\soon_to_be_deleted_(spring-2013)\Instruments\AndorSpectrometer-old\Data\');
%data_dir = strcat('K:\ify\sol\Instruments\AndorSpectrometer\');
%data_dir = strcat('S:\ify\sol\instruments\AndorSpectrometer\');
%data_dir = strcat('C:\Users\espy\Documents\MATLAB\AndorSpectrometer\');
data_dir = strcat('M:\Andor_data_from_Autumn_2020\');


load(strcat(data_dir,DATEYR,DAYNUM,'.mat'))

[nrofmeas filelength]=size(daymat);
SCN=625:1:(625+1023);
wl =  -(0.86627.*10.^(-6).*SCN.^2) + (0.2071.*SCN)+1333.6;
for i=2:nrofmeas
    n=i;
    DATE=['Date: ' int2str(daymat(n,1)) '-' int2str(daymat(n,2)) '-' int2str(daymat(n,3)) ' UTC Time: ' int2str(daymat(n,4)) ':' int2str(daymat(n,5))]
    qqqtst = i-(fix(i/10)*10);
    if ((qqqtst ~=1) && (qqqtst ~=6))
        qqqbkg = fix(i/10)*10. + 1;
%        dat=(daymat(i,12:end) - (daymat(qqqbkg,12:end)+daymat(qqqbkg+5,12:end))/2.0 );
        if( (i-qqqtst <= 2))
            ibkg=qqqbkg
        else
            ibkg=qqqbkg+5
        end
        %subtract off nearest background
        dat=(daymat(i,12:end) - (daymat(ibkg,12:end) ));
        %turn into counts per second (niumber of intervals * sec/interval)
        dat = dat/(daymat(i,7)*daymat(i,8));
        %median filter data
        dat=medfilt1(dat,3);
        plot(wl,dat)
            xlabel('Wavelength [nm]')
            ylabel('Intensity [Counts per second]')
            title(strcat(DATE,' Scan number: ',int2str(n)))
 %           axis([1460 1680 -100 2500])
    end
    pause
end
