function mcs_bform
%
%
% COPYRIGHT (c) 2008
% 
% Applied Research Laboratories, The University of Texas at Austin
% (ARL:UT)
% All rights reserved.
% 
% This material may be reproduced by or for the U.S. Government
% only. This notice must appear in all copies of this file and its
% derivatives. Further distribution outside the U.S. Government is
% prohibited without the explicit written authorization from the
% Director of the Environmental Sciences Laboratory, ARL:UT.
% 
% THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
% EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE
% IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
% PURPOSE, OR NONINFRINGEMENT.
% 
% IN NO EVENT WILL ARL:UT BE LIABLE FOR ANY DAMAGES WHATSOEVER ARISING
% OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN IF ARL:UT HAS
% BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
mcs_global
%
PRUNE=[]; BEAMS=[]; REP=[];
%
MCS.alpha=.2; MCS.alph1=1-MCS.alpha;
MCS.iinm=1;
%
Jday0=MCS.fft_dhm0(1,1);
MCS.xyz=MCS.xyz_all(MCS.iiph,:);
%
MCS.freq_lim=round(MCS.freq_lim/FFT.df)*FFT.df;		% Make freq_lim lie on integral df;
%
% Compute pruning frequencies and indices:
nph_sub_min=1;
lam_parms=[MCS.xc_aper(:)',MCS.bf_aper(:)',nph_sub_min]; iifig=0;
fmin=min(MCS.freq_lim); fmax=max(MCS.freq_lim);
PRUNE=mcs_prune_init2(MCS.xyz,[fmin,fmax],MCS.cavg,lam_parms,iifig);
%
% Compute replica vectors:
beam_parm=[MCS.iisin MCS.iivar MCS.fac_var];
[BEAMS,REP]=mcs_rep_init(beam_parm);
%
% Set up array for beamformer output versus frequency and beam number:
mcs_bf_out=zeros(BEAMS.nf_bf,BEAMS.nphi_out,MCS.nseq); cbf_bf_out=mcs_bf_out;
% Set up array for beamformer output versus time and beam number:
BTR.xlab='Bearing'; BTR.ylab=['Time - hour of day ',int2str(Jday0)];
BTR.zlab=' ';
BTR.x=BEAMS.phi_out;
BTR.y=zeros(MCS.nseq,1);
BTR.z=0;
BTR.data=zeros(MCS.nseq,BEAMS.nphi_out); BTR.cbf=BTR.data;
% Loop over time:
for js=1:MCS.nseq,
	jseq=MCS.seq_nos(js);
% Read FFTS for this sequence:
	[XH,xspec]=fft_read1(FFT,jseq,MCS.iiph,BEAMS.iifbin);
	if BEAMS.nf_abf>0, 
% Update CSDMs for frequencies at which ABF is done:
		mcs_csdm_upd; 
% Compute adaptive weights for frequencies at which ABF is done:
	end
%
% Apply weights at each frequency:
	for jf_bf=1:BEAMS.nf_bf,
% Beamform at each frequency:
		[mcs_out,cbf_out]=mcs_bf_calc(jf_bf,xspec);
		mcs_bf_out(jf_bf,:,js)=mcs_out; cbf_bf_out(jf_bf,:,js)=cbf_out;
	end
% Average over frequency:
	BTR.data(js,:)=mean(mcs_bf_out(:,:,js),1); BTR.cbf(js,:)=mean(cbf_bf_out(:,:,js),1);
	disp(['Finished sequence ',int2str(js),' of ',int2str(MCS.nseq)])
% Set time axis for this sequence:
	[Jday,Jhour,Jmin]=moy2jday(XH.moy); 
	BTR.y(js)=(Jday-Jday0)*24 + Jhour + Jmin/60;
end

%view3(BTR);
figure
imagesc(BTR.x,BTR.y,BTR.data); colorbar; colormap(1-gray);
xlabel(BTR.xlab); ylabel(BTR.ylab);
