Skip to content
Snippets Groups Projects
recalculate.m 1.96 KiB
function [toaData] = recalculate(pFloat, pToaData, pAppliedSoundsources, pOffsetsTable)
%RECALCULATETOADATA Summary of this function goes here
%   Detailed explanation goes here

%% Prepare return variable
toaData = pToaData;

%% Add float offset
floatLaunchRafosTime = artoa.convert.dmy2rd( ...
    pFloat.launchtime(3), ...
    pFloat.launchtime(2), ...
    pFloat.launchtime(1) ...
) ...
+ artoa.convert.hms2rd( ...
    pFloat.launchtime(4), ...
    pFloat.launchtime(5), ...
    0 ...
);

%% Add drift for every phase
stepSize = length(toaData.toa) / pFloat.toaperphase;
for i = 1:stepSize:length(toaData.toa)
    startIndex = i;
    endIndex = i + stepSize - 1;
    toaData.toa(startIndex:endIndex) = artoa.toa.addDrift( ...
        toaData.toa(startIndex:endIndex), ...
        pOffsetsTable{'Float', 'offset'}, ...
        pOffsetsTable{'Float', 'drift'}, ...
        floor(min(toaData.toaDate) - floatLaunchRafosTime) ...
    );
end

%% Calculate soundsources
fnames = fieldnames(pAppliedSoundsources);
for i = 1:length(fnames)

    % get rafos start date
    rafosBeginEmission = artoa.convert.dmy2rd( ...
        pAppliedSoundsources.(fnames{i}).begemis(3), ...
        pAppliedSoundsources.(fnames{i}).begemis(2), ...
        pAppliedSoundsources.(fnames{i}).begemis(1) ...
    ) ...
    + artoa.convert.hms2rd( ...
        pAppliedSoundsources.(fnames{i}).begemis(4), ...
        pAppliedSoundsources.(fnames{i}).begemis(5), ...
        0 ...
    );

    toaLogical = strcmp(fnames{i}, toaData.soundSource);
    toaDate = toaData.toaDate(toaLogical);
    toa = toaData.toa(toaLogical);
    [toaDate, sortedDates] = sort(toaDate);
    toa = toa(sortedDates);

    % calculate drift of soundsource
    toa = artoa.toa.addDrift( ...
        toa, ...
        pOffsetsTable{fnames{i}, 'offset'}, ...
        pOffsetsTable{fnames{i}, 'drift'}, ...
        floor(toaDate - rafosBeginEmission) ...
    );

    % undo sorting
    toa(sortedDates) = toa;

    toaData.toa(toaLogical) = toa;
end

end