function [fid,fmt,nchan,iirec_all,nrec_all,Jday,Jhour,Jhour_end,nbyte_file]= ...
	hlab_header(data_file,fs);
%
% Call [fid,fmt,nchan,iirec_all,nrec_all,Jday,Jhour,Jhour_end]= ...
%	hlab_header(data_file,fs);
%
%
% 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.
top3bits = 2^13 + 2^14 + 2^15;
fmt='int16';
%
little_first=0;
if little_first,
    fid=fopen(data_file,'r','ieee-le');		% Try ieee-le first
else
   fid=fopen(data_file,'r','ieee-be');		% Try ieee-be first
end
%
status=fseek(fid,0,'eof');				% Go to end of file
nbyte_file=ftell(fid);					% # bytes in file
status=fseek(fid,0,'bof');				% Rewind;
% eid = sync_tcode(2); e_data = eid + 2^16;
% if min(min(e_data)) < top3bits
%    disp('Trying to open data file as ''ieee-le'' instead ...');
%    fclose(fid);
%    if little_first,
%        fid=fopen(data_file,'r','ieee-be');		% Must re-open as ieee-be;
%    else
%        fid=fopen(data_file,'r','ieee-le');		% Must re-open as ieee-le;
%    end
%    [sync_tcode,count]=fread(fid,37,fmt);
% 	eid = sync_tcode(2); e_data = eid + 2^16;
%    if min(min(e_data)) < top3bits,
%       error('Could not get valid sync code from file');
%    else
%       disp('Re-open as ''ieee-le'' successful');
%    end
% end
%
if fid<0, disp(['Data file ',data_file 'could not be opened.']); end
nchan=37; iirec_all=[3:37]; 
nrec_all=length(iirec_all); tcode=zeros(1,7); calfac=1; %%%????
for jframe=1:19,
	[sync_tcode,count]=fread(fid,37,fmt); 
	eid = sync_tcode(2);
	e_data = eid + 2^16;
	top3bits = 2^13 + 2^14 + 2^15;
	if min(min(e_data)) >= top3bits
%		disp('  Passed: The 3 most significant bits of all engineering words are "111".')
	else
		e_data,top3bits,jframe
		disp('  Failed: The 3 most significant bits of all engineering words should be "111"??')
	end
% We can remove the 3 most significant bits in case it might make "bitget" run faster:
	e_data = e_data - top3bits;
% This initialization does make the following "for" loop run much faster:
	e_bits = bitget(e_data,1:13);
	eid = 1*e_bits(9) + 2*e_bits(10) + 4*e_bits(11) + 8*e_bits(12) + 16*e_bits(13);
	if ismember(eid,[0:6]) % For ENG ID 0 to 6, interpret the engineering byte as a BCD:
 		bcd = 1*e_bits(1) + 2*e_bits(2) + 4*e_bits(3) + 8*e_bits(4) ...
			+ 10*( 1*e_bits(5) + 2*e_bits(6) + 4*e_bits(7) + 8*e_bits(8) );
		tcode(eid+1)=bcd;
	end
end
%days_mo=[31 28 31 30 31 30 , 31 31 30 31 30 31]; if mod(tcode(7),4)==0, days_mo(2)=29; end
%Jday=sum(days_mo(1:tcode(5)-1)) + tcode(4),
year=tcode(6)*100+tcode(7);
if ((tcode(5) < 1) | (tcode(5) > 12))
    disp(['Illegal month ' num2str(tcode(5)) '.  Resetting'])
end
Jday=date_to_Jday(tcode(5),tcode(4),year);
Jhour=tcode(3) + tcode(2)/60 + tcode(1)/3600;
%
nbyte_sample=2;
nsamp_file=nbyte_file/(nchan*nbyte_sample);
Thour_file=nsamp_file/fs/3600;
Jhour_end=Jhour + Thour_file;
%
% NEW 6-19-00: Must rewind:
status=fseek(fid,0,'bof');				% Rewind
