  function mac = xray_make_mac_yl(xrs, mas)
%|function mac = xray_make_mac_yl(xrs, mas)
%|
%| xray_make_mac()
%| interpolate mass atten coef to source energy sampling
%| in
%|	xrs	strum	X-ray spectra; see xray_read_spectra.m
%|	mas	strum	mass attenuation coefficients; see xray_read_mac.m
%| out
%|	mac.mac	[ne L]
%|	mac.bar	[Ns L M]	effective mass attenuation coefficents near 0 for
%|                      for each gamma angle
%|
%|
%| Yong Long, 2010-04-06, modified from xray_make_mac(xrs, mas)
%|
%|

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

% interpolate mass attenuation coefficients onto desired source energies
mac.mac = mas.mac(xrs.en); % [ne L] 
mac.bar = xray_read_mac_mean_yl(mac.mac, xrs.en, xrs.Ide); % [ Ns L M]
 
%end  xray_make_mac_yl()


%
% xray_read_mac_mean_yl()
% spectrally-weighted "mean" mac
%
function bar = xray_read_mac_mean_yl(mac, kev, Ide)

LL = ncol(mac);
MM = size(Ide, 3);
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)' * mac) ./ Imm; %[Ns L M]
end





