function [nb, nt, off] = rdhead(fid, verbose);

%function [nb, nt, off] = rdhead(fid, verbose);
%	Read the header data from a raw ADCP
%	data file opened for binary reading.
%	fid = file handle returned by fopen
%	nb = number of bytes in the ensemble
%	nt = number of data types
%	off = offset to the data for each type
%	Set verbose = 1 for a text output.

% Written by Marinna Martini
% for the U.S. Geological Survey
% Atlantic Marine Geology, Woods Hole, MA
% 1/7/95

data = zeros(1,2);
fld=1;
if exist('verbose') ~= 1,
	verbose = 0;
end
nb=[]; nt=[]; off=[];

% make sure we're looking at the beginning of
% the header record by testing for it's ID
junk=fread(fid,2,'uchar');
if((length(junk)~=2) | (ftell(fid)<0)),
	disp('End of file found in rdhead.');
	return;
end
if ((junk(1)~=127) | (junk(2)~=127)),
	disp('Header ID not found');
	return;
end
% get the number of bytes this ensemble
nb = fread(fid,1,'int16');
if verbose, disp(sprintf('Number of bytes per ensemble %d',nb)); end;
% get the number of data types
fseek(fid,1,'cof');	% skip spare byte position
nt=fread(fid,1,'uchar');
if verbose, disp(sprintf('Number of data types %d',nt)); end;
% get the type offset
off=zeros(nt,1);
for j=1:nt, off(j)=fread(fid,1,'int16'); end

