function [nb2gga_coef] = get_nbddaycoef(instclass,filepath, filebase, yearbase)
% [nb2gga_coef] = get_nbddaycoef(instclass, filepath, filebase, yearbase)
% read in the scan file to get time ranges for the segments
% offset and slope (for nbdday which was shifted to start at 0)
% nbdday0 = nbdday - nb2gga_coef(1); 
% corrected_nbdday = nbdday0 + nb2gga_coef(2) + nb2gga_coef(3)*nbdday 

[scn_filenum, scn_startdd, scn_enddd] =...
    read_asc([filepath, '/aux_.scn'] ,7 , [1 2 5]);
thisfile_i = 0;
for ii = 1:length(scn_filenum)
   if (strcmp(filebase, sprintf('%d', scn_filenum(ii))))
      thisfile_i = ii;
   end
end
if (thisfile_i == 0)
   error(sprintf('could not find file base %s in aux_.scn\n', filebase))
end


filebase = fullfile(filepath, filebase );
rawfilename = sprintf('%s.raw', filebase);

aends =  read(instclass, rawfilename, 'ends', 2, 'yearbase', yearbase);


if (diff(aends.dday) == 0)
   error(sprintf('start and end times of %s are identical\n', filebase'))
end

nbdday0range = [0 diff(aends.dday)];

auxdata = read_aux(instclass, filebase);

badi = find(isnan(auxdata.ggadday));
auxdata.ggadday(badi)=[];


ggaddayrange = [auxdata.ggadday(1) auxdata.ggadday(end)];
nb2gga_coef = ...
    [aends.dday(1) auxdata.ggadday(1)  diff(ggaddayrange)/diff(nbdday0range)];


%just in case there are repeated times, stretch the time ever so slightly
if (nb2gga_coef(3) == 1)
   nb2gga_coef(3) = 1+10^(-7);
end
