function [ toaRelativeToPhaseRefTime ] = rawToa2PhaseRefTime(pFloatRfb)
%RAWTOA2PHASEREFTIME Converts the raw toa to travel time relative to phasereftime
%   Takes the raw toa given in the rfb file (travel time relative to window
%   start) and converts it to the travel time relative to the phasereftime.
%   
%   To convert it, it adds the windowstart offset to the raw toa. 
%   Parameters:
%       pFloatRfb (struct) The RFB file loaded using artoa.load.rfb function.

%% Initialize return variables
toaRelativeToPhaseRefTime = false;

%% Parameter check

parameterError = false;


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

if (parameterError)
    return;
else
    clear parameterError;
end

%% Collect required data
% gets the toa converted to a column vector with one column
toa = pFloatRfb.DATA(:, pFloatRfb.VARIABLE_LIST.time_of_arrival);
toa = toa(:);

windowStart = pFloatRfb.FLOAT.windowstart;
windowsPerPhase = pFloatRfb.FLOAT.windowsperphase;
toaPerWindow = pFloatRfb.FLOAT.toaperwindow;
window = ones(length(toa), 1) * [1:1:windowsPerPhase];

for i = 1:length(windowStart)
    toa(window == i) = toa(window == i) + (windowStart(i) * 60);
end

toaRelativeToPhaseRefTime = toa;

end

