function cts_shot(f0,BW,PRI,t0)
%
% Call cts_shot(f0,BW,PRI,t0);
%
% f0        = Center frequency;
% BW        = Bandwidth in Hz (negative for octaves);
% PRI       = Total length of CTS file;
%
% Example call:
% cts_shot(200,-1,100);
%
% See:  cts_details, cts_open, cts_read, cts_write, cts_write_open, cts_combine, cts2fft, cts2spec, 
%       cts_from_real, cts_shot, cts_wf_make, fft2cts, mcs_gui.
%
%
% 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.
fs=100000;
T=0.25;
iifig=0;
SHOT=shot([],[],T,fs,iifig);
%
dt=1/fs; T=SHOT.dims(1)*dt, df=1/T;
%
P=fft(SHOT.data);
fax=[0:df:fs-df/2];
%
n_safe_fac=2;
for jf0=1:length(f0);
    f0x=f0(jf0),
    f_bb=round(f0x/df)*df
    jf_bb=round(f_bb/df) + 1;
    BWx=BW(jf0);
    if BWx<0, 
        log_f0=log2(f0x);
        n_oct=-BWx;
        flims=2.^(log_f0 + n_oct/2*[-1,1]);
        BWx=diff(flims),
    else
        flims=f0x + BWx/2*[-1,1];
    end
    fs_poss=2.^[2:20]/T, ii=find(fs_poss>=n_safe_fac*BWx);
%    [dfmin,ii]=min(abs(fs_poss-4000)),
    if isempty(ii), 
        disp('Calc of fs based on T failed: check cts_wf_from_txt.'); ii=1; 
    end
    fs_bb=fs_poss(ii(1));
    nfft_bb=round(fs_bb/df);
    t_bb=[0:nfft_bb-1]/fs_bb;

    iif=find(fax>=flims(1) & fax<=flims(2)); niif=length(iif);
    hann=.5*(1 - cos((2*pi/niif)*[.5:1:niif]'));
    P_take=P(iif) .* hann;
    
    P_bb=zeros(1,nfft_bb);
    nf_take=min(nfft_bb/2-1,jf_bb-1);
    iif_pos=jf_bb + [0:nf_take-1];
    iif_pos=find(iif>=jf_bb);
    P_bb(1:length(iif_pos))=P_take(iif_pos);
    iif_neg=jf_bb + [-nf_take:-1];
    iif_neg=find(iif<jf_bb);
    P_bb(nfft_bb-length(iif_neg)+1:nfft_bb)=P_take(iif_neg);
    sig_bb0=ifft(P_bb);
    t_end=.01; t_into=0.1;
    npt_bb=round(PRI*fs_bb); npt_t0=round((t0-t_end)*fs_bb);
    npt_end=round(t_end*fs_bb); npt_into=round(t_into*fs_bb); 
    ii=[nfft_bb-npt_end:nfft_bb,1:npt_into]; nii=length(ii);
%    sig_bb=[sig_bb0(ii), sig_bb0(ii(end))*ones(1,npt_bb-length(ii))];
    sig_bb=[zeros(1,npt_t0), sig_bb0(ii), zeros(1,npt_bb-nii-npt_t0)];
    fax_bb=[0:nfft_bb-1]*df;
    plot(t_bb,dB(sig_bb(1:nfft_bb))); zoom on;
    plot(dB(sig_bb(1:2*nfft_bb)));
    cts_root=['shot','_',int2str(f0x),'_',int2str(BWx)],
    cts_wf_make(cts_root,fs_bb,f_bb,f_bb,sig_bb,1);
end
