  function lac = xray_make_lac_yl(xrs, lin)
%|function lac = xray_make_lac_yl(xrs, lin)
%|
%| xray_make_lac()
%| interpolate linear atten coef to source energy sampling
%| in
%|	xrs	strum	X-ray spectra; see xray_read_spectra.m
%|	lin	strum	linear attenuation coefficients; see xray_read_lac.m
%| out
%|	lac.lac	[ne L]
%|	lac.bar	[Ns L M]	effective linear attenuation coefficents near 0 for
%|                      for each gamma angle
%|
%|
%| Yong Long, 2010-07-12
%|
%|

if nargin < 2, help(mfilename), error(mfilename), end

% interpolate linear attenuation coefficients onto desired source energies
lac.lac = lin.lac(xrs.en); % [ne L] 
lac.bar = xray_read_lac_mean_yl(lac.lac, xrs.en, xrs.Ide); % [M L Ns]
 
%end  xray_make_lac_yl()


%
% xray_read_lac_mean_yl()
% spectrally-weighted "mean" lac
%
function bar = xray_read_lac_mean_yl(lac, kev, Ide)

LL = ncol(lac);
MM = ncol(kev);
I = permute(sum(Ide, 1), [2 3 1]); % [Ns M], Ide( [Ne, Ns, M] )
for mm = 1 : MM
    Imm = repmat( I(:,1), [1 LL]); % [Ns L],  % I: [Ns, M]
    bar(:,:,mm) = (Ide(:,:,mm)' * lac) ./ Imm; %[Ns L M]
end





