function cts_wf_make(out_root,fs,f_bb,f0,sig_bb,iinorm)
%
% Call cts_wf_make(out_root,fs,f_bb,f0,sig_bb,iinorm);
%
% Makes a CTS file of a source waveform.
%
% INPUTS:
% out_root      = Output file root;
% fs            = Sample rate;
% f_bb          = Basebanding frequency;
% f0            = Center frequency (can be same as f_bb);
% sig_bb        = Complex, basebanded time series of source waveform;
% iinorm        = 1 to normalize to unit power;
%
% 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.
SL=zrms(sig_bb,0);
if iinorm, sig_bb=sig_bb/(10.^(SL/20)); SL=0; end
%
fid=cts_write_open(out_root,0,0,1,fs,f_bb,5,f0);
if fid<0, error('Error opening CTS file'); end
%
npt=length(sig_bb);
zz=[reshape(real(sig_bb),1,npt); reshape(imag(sig_bb),1,npt)];
% Write out multiplexed in receiver number (one receiver here), 
% with (real,imag) for each data point:
count=fwrite(fid,zz,'real*4');
if count<2*npt, 
    error(['Error writing CTS waveform to CTS file: ', ...
        int2str(count),' of ',int2str(2*npt), ' real*4 words written.']); 
end
ii=fclose(fid);
if ii==0,
    disp(['Finished writing CTS file ',out_root,'.cts']);
else
    disp(['Error writing CTS file ',out_root,'.cts']);
end
