function PULSE=orca_wind_noise(SD,f_lims,zs_lims,zr_lims,rng_lims,tau_lims,p_lims,BW,iinorm,tsize,iifig,iinewfig);
% Call PULSE=orca_pulse_env(SD,f_lims,zs_lims,zr_lims,rng_lims,tau_lims,p_lims,BW,iinorm,tsize,iifig,iinewfig);
%
%
% 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.
if nargin<9, iinorm=1; end
if nargin<10, tsize=[]; end
if nargin<11, iifig=1; end
if nargin<12, iinewfig=1; end
%
% Read in needed
jset_phi=find(strcmp(SD.data_name,'mag(phi)'));
if isempty(jset_phi), error('mag(phi) not found'); end
%
[PHIR,stat]=hdfsd_read(SD,{zr_lims,[],f_lims,p_lims},jset_phi);
if stat~=0, error('Unsuccesful hdfsd_read of PHIR'); end
zr=PHIR.scales{1}; nzr=length(zr);
[PHIS,stat]=hdfsd_read(SD,{zs_lims,[],f_lims,p_lims},jset_phi); 
if stat~=0, error('Unsuccesful hdfsd_read of PHIS'); end
zs=PHIS.scales{1}; nzs=length(zs);
freq=PHIR.scales{3}; nfreq=length(freq);
if length(PHIR.scales)>3,
    parms=PHIR.scales{4}; nparm=length(parms);
else
    parms=0; nparm=1;
end
%
jset_knr=find(strcmp(SD.data_name,'Re(kn)'));
if isempty(jset_knr), error('Re(kn) not found'); end
[KNR,stat]=hdfsd_read(SD,{f_lims,[],p_lims},jset_knr);
if stat~=0, error('Unsuccesful hdfsd_read of KNR'); end
jset_kni=find(strcmp(SD.data_name,'Im(kn)'));
if isempty(jset_kni), error('Im(kn) not found'); end
[KNI,stat]=hdfsd_read(SD,{f_lims,[],p_lims},jset_kni);
if stat~=0, error('Unsuccesful hdfsd_read of KNI'); end
jset_vg=find(strcmp(SD.data_name,'Group Speed - m/s'));
if isempty(jset_vg), error('Group Speed not found'); end
[VG,stat]=hdfsd_read(SD,{f_lims,[],p_lims},jset_vg);
if stat~=0, error('Unsuccesful hdfsd_read of VG'); end
%
rng_km=adi_lim_eval(rng_lims); nrng=length(rng_km); rng=1000*rng_km;
%
Ts_ax=spread_env_init2(tau_lims,1/BW,3);
tau=Ts_ax.xax;
ntau=Ts_ax.nx;
fac=sqrt(2*pi);
PULSE.file_name=SD.hdf_file;
PULSE.dlab='TL - dB';
if nparm==1,
    PULSE.data=zeros(nzr,nrng,ntau,nzs,nfreq);
    PULSE.ndim=5;
    PULSE.dims=[nzr,nrng,ntau,nzs,nfreq];
    PULSE.labels={'Depth - m','Range - km','Time Delay - s','Source Depth - m','Frequency - Hz'};
    PULSE.scales={zr,rng_km,tau,zs,freq};
else
    PULSE.data=zeros(nzr,nrng,ntau,nzs,nfreq,nparm);
    PULSE.ndim=6;
    PULSE.dims=[nzr,nrng,ntau,nzs,nfreq,nparm];
    PULSE.labels={'Depth - m','Range - km','Time Delay - s','Source Depth - m','Frequency - Hz','Parameter'};
    PULSE.scales={zr,rng_km,tau,zs,freq,parms};
end
PULSE.iidB=1;
if iinorm,
    PULSE.dB_max=zeros(nrng,nfreq,nparm);
end
PULSE.vg_ref=zeros(nfreq,nparm);
%
for jparm=1:nparm,
	for jf=1:nfreq,
        iim=find(~isnan(KNR.data(jf,:,jparm))); nmode=length(iim);
		kn=KNR.data(jf,iim,jparm) + i*KNI.data(jf,iim,jparm);
		denom=real(kn).*imag(kn);
		K_sq=(2*pi*freq(jf)/1500)^2;
		for jzs=1:nzs,
			phis_sq=PHIS.data(jzs,iim,jf,jparm).^2; 
			for jzr=1:nzr,
				phir_sq=PHIR.data(jzr,iim,jf,jparm).^2; 
				summand=phis_sq.*phir_sq./denom;
				cw=(pi/2)*sum(summand)/K_sq;
				ndb(jzx)=5*log10(zmagsq(cw));
			end
		end
        if iinorm,
            for jrng=1:nrng,
                dB_max=max(max(max(PULSE.data(:,jrng,:,jzs,jf,jparm),[],3),[],1),[],4);
                PULSE.data(:,jrng,:,:,jf,jparm)=PULSE.data(:,jrng,:,:,jf,jparm) - repmat(dB_max,[nzr,1,ntau,nzs]);
                PULSE.dB_max(jrng,jf,jparm)=dB_max;
            end
        end
	end
end
dBmax=ceil(max(PULSE.data(:))/5)*5;
PULSE.clim=[dBmax-40,dBmax];
%
if iifig,
    [dim_sort,ii]=sort([nzr,nrng,0,nzs,nfreq,nparm]); vdims=[ii(6),3,ii(5)];
    keyboard
    view6(PULSE,vdims,[],iinewfig,tsize);
end
