% pppulsetime_14_09_07.m

    clear all ; close all ;

    bitdiv = 4 ;

    [ppdir,bsfs] = getppdir ;
    datdir = ('14_09_07') ;
    subdir = ('variation within the pulse') ;

    fuldir = fullfile(ppdir, datdir, subdir) ;

    datfiles = ['9kV_25us_exp_000us_delay.tif'; ...
        '9kV_25us_exp_025us_delay.tif'; ...
        '9kV_25us_exp_050us_delay.tif'; ...
        '9kV_25us_exp_075us_delay.tif'; ...
        '9kV_25us_exp_100us_delay.tif'; ...
        '9kV_25us_exp_125us_delay.tif'; ...
        '9kV_25us_exp_150us_delay.tif'; ...
        '9kV_25us_exp_175us_delay.tif'; ...
        '9kV_25us_exp_200us_delay.tif'; ...
        '9kV_25us_exp_225us_delay.tif'; ...
        '9kV_25us_exp_250us_delay.tif'; ...
        '9kV_25us_exp_275us_delay.tif'; ...
        '9kV_25us_exp_300us_delay.tif'; ...
        '9kV_25us_exp_325us_delay.tif'; ...
        '9kV_25us_exp_350us_delay.tif'; ...
        '9kV_25us_exp_375us_delay.tif'] ;

%    pplim = 250 ;
    pplim = 0 ;
%    numfiles = length(datfiles) ;
    numfiles = 16 ;
    makemov = 1 ;
    loopmat = [[1:16] [15:-1:1]] ;
    numfiles = 31 ;

    if makemov == 1
        mov = avifile('C:\Documents and Settings\jolly\Desktop\pppulsetime_25us_looped_14_09_07.avi','fps',4,'quality',100) ;
    end

    for i = 1:numfiles

        fulldatfile = fullfile(fuldir,datfiles(loopmat(i),:)) ;

        [ppim,stdm,pphist,ppminmax] = pepperplotfun(fulldatfile,0,[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,[100 250],'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)) ;
            close(1) ;
        end

    end

    if makemov == 1
        mov = close(mov) ;
    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)']) ;




