function [ correctedToa ] = addFloatOffsetAndSignalLength(pFloatRfb, pToa)
%ADDFLOATOFFSETANDSIGNALLENGTH Adds the float offset, substracts signal length
%   
%   Parameters:
%       pFloatRfb (struct) The RFB file loaded using artoa.load.rfb function.
%       pToa (double)      The 1D Toa vector.

%% Initialize return variables
correctedToa = false;

%% Parameter check

parameterError = false;

if (~isstruct(pFloatRfb))
    warning([mfilename ': Given rfb data is not a struct!']);
    parameterError = true;
end
if (~isnumeric(pToa))
    warning([mfilename ': Given TOA data is not numeric!']);
    parameterError = true;
end

if (parameterError)
    return;
else
    clear parameterError;
end

%% Add offset and subtract signal length

signalLength = pFloatRfb.FLOAT.signal_length;
floatOffset = pFloatRfb.FLOAT.offset(:, 6);
if size(floatOffset, 1) == 1
    floatOffset = [floatOffset; NaN];
end
schedule = pFloatRfb.FLOAT.schedule;
step = schedule / 24;
cycle = pFloatRfb.FLOAT.cycle;
cycleBegin = artoa.convert.dmy2rd(cycle(6), cycle(5), cycle(4)) ...
    + artoa.convert.hms2rd(cycle(7), cycle(8), 0);
cycleEnd = artoa.convert.dmy2rd(cycle(13), cycle(12), cycle(11)) ...
    + artoa.convert.hms2rd(cycle(14), cycle(15), 0);
toaDate = repmat([cycleBegin:step:cycleEnd]', 6, 1);

offsetCorrection = ...
    ((floatOffset(2) - floatOffset(1)) / (cycleEnd - cycleBegin)) ...
    * (toaDate - min(toaDate)) + floatOffset(1);

correctedToa = pToa + offsetCorrection - signalLength;

end

