function r = fillhdg(instclass, fullfilebase, r);
% r = fillhdg(instclass, fullfilebase, r);
% fill att heading from aux files
% get it from aux: split_aux.py made a file called [a_file,'.hdg']
% must have already fixed time 
%the file has been read but not concatenated

aux = read_aux(instclass, fullfilebase);


goodi = [1:length(aux.ggadday)]';

if (isempty(r.dday))
   error('no data in r.dday (fillnavhdg)')
end


%replace with data att data: 
if (isfield(aux, 'gyro') & isfield(aux, 'ashgyrodiff'))
   ash_heading = table1(  ...
   [aux.ggadday(goodi) aux.gyro(goodi)+aux.ashgyrodiff(goodi)], r.dday);
   gyroheading = r.heading;
   [mdiff, sdiff] = mstdgap(ash_heading - gyroheading );
   shd = std(r.heading);  %checking to see whether heading is updated in r
   if (length(r.dday) > 1)
      if (shd ~= 0) %measured headings differ
         r.heading = ash_heading;
         clg
         fprintf('measheading-auxheading: mean (%f) std (%f)\n', mdiff, sdiff)
         if (sdiff>.2)
            warning('possible heading error detected in fillnavhdg')
            clg
            plot(r.dday, ash_heading,'r.')
            hold on
            plot(r.dday, gyroheading,'g.')
            title('gyro: green; ashtech: red')
            paused
         end
      else %measured headings do not change
         fprintf('no headings available\n')
      end
   end
end

