
function ave_a = plot_ea_sub(drc, dat_f, lbl_f)

dat_fnm = [drc, dat_f]
lbl_fnm = [drc, lbl_f]

tl = dlmread(lbl_fnm, ' ', [0 0 2 2]);
G_FCTR = tl(2,1);
NOTHNG = tl(2,2);
AVE_E =  tl(2,3);

%[ENERGY, ALPHA, SECTOR] = dlmread(lbl_fnm,' ', [0 0 0 2]);
%[G_FCTR, NOTHNG, AVE_E] = dlmread(lbl_fnm,' ', [1 0 1 2]);
%[TAG] = textread(lbl_fnm,'%s', 1);

[ENERGY, ALPHA, SECTOR] = textread(dat_fnm,'%f %f %f', 1);

% TATE YOKO
range=[1 0 ENERGY 1];
ee = dlmread(dat_fnm, ' ', range);
range=[ENERGY+1 0 ENERGY+ALPHA 1];
aa = dlmread(dat_fnm, ' ', range);
range=[ENERGY+ALPHA+1 0 ENERGY+ALPHA+SECTOR 1];
pp = dlmread(dat_fnm, ' ', range);
range=[ENERGY+ALPHA+SECTOR+1 0 2*ENERGY+ALPHA+SECTOR ALPHA-1];
ea = dlmread(dat_fnm, ' ', range);

delt_a(1) = abs(aa(2,1) - aa(1,1));
delt_a(ALPHA) = abs(aa(ALPHA,1) - aa(ALPHA-1,1));
for i = 2:ALPHA-1
    delt_a(i) = abs(delt_a(i+1) - delt_a(i-1))/2.;
end
sum_a = 0.;
sum_d = 0.;
for i = 1:ALPHA
    %if aa(i,1) > 45
    %    continue;
    %end
    sum_a = sum_a + aa(i,2)*aa(i,1)*delt_a(i);
    sum_d = sum_d + aa(i,2)*delt_a(i);
end
ave_a = sum_a/sum_d;

    CVAL = 20;
    ENRGY_MIN= (ee(min(find(ee(:,2)>CVAL)),1)*(CVAL-ee(min(find(ee(:,2)>CVAL))-1,2)) + ee(min(find(ee(:,2)>CVAL))-1,1)*(ee(min(find(ee(:,2)>CVAL)),2)-CVAL))/(ee(min(find(ee(:,2)>CVAL)),2)-ee(min(find(ee(:,2)>CVAL))-1,2));
    ENRGY_MAX= (ee(max(find(ee(:,2)>CVAL)),1)*(CVAL-ee(max(find(ee(:,2)>CVAL))+1,2)) + ee(max(find(ee(:,2)>CVAL))+1,1)*(ee(max(find(ee(:,2)>CVAL)),2)-CVAL))/(ee(max(find(ee(:,2)>CVAL)),2)-ee(max(find(ee(:,2)>CVAL))+1,2));
    ALPHA_MIN= (aa(min(find(aa(:,2)>CVAL)),1)*(CVAL-aa(min(find(aa(:,2)>CVAL))-1,2)) + aa(min(find(aa(:,2)>CVAL))-1,1)*(aa(min(find(aa(:,2)>CVAL)),2)-CVAL))/(aa(min(find(aa(:,2)>CVAL)),2)-aa(min(find(aa(:,2)>CVAL))-1,2));
    %ALPHA_MAX= (aa(max(find(aa(:,2)>CVAL)),1)*(CVAL-aa(max(find(aa(:,2)>CVAL))+1,2)) + aa(max(find(aa(:,2)>CVAL))+1,1)*(aa(max(find(aa(:,2)>CVAL)),2)-CVAL))/(aa(max(find(aa(:,2)>CVAL)),2)-aa(max(find(aa(:,2)>CVAL))+1,2));
    %BETA_MIN = (pp(min(find(pp(:,2)>CVAL)),1)*(CVAL-pp(min(find(pp(:,2)>CVAL))-1,2)) + pp(min(find(pp(:,2)>CVAL))-1,1)*(pp(min(find(pp(:,2)>CVAL)),2)-CVAL))/(pp(min(find(pp(:,2)>CVAL)),2)-pp(min(find(pp(:,2)>CVAL))-1,2));
    %BETA_MAX = (pp(max(find(pp(:,2)>CVAL)),1)*(CVAL-pp(max(find(pp(:,2)>CVAL))+1,2)) + pp(max(find(pp(:,2)>CVAL))+1,1)*(pp(max(find(pp(:,2)>CVAL)),2)-CVAL))/(pp(max(find(pp(:,2)>CVAL)),2)-pp(max(find(pp(:,2)>CVAL))+1,2));
    ENRGY_0= (ee(min(find(ee(:,2)>500)),1)*(500-ee(min(find(ee(:,2)>500))-1,2)) + ee(min(find(ee(:,2)>500))-1,1)*(ee(min(find(ee(:,2)>500)),2)-500))/(ee(min(find(ee(:,2)>500)),2)-ee(min(find(ee(:,2)>500))-1,2));
    ENRGY_1= (ee(max(find(ee(:,2)>500)),1)*(500-ee(max(find(ee(:,2)>500))+1,2)) + ee(max(find(ee(:,2)>500))+1,1)*(ee(max(find(ee(:,2)>500)),2)-500))/(ee(max(find(ee(:,2)>500)),2)-ee(max(find(ee(:,2)>500))+1,2));
    ALPHA_0= (aa(min(find(aa(:,2)>500)),1)*(500-aa(min(find(aa(:,2)>500))-1,2)) + aa(min(find(aa(:,2)>500))-1,1)*(aa(min(find(aa(:,2)>500)),2)-500))/(aa(min(find(aa(:,2)>500)),2)-aa(min(find(aa(:,2)>500))-1,2));
    ALPHA_1= (aa(max(find(aa(:,2)>500)),1)*(500-aa(max(find(aa(:,2)>500))+1,2)) + aa(max(find(aa(:,2)>500))+1,1)*(aa(max(find(aa(:,2)>500)),2)-500))/(aa(max(find(aa(:,2)>500)),2)-aa(max(find(aa(:,2)>500))+1,2));
    %BETA_0 = (pp(min(find(pp(:,2)>500)),1)*(500-pp(min(find(pp(:,2)>500))-1,2)) + pp(min(find(pp(:,2)>500))-1,1)*(pp(min(find(pp(:,2)>500)),2)-500))/(pp(min(find(pp(:,2)>500)),2)-pp(min(find(pp(:,2)>500))-1,2));
    %BETA_1 = (pp(max(find(pp(:,2)>500)),1)*(500-pp(max(find(pp(:,2)>500))+1,2)) + pp(max(find(pp(:,2)>500))+1,1)*(pp(max(find(pp(:,2)>500)),2)-500))/(pp(max(find(pp(:,2)>500)),2)-pp(max(find(pp(:,2)>500))+1,2));
    ENRGY_FWHM = (ENRGY_1 - ENRGY_0)*100/AVE_E
    ALPHA_FWHM = ALPHA_1 - ALPHA_0
    %BETA_FWHM = BETA_1 - BETA_0;

figure(1);

subplot(2,2,1);
contour(aa(:,1), (ee(:,1)-AVE_E)*100/AVE_E, ea, 10);
grid on;
title(dat_f);
xlabel('Alpha');
ylabel('Energy(%)');

subplot(2,2,2);
plot(ee(:,2), (ee(:,1)-AVE_E)*100/AVE_E, 'rs','MarkerSize',4);
grid on;
title(['<E>/V  ', num2str(AVE_E/880)]); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%title(['<E>/V  ', num2str(AVE_E/880*1.099)]); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
xlabel('Counts');
ylabel('Energy(%)');
hold on
plot([CVAL, CVAL], ([ENRGY_MIN, ENRGY_MAX] -AVE_E)*100/AVE_E, 'bo-','MarkerSize',4)
plot([500, 500], ([ENRGY_0, ENRGY_1] -AVE_E)*100/AVE_E, 'bo-','MarkerSize',4)
hold off

subplot(2,2,3);
plot(aa(:,1), aa(:,2), 'rs','MarkerSize',4);
grid on;
title(['<a>: ', num2str(ave_a)]);
xlabel('Alpha');
ylabel('Counts');
hold on
%plot([ALPHA_MIN, ALPHA_MAX], [CVAL, CVAL], 'bo-','MarkerSize',4)
plot([ALPHA_0, ALPHA_1], [500, 500], 'bo-','MarkerSize',4)
hold off

subplot(2,2,4);
plot(pp(:,1), pp(:,2), 'rs','MarkerSize',4);
grid on;
title(['g: ', num2str(G_FCTR)]);
xlabel('Sector');
ylabel('Counts');
hold on
%plot([BETA_MIN, BETA_MAX], [CVAL, CVAL], 'bo-','MarkerSize',4)
%plot([BETA_0, BETA_1], [500, 500], 'bo-','MarkerSize',4)
hold off

