function orca_wind_xyz(hdf_root,out_root,zs,xyz_rec,freq_lims,BW,Tw)
%
%
%
% 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.
nrec=size(xyz_rec,1); 
if size(xyz_rec,2)~=3, error('xyz_rec must be nrec by 3'); end
%
if 0,
	iipert=1; blims=[.1,10,.1,1];
	[xg,yg,dA,N_ell,b_ax,iiell]=ellipse_grid([0,0],[0,0],blims,iipert);
	nsrc=length(xg);
	xyz_src=[1000*xg(:), 1000*yg(:), repmat(zs,[nsrc,1])];
end
%
% Try using circular sections:
rmin=.05; rmax=50; nsrc=500;
rng_ax=1000*logspace(log10(rmin),log10(rmax),nsrc);
delr=diff([0,rng_ax]);
dA=2*pi*rng_ax.*delr;
disp(sum(dA)), disp(pi*(1000*rmax+delr(end)/2)^2)
xyz_src=[rng_ax(:), zeros(nsrc,1), repmat(zs,[nsrc,1])];
%
[SD,status]=hdfsd_open([hdf_root,'.hdf']); if status<0, error('Reading SD'); end
jset_kn=find(strcmp(SD.data_name,'Re(kn)'));
if isempty(jset_kn), 
	error('Unexpected in orca_nba_ri_run: HDF file does not contain Re(kn), Im(kn).'); 
end
[KNR,status]=hdfsd_read(SD,[],jset_kn); if status<0, error('Reading KNR'); end
[KNI,status]=hdfsd_read(SD,[],jset_kn+1); if status<0, error('Reading KNI'); end
jset_vg=find(strncmp(SD.data_name,'Group Speed',11));
if isempty(jset_vg), 
	error('Unexpected in orca_nba_ri_run: HDF file does not contain Group Speed.'); 
end
[VG,status]=hdfsd_read(SD,[],jset_vg); if status<0, error('Reading VG'); end
%
jset_phi_re=find(strcmp(SD.data_name,'Re(phi)'));
jset_phi_im=find(strcmp(SD.data_name,'Im(phi)'));
if isempty(jset_phi_re) | isempty(jset_phi_im), error('Re/Im(phi) not found'); end
%
[PHI_re,status]=hdfsd_read(SD,[],jset_phi_re); if status<0, error('Reading PHI_re'); end
[PHI_im,status]=hdfsd_read(SD,[],jset_phi_im); if status<0, error('Reading PHI_im'); end
%
iif=find(KNR.scales{1}>=freq_lims(1) & KNR.scales{1}<=freq_lims(2));
cf=KNR.scales{1}(iif), ncf=length(cf);
if BW==0, 
	if ncf>1, BW=2*min(diff(cf)); else, disp('BW=0, but ncf=1.  Setting BW=30.'); BW=30; end
end
if Tw<0, Tw=-1/Tw; end
df=1/Tw; ndf=ceil(BW/df); ndf=floor(ndf/2)*2+1; ndfh=(ndf-1)/2; df_ax=[-ndfh:ndfh]*df;
%
TF.ndim=3;
TF.dims=[ndf,nrec,ncf];
TF.labels={'Frequency - Hz','Receiver No.','CF - Hz'};
TF.scales={df_ax,[1:nrec],cf};
TF.data=zeros(ndf,nrec,ncf);
TF.dlab='Transfer Function'%

zmf=PHI_re.scales{1};
for jcf=1:ncf;
	jf=iif(jcf);
	kn=KNR.data(jf,:) + i*KNI.data(jf,:); vg=VG.data(jf,:); 
	phi=PHI_re.data(:,:,jf) + i*PHI_im.data(:,:,jf);
	f_ax=cf(jcf) + df_ax;
	tf=orca_nba_xyz(xyz_src,xyz_rec,cf(jcf),f_ax,kn,vg,zmf,phi);	% size: [ndf,nrec,nsrc]
	for jsrc=1:nsrc,
		tf(:,:,jsrc)=dA(jsrc)*tf(:,:,jsrc);
	end
	figure(222);
	tf_favg=squeeze(sum(zmagsq(tf(:,1,:)),1)); size(tf_favg), size(rng_ax),
	plot_cfill(.001*rng_ax,tf_favg);
	keyboard
	TF.data(:,:,jcf)=sum(tf,3);
end
%
str=['save ',out_root,'_WN TF']; disp(str); eval(str);
%
iifft=1;
if iifft,
	nrec=TF.dims(1); nfreq=TF.dims(2); nzp_f=2; ii_app=0;
	df=diff(TF.scales{2}(1:2)); f1=TF.scales{2}(1); f2=TF.scales{2}(end);
	FFT=fft_write1_open2(out_root,nrec,f1,f2,df,nzp_f,ii_app);
	jrec=[1:nrec];
	jday=0; t0=0; 
	jrec_parm=jrec;
	rng_m=TF.scales{2}*1000; c_ref=1500; w_ax=2*pi*TF.scales{3}.';
	jseq=1; t0=0;
	cspec=conj(TF.data(:,:,1).');
	count=fft_write1(FFT,cspec,jseq,jrec,jday,t0,jseq,jrec_parm);
	fclose(FFT.fft_fid);
end
