% ppcedecay_14_09_07.m

    clear all ; close all ;

    bitdiv = 4 ;

    [ppdir,bsfs] = getppdir ;
    datdir = ('14_09_07') ;
    subdir = ('scintilator light decay study') ;

    fuldir = fullfile(ppdir, datdir, subdir) ;

    datfile = ['20seconds_1msExp_EveryPulse_F4.tif'] ;
%    datfile = ['10seconds_30usExp_EveryPulse_F2_8.tif'] ;
%    datfile = ['10seconds_100usExp_EveryPulse_F2_8.tif'] ;
    fulldatfile = fullfile(fuldir,datfile) ;
    numims = length(imfinfo(fulldatfile)) ;
%    numims = 10 ;
    datinf = imfinfo(fulldatfile) ;

%    pplim = 250 ;
    pplim = 0 ;
    makemov = 1 ;

    if makemov == 1
%        mov = avifile('C:\Documents and Settings\jolly\Desktop\ppcedecay_14_09_07_fixed.avi','fps',10,'quality',100,'compression','none') ;
        mov2 = avifile('C:\Documents and Settings\jolly\Desktop\ppcedecay_14_09_07_fast_fixed_uc.avi','fps',25,'quality',100,'compression','none') ;
%        mov3 = avifile('C:\Documents and Settings\jolly\Desktop\ppcedecay_14_09_07_scaled.avi','fps',10,'quality',100) ;
%        mov4 = avifile('C:\Documents and Settings\jolly\Desktop\ppcedecay_14_09_07_fast_scaled.avi','fps',25,'quality',100) ;
    end

    for i = 1:numims

%        datinf(i).FileModDate
        [ppim,stdm,pphist,ppminmax] = pepperplotfun(fulldatfile,i,[0 0]) ;
%        ppcutmat = ( ppim > pplim ) ;
%        ppim = ( ppim - pplim ).*ppcutmat ;
        sumint(i) = sum( sum( ppim ) ) ;
        [y,ind] = max(ppim) ;
        [maxes(i),iind] = max(y) ;
        maxpos(i,:) = [iind ind(iind)] ;
        low(i) = min( min( ppim ) ) ;
        pplow = ppminmax(1) ;
        pphigh = ppminmax(2) ;

        if makemov == 1
            figure(1), imshow(ppim,[0 3500],'Border','tight','XData',[1 1024],'YData',[1 1024]) ;
            colormap(jet) ;
            set(1,'Position',[300 300 512 512]) ;
            frame(i) = getframe(gca) ;
 %           mov = addframe(mov,frame(i)) ;
            mov2 = addframe(mov2,frame(i)) ;
            close(1) ;
 %           figure(1), imshow(ppim,[pplow pphigh],'Border','tight','XData',[1 1024],'YData',[1 1024]) ;
 %           colormap(jet) ;
 %           set(1,'Position',[300 300 512 512]) ;
 %           frame(i) = getframe(gca) ;
 %           mov3 = addframe(mov3,frame(i)) ;
 %           mov4 = addframe(mov4,frame(i)) ;
 %           close(1) ;
        end

    end

    if makemov == 1
 %       mov = close(mov) ;
        mov2 = close(mov2) ;
 %       mov3 = close(mov3) ;
 %       mov4 = close(mov4) ;
    end

    figure, plot(maxes,'x-k') ;
    xlabel(['File number']), ylabel(['Pixel Intensity']), ...
        title(['\bf Light intensity of the brightest pixel']) ;

    figure, plot(low,'x-k') ;
    xlabel(['File number']), ylabel(['Pixel Intensity']), ...
        title(['\bf Light intensity of the darkest pixel']) ;

    figure, plot(sumint,'x-k') ;
    xlabel(['File number']), ylabel(['Image Intensity']), ...
        title(['\bf Integrated light intensity for the total image (after cut)']) ;



