function cts_wf_from_txt(txt_root,fs,f0,BW)
%
% Call cts_wf_from_txt(txt_root,fs,f0,BW);
%
% Example calls:
%
% cts_wf_from_txt('mod_comb_b14',4000,490,35);
% cts_wf_from_txt('mod_comb_b11',4000,230,35);
% cts_wf_from_txt('qpsk_b14',4000,490,35);
% cts_wf_from_txt('qpsk_b11',4000,230,35);
%
%
% 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.
fid=fopen([txt_root,'.txt']),
[p,nfft]=fscanf(fid,'%g',inf);
if fs<0, fs=nfft/(-fs), end
PRI=nfft/fs; df=1/PRI;
disp(['PRI = ',num2str(PRI),'; fs = ',num2str(fs),'; npt = ',int2str(nfft)]);
%
P=fft(p);
%
n_safe_fac=20;
n_safe_fac=40;
for jf0=1:length(f0);
    f0x=f0(jf0),
    f_bb=round(f0x/df)*df
    jf_bb=round(f_bb/df) + 1;
    BWx=BW(jf0);
    fs_poss=2.^[2:20]/PRI; ii=find(fs_poss>=n_safe_fac*BWx);
%    [dfmin,ii]=min(abs(fs_poss-4000)),
    if isempty(ii), 
        disp('Calc of fs based on PRI failed: check cts_wf_from_txt.'); ii=1; 
    end
    fs_bb=fs_poss(ii(1)),
    nfft_bb=round(fs_bb/df)
    P_bb=zeros(1,nfft_bb);
    nf_take=min(nfft_bb/2-1,jf_bb-1);
    iif_pos=jf_bb + [0:nf_take-1];
    P_bb(1:nf_take)=P(iif_pos);
    iif_neg=jf_bb + [-nf_take:-1];
    P_bb(nfft_bb-nf_take+1:nfft_bb)=P(iif_neg);
    sig_bb=ifft(P_bb);
    fax_bb=[0:nfft_bb-1]*df;
    figure(215); plot(fax_bb,dB(P_bb));
    cts_root=[txt_root,'_',int2str(f0x)],
    cts_wf_make(cts_root,fs_bb,f_bb,f_bb,sig_bb,1);
end
keyboard
%
    
