function [TM] = sw06_gettime_shru(drhs)
% -----------------------------------------------------------
%  sw06_gettime_shru
%
%   [TM] = sw06_gettime_shru(drhs);
%
%   returns time from an array of shru headers
%
%
%                              newhall  8/8/2006
% ----------------------------------------------------------

if (nargin == 0)
    error('  No argument in function call.\n');
    return
end

nrecs  = length(drhs);      % number of records

if (nrecs == 1)
     
  yd = drhs.date(2);               %  yearday  (integer)
  minute = drhs.time(1);           %  hours*60+minutes
  millisec = drhs.time(2);         %  seconds*1000 + milliseconds
  microsec = drhs.microsec;        %  millisec = microsecs/1000
  
  tot_ms  = millisec + microsec/1000;
  tot_sec = tot_ms/1000;
  tot_min = minute + tot_sec/60;
  
  TM.yday = yd + tot_min/(60*24);         % days from Jan 1st (yearday)
  TM.ymin = yd*24*60 + tot_min;              % min from Jan 1st
  
  TM.day = yd;                            % day number
  TM.hr  = floor(tot_min/60);             % hour
  TM.min = floor((tot_min/60-TM.hr)*60);  % minute
  TM.sec = ((tot_min/60-TM.hr)*60-TM.min)*60;  % second
  
  TM.org_micros = microsec;               % original microsecs
  TM.org_millis  = millisec;              % original millisecs
  TM.org_min = minute;                    % original minutes
  TM.yr  = drhs.date(1);
  
  % This length is to the end of the record (16 secs for shark...)
  TM.tlen_min = drhs.npts/drhs.rhfs/60;
  TM.tlen_sec = drhs.npts/drhs.rhfs; 
  
else     % for multiple headers...   addon... 
         % Probably don't need an if!!

  fs     = drhs(1).rhfs;      % freq
  nchan  = drhs(1).ch;        % number of channels
  reclen = drhs(1).reclen;    % record length + header (1251024)
  nscans = drhs(1).npts;      % bytes per scan
  nrecs  = length(drhs);      % number of records

  for rec=1:nrecs
      
    yd = drhs(rec).date(2);               %  yearday  (integer)
    minute = drhs(rec).time(1);           %  hours*60+minutes
    millisec = drhs(rec).time(2);         %  seconds*1000 + milliseconds
    microsec = drhs(rec).microsec;        %  millisec = microsecs/1000
  
    tot_ms  = millisec + microsec/1000;
    tot_sec = tot_ms/1000;
    tot_min = minute + tot_sec/60;
  
    TM(rec).yday = yd + tot_min/(60*24);      % days from Jan 1st (yearday)
    TM(rec).ymin = yd*24*60 + tot_min;           % min from Jan 1st
  
    TM(rec).day = yd;                            % day number
    TM(rec).hr  = floor(tot_min/60);             % hour
    TM(rec).min = floor((tot_min/60-TM(rec).hr)*60);  % minute
    TM(rec).sec = ((tot_min/60-TM(rec).hr)*60-TM(rec).min)*60;  % second
  
    TM(rec).org_micros = microsec;               % original microsecs
    TM(rec).org_millis  = millisec;              % original millisecs
    TM(rec).org_min = minute;                    % original minutes
    TM(rec).yr  = drhs(rec).date(1);
  
  
     % duration to this point
  
    yd_begin = drhs(1).date(2);
    t_begin = drhs(1).time(1)   + drhs(1).time(2)/(60*1000);  % mins
    d_begin = yd_begin + t_begin/(60*24);
    m_begin = yd_begin*24*60 + t_begin;
  
    %  end time in rec is beginning of data rec, not when finished
    %  add another 16 secs for shark??????   Na..
    
    yd_end = drhs(rec).date(2);
    tm_end = drhs(rec).time(1)   + drhs(rec).time(2)/(60*1000);
    d_end = yd_end + tm_end/(60*24);
    m_end = yd_end*24*60 + tm_end;
  
    TM(rec).tlen_min = m_end - m_begin + drhs(1).npts/drhs(1).rhfs/60;
    TM(rec).tlen_sec = m_end - m_begin + drhs(1).npts/drhs(1).rhfs;
    
  end 
  
end
% ---------------------------------------------------------------------
   
