function [SHRU,status]=sw06_readFile_shru(fid)
% -----------------------------------------------------------------------
%   sw06_readFile_shru
%
%        Reads whole datafile
%        Make sure it is at the beginning of a data record.   
%
%        Converts raw data to volts
%
%        Also returns header associated with that data record.
%
%       [SHRU,STATUS] = sw06_readRec_shru(fid); 
%        SHRU[i].data and SHRU[i].hdr
% 
%  Remember:  File should be opened big endian for shru
%               fid = fopen(filename,'rb','ieee-be');
%
%   SW06 shru data ONLY    
%			Newhall  2006
%-------------------------------------------------------------------------

nch = 1;   % only 1 channel on shru
channel = [1];
bytes_hdr = 1024;

[drhs] = sw06_getAllDRH_shru(fid);
fseek(fid,0,'bof');

for ii = 1:length(drhs);
   
  %% fprintf('Record #%d/%d\n',ii,length(drhs))

  % ------------------------------------------
  %   some variables we have to know and set
  
  sfreq = drhs(ii).rhfs;
  spts = drhs(ii).npts;
  total_b_rec = drhs(ii).reclen;

  % ------------------------------------------
  
  % skip record header
  [status] = fseek(fid,bytes_hdr,'cof');
  if (status < 0)
      Data=[];
      fprintf('Error: Something very bad happened...\n');
      return;
  end
  
  % Get data record, all channels
  [all_data, count]=fread(fid,[nch,spts],'short'); % read 1 record of data
  if (count < 0)
      Data=[]; status=-1;
      fprintf('Error: Something very bad happened...\n');
      return;
  end
  
  % save only data to be returned.
  data = all_data(channel,:);
  
  %% from keith
  fixed_gain = 10;    % linear - fixed gain is 10 for shark, 20 for shru..
  ADC_halfscale = 2.5;  % ADC half scale volts (+/- half scale is ADC i/p range)
  ADC_maxvalue = 8192; % ADC maximum halfscale o/p value, half the 2's complement range
  norm_factor = ADC_halfscale/ADC_maxvalue/fixed_gain;
  
  % Now we clip off the last two bits as a gain (actually an exponent)
 
  data=data/4;
  mant=floor(data);
  % "floor" is required due to the nature of negative binary numbers
  gain=4*(data-floor(data));
  % exp=gain;
  gain=(2*(ones(length(channel),spts))).^(3*gain);
   
  data=data*norm_factor./gain;
  
  SHRU(ii).data = data(:);
  SHRU(ii).hdr = drhs(ii);
    
end
% ------------------------------------------------------------------- 
