function FFT=fft_write1_open2(fft_root,nrec,f1,f2,df,nzp_f,ii_app);
%
% FFT=fft_write1_open2(fft_root,nrec,f1,f2,df,nzp_f,ii_app);
%
% where
% fft_root		= Root of output FFT file;
%
%
% 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.
FFT.fft_root=fft_root;
FFT.fft_name=[fft_root,'_fft'];
ii_exist=exist(FFT.fft_name,'file');
if ii_app,
	if ~ii_exist,
		disp('Asked to apped, but creating new file since does not exist');
		ii_app=0;
	end
elseif ii_exist,
	disp('Warning: Overwriting existing FFT file.');	
end
%
nf1=round(f1/df) + 1; nf2=round(f2/df) + 1; nfreq=nf2-nf1+1
imap=zeros(nfreq,3);
imap(:,1)=[nf1:nf2]';
imap(:,2)=20 + [1:2:2*nfreq]';
imap(:,3)=imap(:,2) + 1;
%
jf1=imap(1,1)-1; jf2=imap(nfreq,1)-1;
%
nfft=2^(nextpow2(nf2) + nzp_f), fs=df*nfft,
nT_int=nfft; iihann=0;
%
if ii_app,
	FFT=fft_read1_open(fft_root);
	if FFT.nfft~=nfft | FFT.fs~=fs | FFT.nrec~=nrec | ...
		FFT.xh(15)~=jf1 | FFT.xh(16)~=jf2,
		error('Cannot append since FFT parms not same: ');
	end
	return
end
%
FFT.fft_fid=fopen(FFT.fft_name,'w','ieee-be');	
%
if FFT.fft_fid<0, 
	error(['CANNOT OPEN OUTPUT FFT FILE ',FFT.fft_name, ...
		'. Name too long or disk full?']);
end
%
FFT.nfft=nfft;
FFT.fs=fs;
FFT.dt=1/fs;
FFT.df=fs/nfft;
FFT.Tfft=1/FFT.df;
%if isfield(SP,'pri'), FFT.pri=SP.pri; else, FFT.pri=0; end
FFT.nT_int=nT_int;
FFT.nbands=1;
FFT.nrec=nrec;
%if isfield(REC,'z'), 
%	FFT.zr=REC.z + REC.dzr;
%elseif isfield(REC,'zr'), 
%	FFT.zr=REC.zr; 
%end
FFT.nfreq=nfreq;
FFT.imap=imap;
FFT.nwords=20 + 2*nfreq;
FFT.lenrec=4*FFT.nwords;
FFT.nseq=0;
FFT.iihann=iihann; 
FFT.T_step=1/df;
FFT.pri=0;
%
FFT.xh=[0 FFT.nT_int 0 1 FFT.nfft ...
		FFT.fs  FFT.nbands FFT.pri FFT.iihann -FFT.T_step ...
		FFT.nrec  0  0  0  jf1 jf2  0  0  0  0];
