% ppalldata_13_08_07_christoph

    clear all ; close all ;

    cent = [1024 1024] ;
    width = 45 ;
    zlen = 10 ;
    rotang = 0 ;
    energy = 35e3 ;
%    plt = [2 2 1 1 1 2 1 0 1 2] ;
%    plt = [0 0 0 0 0 0 0 0 0 0 2] ;
%    plt = [0 0 0 0 0 0 0 0 0 0 0] ;
%    plt = [0 0 0 0 0 0 1 0 1 2 0] ;
    plt = [0 0 0 0 0 0 0 0 1 0 0] ;
    calplt = 0 ;
    bitdiv = 4 ;

%    pplim = 114 ;
    pplim = 250 ;

    histpart = 1e4 ;
    angres = 6.3565 ;

    [ppdir,bsfs] = getppdir ;
    datdir = ('13_08_07_to-analyse') ;

    subdir{1} = (['Vary Post acceleration keep extract at 10 kV' bsfs ...
        'without new post acceleration electrode']) ;
    prpdir{1} = ('pepperpot') ;
    datfile{1} = ('10-0kV_8-50mm.tif') ;
    calfile{1} = ('cal_008-50_2s.tif') ;
    bgfile{1} = ('bg_008-50_2s.tif') ;
    enemat(1) = 35e3 ;

    cfile = [ppdir bsfs datdir bsfs char(subdir{1}) bsfs char(prpdir{1}) bsfs char(calfile{1})] ;
    bfile = [ppdir bsfs datdir bsfs char(subdir{1}) bsfs char(prpdir{1}) bsfs char(bgfile{1})] ;
    dfile = [ppdir bsfs datdir bsfs char(subdir{1}) bsfs char(prpdir{1}) bsfs char(datfile{1})] ;

%    ppimc = pepperplotfun(cfile,0,[2 2]) ;
%    figure, imagesc(ppimc,[120 5000]), axis image, colormap(gray) ;
%    [midpos,sp2sp,imtilt] = ppcalfindmm(cfile,[23 27],[2003 26],[26 2008],[2003 2008],126,calplt) ;
    [midpos,sp2sp,imtilt] = ppcalfindmm([],[23 27],[2003 26],[26 2008],[2003 2008],126,calplt) ;

%    [ppimbg,stdmbg,pphistbg,ppminmaxbg] = pepperplotfun(bfile,0,[2 2]) ;

    [ppposdat,ppemitdat,ppim,pppixemit5d,pppixemit2d] = ...
        ppanalyse41(dfile,[],midpos,imtilt,sp2sp,pplim,width,zlen,rotang,enemat(1),plt,bitdiv) ;

    intsum = sum(pppixemit2d(:,5)) ;
    intdiv = intsum./histpart ;
    intens = (pppixemit2d(:,5)./intdiv) ;
    [ppemithist] = ppemithistgen(pppixemit2d(:,1),pppixemit2d(:,2),pppixemit2d(:,3), ...
        pppixemit2d(:,4),intens,3,3,angres,angres) ;
    lintrawrite(ppemithist(:,1),ppemithist(:,3),ppemithist(:,2),ppemithist(:,4),0,0,'pp_10kV-ex_35kV-plat_oldelec.txt') ;

    subdir{2} = (['Vary Post acceleration keep extract at 10 kV' bsfs ...
        'with new post acceleration electrode']) ;
    prpdir{2} = ('pepperpot data') ;
    datfile{2} = ('21kV_PlatformVoltage.tif') ;
    calfile{2} = ('calib.tif') ;
    bgfile{2} = ('backgrnd.tif') ;
    enemat(2) = 21e3 ;

    cfile = [ppdir bsfs datdir bsfs char(subdir{2}) bsfs char(prpdir{2}) bsfs char(calfile{2})] ;
    bfile = [ppdir bsfs datdir bsfs char(subdir{2}) bsfs char(prpdir{2}) bsfs char(bgfile{2})] ;
    dfile = [ppdir bsfs datdir bsfs char(subdir{2}) bsfs char(prpdir{2}) bsfs char(datfile{2})] ;
%    ppimc = pepperplotfun(cfile,0,[2 2]) ;
%    figure, imagesc(ppimc,[120 3000]), axis image, colormap(gray) ;
%    [midpos,sp2sp,imtilt] = ppcalfindmm(cfile,[31 20],[2012 21],[32 2003],[2010 2003],126,calplt) ;
    [midpos,sp2sp,imtilt] = ppcalfindmm([],[31 20],[2012 21],[32 2003],[2010 2003],126,calplt) ;

%    [ppimbg,stdmbg,pphistbg,ppminmaxbg] = pepperplotfun(bfile,0,[2 2]) ;

    [ppposdat,ppemitdat,ppim,pppixemit5d,pppixemit2d] = ...
        ppanalyse41(dfile,[],midpos,imtilt,sp2sp,pplim,width,zlen,rotang,enemat(2),plt,bitdiv) ;

    intsum = sum(pppixemit2d(:,5)) ;
    intdiv = intsum./histpart ;
    intens = (pppixemit2d(:,5)./intdiv) ;
    [ppemithist] = ppemithistgen(pppixemit2d(:,1),pppixemit2d(:,2),pppixemit2d(:,3), ...
        pppixemit2d(:,4),intens,3,3,angres,angres) ;
    lintrawrite(ppemithist(:,1),ppemithist(:,3),ppemithist(:,2),ppemithist(:,4),0,0,'pp_10kV-ex_21kV-plat_newelec.txt') ;

    subdir{3} = (['Vary Post acceleration keep extract at 10 kV' bsfs ...
        'with new post acceleration electrode']) ;
    prpdir{3} = ('pepperpot data') ;
    datfile{3} = ('27kV_PlatformVoltage.tif') ;
    calfile{3} = ('calib.tif') ;
    bgfile{3} = ('backgrnd.tif') ;
    enemat(3) = 27e3 ;

    cfile = [ppdir bsfs datdir bsfs char(subdir{3}) bsfs char(prpdir{3}) bsfs char(calfile{3})] ;
    bfile = [ppdir bsfs datdir bsfs char(subdir{3}) bsfs char(prpdir{3}) bsfs char(bgfile{3})] ;
    dfile = [ppdir bsfs datdir bsfs char(subdir{3}) bsfs char(prpdir{3}) bsfs char(datfile{3})] ;
%    ppimc = pepperplotfun(cfile,0,[2 2]) ;
%    figure, imagesc(ppimc,[120 3000]), axis image, colormap(gray) ;
%    [midpos,sp2sp,imtilt] = ppcalfindmm(cfile,[31 20],[2012 21],[32 2003],[2010 2003],126,calplt) ;
    [midpos,sp2sp,imtilt] = ppcalfindmm([],[31 20],[2012 21],[32 2003],[2010 2003],126,calplt) ;

%    [ppimbg,stdmbg,pphistbg,ppminmaxbg] = pepperplotfun(bfile,0,[2 2]) ;

    [ppposdat,ppemitdat,ppim,pppixemit5d,pppixemit2d] = ...
        ppanalyse41(dfile,[],midpos,imtilt,sp2sp,pplim,width,zlen,rotang,enemat(3),plt,bitdiv) ;

    intsum = sum(pppixemit2d(:,5)) ;
    intdiv = intsum./histpart ;
    intens = (pppixemit2d(:,5)./intdiv) ;
    [ppemithist] = ppemithistgen(pppixemit2d(:,1),pppixemit2d(:,2),pppixemit2d(:,3), ...
        pppixemit2d(:,4),intens,3,3,angres,angres) ;
    lintrawrite(ppemithist(:,1),ppemithist(:,3),ppemithist(:,2),ppemithist(:,4),0,0,'pp_10kV-ex_27kV-plat_newelec.txt') ;

    subdir{4} = (['Vary Post acceleration keep extract at 10 kV' bsfs ...
        'with new post acceleration electrode']) ;
    prpdir{4} = ('pepperpot data') ;
    datfile{4} = ('35kV_PlatformVoltage.tif') ;
    calfile{4} = ('calib.tif') ;
    bgfile{4} = ('backgrnd.tif') ;
    enemat(4) = 35e3 ;

    cfile = [ppdir bsfs datdir bsfs char(subdir{4}) bsfs char(prpdir{4}) bsfs char(calfile{4})] ;
    bfile = [ppdir bsfs datdir bsfs char(subdir{4}) bsfs char(prpdir{4}) bsfs char(bgfile{4})] ;
    dfile = [ppdir bsfs datdir bsfs char(subdir{4}) bsfs char(prpdir{4}) bsfs char(datfile{4})] ;
%    ppimc = pepperplotfun(cfile,0,[2 2]) ;
%    figure, imagesc(ppimc,[120 3000]), axis image, colormap(gray) ;
%    [midpos,sp2sp,imtilt] = ppcalfindmm(cfile,[31 20],[2012 21],[32 2003],[2010 2003],126,calplt) ;
    [midpos,sp2sp,imtilt] = ppcalfindmm([],[31 20],[2012 21],[32 2003],[2010 2003],126,calplt) ;

%    [ppimbg,stdmbg,pphistbg,ppminmaxbg] = pepperplotfun(bfile,0,[2 2]) ;

    [ppposdat,ppemitdat,ppim,pppixemit5d,pppixemit2d] = ...
        ppanalyse41(dfile,[],midpos,imtilt,sp2sp,pplim,width,zlen,rotang,enemat(4),plt,bitdiv) ;

    intsum = sum(pppixemit2d(:,5)) ;
    intdiv = intsum./histpart ;
    intens = (pppixemit2d(:,5)./intdiv) ;
    [ppemithist] = ppemithistgen(pppixemit2d(:,1),pppixemit2d(:,2),pppixemit2d(:,3), ...
        pppixemit2d(:,4),intens,3,3,angres,angres) ;
    lintrawrite(ppemithist(:,1),ppemithist(:,3),ppemithist(:,2),ppemithist(:,4),0,0,'pp_10kV-ex_35kV-plat_newelec.txt') ;

    subdir{5} = (['Vary Extract keep post acceleration constant 18kV' bsfs ...
        'with new post acceleration electrode']) ;
    prpdir{5} = ('pepperpot') ;
    datfile{5} = ('09kV_Ext_07_2A_Sec_27kV.tif') ;
    calfile{5} = ('calib.tif') ;
    bgfile{5} = ('backgrnd.tif') ;
    enemat(5) = 27e3 ;

    cfile = [ppdir bsfs datdir bsfs char(subdir{5}) bsfs char(prpdir{5}) bsfs char(calfile{5})] ;
    bfile = [ppdir bsfs datdir bsfs char(subdir{5}) bsfs char(prpdir{5}) bsfs char(bgfile{5})] ;
    dfile = [ppdir bsfs datdir bsfs char(subdir{5}) bsfs char(prpdir{5}) bsfs char(datfile{5})] ;
%    ppimc = pepperplotfun(cfile,0,[2 2]) ;
%    figure, imagesc(ppimc,[120 3000]), axis image, colormap(gray) ;
%    [midpos,sp2sp,imtilt] = ppcalfindmm(cfile,[31 20],[2012 21],[32 2003],[2010 2003],126,calplt) ;
    [midpos,sp2sp,imtilt] = ppcalfindmm([],[31 20],[2012 21],[32 2003],[2010 2003],126,calplt) ;

%    [ppimbg,stdmbg,pphistbg,ppminmaxbg] = pepperplotfun(bfile,0,[2 2]) ;

    [ppposdat,ppemitdat,ppim,pppixemit5d,pppixemit2d] = ...
        ppanalyse41(dfile,[],midpos,imtilt,sp2sp,pplim,width,zlen,rotang,enemat(5),plt,bitdiv) ;

    intsum = sum(pppixemit2d(:,5)) ;
    intdiv = intsum./histpart ;
    intens = (pppixemit2d(:,5)./intdiv) ;
    [ppemithist] = ppemithistgen(pppixemit2d(:,1),pppixemit2d(:,2),pppixemit2d(:,3), ...
        pppixemit2d(:,4),intens,3,3,angres,angres) ;
    lintrawrite(ppemithist(:,1),ppemithist(:,3),ppemithist(:,2),ppemithist(:,4),0,0,'pp_09kV-ex_27kV-plat_newelec.txt') ;

    subdir{6} = (['Vary Extract keep post acceleration constant 18kV' bsfs ...
        'with new post acceleration electrode']) ;
    prpdir{6} = ('pepperpot') ;
    datfile{6} = ('13kV_Ext_08_7A_Sec_31kV.tif') ;
    calfile{6} = ('calib.tif') ;
    bgfile{6} = ('backgrnd.tif') ;
    enemat(6) = 31e3 ;

    cfile = [ppdir bsfs datdir bsfs char(subdir{6}) bsfs char(prpdir{6}) bsfs char(calfile{6})] ;
    bfile = [ppdir bsfs datdir bsfs char(subdir{6}) bsfs char(prpdir{6}) bsfs char(bgfile{6})] ;
    dfile = [ppdir bsfs datdir bsfs char(subdir{6}) bsfs char(prpdir{6}) bsfs char(datfile{6})] ;
%    ppimc = pepperplotfun(cfile,0,[2 2]) ;
%    figure, imagesc(ppimc,[120 3000]), axis image, colormap(gray) ;
%    [midpos,sp2sp,imtilt] = ppcalfindmm(cfile,[31 20],[2012 21],[32 2003],[2010 2003],126,calplt) ;
    [midpos,sp2sp,imtilt] = ppcalfindmm([],[31 20],[2012 21],[32 2003],[2010 2003],126,calplt) ;

%    [ppimbg,stdmbg,pphistbg,ppminmaxbg] = pepperplotfun(bfile,0,[2 2]) ;

    [ppposdat,ppemitdat,ppim,pppixemit5d,pppixemit2d] = ...
        ppanalyse41(dfile,[],midpos,imtilt,sp2sp,pplim,width,zlen,rotang,enemat(6),plt,bitdiv) ;

    intsum = sum(pppixemit2d(:,5)) ;
    intdiv = intsum./histpart ;
    intens = (pppixemit2d(:,5)./intdiv) ;
    [ppemithist] = ppemithistgen(pppixemit2d(:,1),pppixemit2d(:,2),pppixemit2d(:,3), ...
        pppixemit2d(:,4),intens,3,3,angres,angres) ;
    lintrawrite(ppemithist(:,1),ppemithist(:,3),ppemithist(:,2),ppemithist(:,4),0,0,'pp_13kV-ex_31kV-plat_newelec.txt') ;

    subdir{7} = (['Vary Extract keep post acceleration constant 18kV' bsfs ...
        'with new post acceleration electrode']) ;
    prpdir{7} = ('pepperpot') ;
    datfile{7} = ('17kV_Ext_10_7A_Sec_35kV.tif') ;
    calfile{7} = ('calib.tif') ;
    bgfile{7} = ('backgrnd.tif') ;
    enemat(7) = 35e3 ;

    cfile = [ppdir bsfs datdir bsfs char(subdir{7}) bsfs char(prpdir{7}) bsfs char(calfile{7})] ;
    bfile = [ppdir bsfs datdir bsfs char(subdir{7}) bsfs char(prpdir{7}) bsfs char(bgfile{7})] ;
    dfile = [ppdir bsfs datdir bsfs char(subdir{7}) bsfs char(prpdir{7}) bsfs char(datfile{7})] ;
%    ppimc = pepperplotfun(cfile,0,[2 2]) ;
%    figure, imagesc(ppimc,[120 3000]), axis image, colormap(gray) ;
%    [midpos,sp2sp,imtilt] = ppcalfindmm(cfile,[31 20],[2012 21],[32 2003],[2010 2003],126,calplt) ;
    [midpos,sp2sp,imtilt] = ppcalfindmm([],[31 20],[2012 21],[32 2003],[2010 2003],126,calplt) ;

%    [ppimbg,stdmbg,pphistbg,ppminmaxbg] = pepperplotfun(bfile,0,[2 2]) ;

    [ppposdat,ppemitdat,ppim,pppixemit5d,pppixemit2d] = ...
        ppanalyse41(dfile,[],midpos,imtilt,sp2sp,pplim,width,zlen,rotang,enemat(7),plt,bitdiv) ;

    intsum = sum(pppixemit2d(:,5)) ;
    intdiv = intsum./histpart ;
    intens = (pppixemit2d(:,5)./intdiv) ;
    [ppemithist] = ppemithistgen(pppixemit2d(:,1),pppixemit2d(:,2),pppixemit2d(:,3), ...
        pppixemit2d(:,4),intens,3,3,angres,angres) ;
    lintrawrite(ppemithist(:,1),ppemithist(:,3),ppemithist(:,2),ppemithist(:,4),0,0,'pp_17kV-ex_35kV-plat_newelec.txt') ;

    subdir{8} = (['Vary Both Extract and Post acceleration i.e. keep platform at 35kV (all images close to source)' ...
        bsfs 'without new post acceleration electrode']) ;
    prpdir{8} = ('pepperpot') ;
    datfile{8} = ('13-0kV_8-50mm.tif') ;
    calfile{8} = ('cal_008-50_2s.tif') ;
    bgfile{8} = ('bg_008-50_2s.tif') ;
    enemat(8) = 35e3 ;

    cfile = [ppdir bsfs datdir bsfs char(subdir{8}) bsfs char(prpdir{8}) bsfs char(calfile{8})] ;
    bfile = [ppdir bsfs datdir bsfs char(subdir{8}) bsfs char(prpdir{8}) bsfs char(bgfile{8})] ;
    dfile = [ppdir bsfs datdir bsfs char(subdir{8}) bsfs char(prpdir{8}) bsfs char(datfile{8})] ;
%    ppimc = pepperplotfun(cfile,0,[2 2]) ;
%    figure, imagesc(ppimc,[120 5000]), axis image, colormap(gray) ;
%    [midpos,sp2sp,imtilt] = ppcalfindmm(cfile,[23 27],[2003 26],[26 2008],[2003 2008],126,calplt) ;
    [midpos,sp2sp,imtilt] = ppcalfindmm([],[23 27],[2003 26],[26 2008],[2003 2008],126,calplt) ;

%    [ppimbg,stdmbg,pphistbg,ppminmaxbg] = pepperplotfun(bfile,0,[2 2]) ;

    [ppposdat,ppemitdat,ppim,pppixemit5d,pppixemit2d] = ...
        ppanalyse41(dfile,[],midpos,imtilt,sp2sp,pplim,width,zlen,rotang,enemat(8),plt,bitdiv) ;

    intsum = sum(pppixemit2d(:,5)) ;
    intdiv = intsum./histpart ;
    intens = (pppixemit2d(:,5)./intdiv) ;
    [ppemithist] = ppemithistgen(pppixemit2d(:,1),pppixemit2d(:,2),pppixemit2d(:,3), ...
        pppixemit2d(:,4),intens,3,3,angres,angres) ;
    lintrawrite(ppemithist(:,1),ppemithist(:,3),ppemithist(:,2),ppemithist(:,4),0,0,'pp_13kV-ex_35kV-plat_oldelec_pavar.txt') ;

    subdir{9} = (['Vary Both Extract and Post acceleration i.e. keep platform at 35kV (all images close to source)' ...
        bsfs 'without new post acceleration electrode']) ;
    prpdir{9} = ('pepperpot') ;
    datfile{9} = ('17-0kV_8-50mm.tif') ;
    calfile{9} = ('cal_008-50_2s.tif') ;
    bgfile{9} = ('bg_008-50_2s.tif') ;
    enemat(9) = 35e3 ;

    cfile = [ppdir bsfs datdir bsfs char(subdir{9}) bsfs char(prpdir{9}) bsfs char(calfile{9})] ;
    bfile = [ppdir bsfs datdir bsfs char(subdir{9}) bsfs char(prpdir{9}) bsfs char(bgfile{9})] ;
    dfile = [ppdir bsfs datdir bsfs char(subdir{9}) bsfs char(prpdir{9}) bsfs char(datfile{9})] ;
%    ppimc = pepperplotfun(cfile,0,[2 2]) ;
%    figure, imagesc(ppimc,[120 5000]), axis image, colormap(gray) ;
%    [midpos,sp2sp,imtilt] = ppcalfindmm(cfile,[23 27],[2003 26],[26 2008],[2003 2008],126,calplt) ;
    [midpos,sp2sp,imtilt] = ppcalfindmm([],[23 27],[2003 26],[26 2008],[2003 2008],126,calplt) ;

%    [ppimbg,stdmbg,pphistbg,ppminmaxbg] = pepperplotfun(bfile,0,[2 2]) ;

    [ppposdat,ppemitdat,ppim,pppixemit5d,pppixemit2d] = ...
        ppanalyse41(dfile,[],midpos,imtilt,sp2sp,pplim,width,zlen,rotang,enemat(9),plt,bitdiv) ;

    intsum = sum(pppixemit2d(:,5)) ;
    intdiv = intsum./histpart ;
    intens = (pppixemit2d(:,5)./intdiv) ;
    [ppemithist] = ppemithistgen(pppixemit2d(:,1),pppixemit2d(:,2),pppixemit2d(:,3), ...
        pppixemit2d(:,4),intens,3,3,angres,angres) ;
    lintrawrite(ppemithist(:,1),ppemithist(:,3),ppemithist(:,2),ppemithist(:,4),0,0,'pp_17kV-ex_35kV-plat_oldelec_pavar.txt') ;

    subdir{10} = (['Vary Both Extract and Post acceleration i.e. keep platform at 35kV (all images close to source)' ...
        bsfs 'with new post acceleration electrode']) ;
    prpdir{10} = ('pepperpot') ;
    datfile{10} = ('13kV_Ext_08_7A_Sec_4_2A_Pen.tif') ;
    calfile{10} = ('calib.tif') ;
    bgfile{10} = ('backgrnd.tif') ;
    enemat(10) = 35e3 ;

    cfile = [ppdir bsfs datdir bsfs char(subdir{10}) bsfs char(prpdir{10}) bsfs char(calfile{10})] ;
    bfile = [ppdir bsfs datdir bsfs char(subdir{10}) bsfs char(prpdir{10}) bsfs char(bgfile{10})] ;
    dfile = [ppdir bsfs datdir bsfs char(subdir{10}) bsfs char(prpdir{10}) bsfs char(datfile{10})] ;
%    ppimc = pepperplotfun(cfile,0,[2 2]) ;
%    figure, imagesc(ppimc,[120 3000]), axis image, colormap(gray) ;
%    [midpos,sp2sp,imtilt] = ppcalfindmm(cfile,[31 20],[2012 21],[32 2003],[2010 2003],126,calplt) ;
    [midpos,sp2sp,imtilt] = ppcalfindmm([],[31 20],[2012 21],[32 2003],[2010 2003],126,calplt) ;

%    [ppimbg,stdmbg,pphistbg,ppminmaxbg] = pepperplotfun(bfile,0,[2 2]) ;

    [ppposdat,ppemitdat,ppim,pppixemit5d,pppixemit2d] = ...
        ppanalyse41(dfile,[],midpos,imtilt,sp2sp,pplim,width,zlen,rotang,enemat(10),plt,bitdiv) ;

    intsum = sum(pppixemit2d(:,5)) ;
    intdiv = intsum./histpart ;
    intens = (pppixemit2d(:,5)./intdiv) ;
    [ppemithist] = ppemithistgen(pppixemit2d(:,1),pppixemit2d(:,2),pppixemit2d(:,3), ...
        pppixemit2d(:,4),intens,3,3,angres,angres) ;
    lintrawrite(ppemithist(:,1),ppemithist(:,3),ppemithist(:,2),ppemithist(:,4),0,0,'pp_13kV-ex_35kV-plat_newelec_pavar.txt') ;

    subdir{11} = (['Vary Both Extract and Post acceleration i.e. keep platform at 35kV (all images close to source)' ...
        bsfs 'with new post acceleration electrode']) ;
    prpdir{11} = ('pepperpot') ;
    datfile{11} = ('17kV_Ext_10_7A_Sec_4_2A_Pen.tif') ;
    calfile{11} = ('calib.tif') ;
    bgfile{11} = ('backgrnd.tif') ;
    enemat(11) = 35e3 ;

    cfile = [ppdir bsfs datdir bsfs char(subdir{11}) bsfs char(prpdir{11}) bsfs char(calfile{11})] ;
    bfile = [ppdir bsfs datdir bsfs char(subdir{11}) bsfs char(prpdir{11}) bsfs char(bgfile{11})] ;
    dfile = [ppdir bsfs datdir bsfs char(subdir{11}) bsfs char(prpdir{11}) bsfs char(datfile{11})] ;
%    ppimc = pepperplotfun(cfile,0,[2 2]) ;
%    figure, imagesc(ppimc,[120 3000]), axis image, colormap(gray) ;
%    [midpos,sp2sp,imtilt] = ppcalfindmm(cfile,[31 20],[2012 21],[32 2003],[2010 2003],126,calplt) ;
    [midpos,sp2sp,imtilt] = ppcalfindmm([],[31 20],[2012 21],[32 2003],[2010 2003],126,calplt) ;

%    [ppimbg,stdmbg,pphistbg,ppminmaxbg] = pepperplotfun(bfile,0,[2 2]) ;

    [ppposdat,ppemitdat,ppim,pppixemit5d,pppixemit2d] = ...
        ppanalyse41(dfile,[],midpos,imtilt,sp2sp,pplim,width,zlen,rotang,enemat(11),plt,bitdiv) ;

    intsum = sum(pppixemit2d(:,5)) ;
    intdiv = intsum./histpart ;
    intens = (pppixemit2d(:,5)./intdiv) ;
    [ppemithist] = ppemithistgen(pppixemit2d(:,1),pppixemit2d(:,2),pppixemit2d(:,3), ...
        pppixemit2d(:,4),intens,3,3,angres,angres) ;
    lintrawrite(ppemithist(:,1),ppemithist(:,3),ppemithist(:,2),ppemithist(:,4),0,0,'pp_17kV-ex_35kV-plat_newelec_pavar.txt') ;
    gdfwrite(ppemithist(:,1),ppemithist(:,3),ppemithist(:,2),ppemithist(:,4),0,enemat(11),[],'pp_17kV-ex_35kV-plat_newelec_pavar_gdf.txt') ;

    return



