function FFT=fft_read1_open(fft_root,isdata);
%
% Call FFT=fft_read1_open(fft_root);
%
% INPUT:
% fft_root		= root of _fft file;
%
% OUTPUT:
% FFT			= structure containing header info (nfft,fs,nf1,nf2,imap, etc);
%
%
% 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<2, isdata=1; end
%
fft_name=[fft_root,'_fft'];
%tms:  fft shortcuts
if ~exist(fft_name),
    if exist([fft_root '_fft.lnk']),
        disp(['Warning:  ' fft_name ' not found;  trying ' fft_name '.lnk'])
        fft_name=lnktarget([fft_root '_fft.lnk']);
    else
        exist(fft_name)~=2,
		disp(['Note: ',fft_name,' not found locally.']);
		[fft_name,path_name]=uigetfile('*_fft','Please Choose _fft File');
		if fft_name==0, LGRAM=[]; return; end
		fft_root=fft_name(1:end-4);
    end
end
FFT.fft_root=fft_root;
FFT.fft_name=fft_name;
% Plus OK? (for call from fft_write1_open):
FFT.fft_fid = fopen(fft_name,'r+','ieee-be');
if FFT.fft_fid==-1, 
	disp(fft_name); 
	error('FFT file not opened. Check that it exists'); 
end
[xh,count]=fread(FFT.fft_fid,20,'real*4');
if count<20, FFT.fft_fid, error('Error reading 20-word header'); end
FFT.xh=xh;
FFT.isdata = isdata;
FFT.moy0=xh(1) + xh(14)/60;
rng0=.001*xh(18);
[FFT.jday0,Jhour1,Jmin1]=moy2jday(FFT.moy0);
FFT.nT_int=xh(2);
FFT.Tfft=xh(5)/xh(6);
FFT.nfft=xh(5);
FFT.fs=xh(6);
FFT.dt=1/xh(6);
FFT.df=xh(6)/xh(5);
FFT.nbands=xh(7);
FFT.pri=xh(8);
FFT.iihann=xh(9);
if xh(10)<0, FFT.T_step=-xh(10); else, FFT.T_step=FFT.Tfft*(1-xh(10)/100); end
FFT.nrec=xh(11);
if FFT.nT_int<=0 | round(FFT.nT_int)~=FFT.nT_int | FFT.nT_int>FFT.nfft,
	disp('FFT has bad nT_int in header(2); assuming nT_int=nfft');
	disp('Make sure FFT maker puts nT_int into header(2)');
	FFT.nT_int=FFT.nfft;
end
%
if FFT.nbands==0,
	FFT.nbands=1;
	xh(15)=0;
	xh(16)=FFT.nfft/2;
end
nfreq=0;
for i=1:FFT.nbands;
	offset1(i)=xh(i*2+13);
	offset2(i)=xh(i*2+14);
	numbins(i)=offset2(i) - offset1(i) + 1;
	nfreq=nfreq + numbins(i);
end
imap=zeros(nfreq,3);
jj=0;
for i=1:FFT.nbands;
    jj2=jj + numbins(i);
	imap(jj+1:jj2,1)= offset1(i)+[1:numbins(i)]';
	jj=jj2;
end
%%disp(num2str(FFT.xh)), nfreq,
imap(:,2)=20 + [1:2:2*nfreq]';
imap(:,3)=imap(:,2) + 1;
FFT.f1=(imap(1,1)-1)*FFT.df; 
FFT.f2=(imap(nfreq,1)-1)*FFT.df;
FFT.nfreq=nfreq;
FFT.imap=imap;
FFT.nwords=20+2*nfreq;
FFT.lenrec=4*FFT.nwords;
% Compute number of sequences in FFT file:
frewind(FFT.fft_fid);
status=fseek(FFT.fft_fid,0,'eof');
if status<0, 
    error('Unsuccessful fseek to end of file - file too large?');
%    nseq=600, moy_last=FFT.moy0 + 60*4, rng_last=0,
end
n_byte=ftell(FFT.fft_fid);
if n_byte<0,
    error('Unsuccessful fseek to end of file - file too large?');
    n_byte=2^25-1,
end
nseq=n_byte/(FFT.nrec*FFT.lenrec);
FFT.nseq=round(nseq);
[XH,spec]=fft_read1(FFT,FFT.nseq,1,[1]);
moy_last=XH.moy + XH.t0/60;
rng_last=.001*XH.rng;
if abs(FFT.nseq-nseq)>.001,
	disp('WARNING: computed number of sequences not an integer!'); nseq,
end
% Read in last sequence of FFT file to get ending MOY:
FFT.moy_last=moy_last;
[Jday2,Jhour2,Jmin2]=moy2jday(moy_last);
hour1=Jhour1+Jmin1/60; hour2=Jhour2+Jmin2/60;
FFT.T_lims=[hour1, (Jday2-FFT.jday0)*24 + hour2];
%%FFT.T_step=diff(FFT.T_lims)*3600/max(FFT.nseq-1,1);
FFT.pct_step=100*FFT.T_step/FFT.Tfft;
FFT.Tax=mylinspace(FFT.moy0,moy_last,FFT.nseq);
FFT.range=mylinspace(rng0,rng_last,FFT.nseq);
hour1=mod(FFT.moy0,1440)/60; hour2=hour1 + (moy_last-FFT.moy0)/60;
FFT.hodax=mylinspace(hour1,hour2,FFT.nseq);
