Skip to content
Snippets Groups Projects
calculateTrajectoryObject.m 4.62 KiB
Newer Older
function [trajectoryObject] = calculateTrajectoryObject()
%CALCULATETRAJECTORYOBJECT Summary of this function goes here
%   Detailed explanation goes here

global artoaWorkspace artoaConfig artoaDataInput;

%% Remove all unused combinations
filteredSoundsourceCombinations = artoaWorkspace.trackParameter.soundsourceCombinations(artoaWorkspace.trackParameter.soundsourceCombinations.use, 2:end);
trackParameter = artoaWorkspace.trackParameter;
trackParameter.soundsourceCombinations = filteredSoundsourceCombinations;

if isempty(filteredSoundsourceCombinations)
    trajectoryObject = false;
    return;
end

%% Calculate trajectory
[ ...
    trajectory, ...
    trajectoryDates, ...
    trajectoryClockError, ...
    trajectoryResiduals, ...
    trajectoryVelocities, ...
    trajectoryTimeDivergenceToGps, ...
    trajectorySegmentSize, ...
    trajectoryVariationResults, ...
    toaData ...
] = calculateTrajectoryWithTrackParameter(trackParameter, false);


%% Setup trajectory object
trajectoryObject = struct();
trajectoryObject.trackParameter = artoaWorkspace.trackParameter;
trajectoryObject.offsets = artoaWorkspace.editOffsets.offsets;
trajectoryObject.toaData = toaData;
% trajectory contains [lat lon]
trajectoryObject.latitude = trajectory(:, 1);
trajectoryObject.longitude = trajectory(:, 2);
trajectoryObject.date = trajectoryDates;
trajectoryObject.clockError = trajectoryClockError;
trajectoryObject.residuals = trajectoryResiduals;
trajectoryObject.velocities = trajectoryVelocities;
trajectoryObject.timeDivergenceToGps = trajectoryTimeDivergenceToGps;
trajectoryObject.segmentSize = trajectorySegmentSize;
trajectoryObject.variationResults = trajectoryVariationResults;
% find pressure and temperature values
selectedIndices = (artoaWorkspace.statusPressure == 1) & (artoaWorkspace.statusTemperature == 1);
[~, dateIndices, indices] = intersect(trajectoryDates, artoaWorkspace.rafosDate(selectedIndices));
trajectoryObject.pressure = NaN(size(trajectoryDates));
trajectoryObject.pressure(dateIndices) = artoaWorkspace.pressure(indices);
trajectoryObject.temperature = NaN(size(trajectoryDates));
trajectoryObject.temperature(dateIndices) = artoaWorkspace.temperature(indices);


%% Helper functions
    function [ ...
            trajectory, ...
            trajectoryDates, ...
            trajectoryClockError, ...
            trajectoryResiduals, ...
            trajectoryVelocities, ...
            trajectoryTimeDivergenceToGps, ...
            trajectorySegmentSize, ...
            trajectoryVariationResults, ...
            toaData ...
        ] = calculateTrajectoryWithTrackParameter(pTrackingParameter, pStartEndPosition)

        pressureAndDate = { ...
            artoaWorkspace.pressure(artoaWorkspace.statusPressure == 1), ...
            artoaWorkspace.rafosDate(artoaWorkspace.statusPressure == 1) ...
        };

        % reset the toa data for recalculation
        % in general there is no reason why you create a workspace
        % and use the initial state of the data as input to
        % the tracking algorithm.
        % However in this case, the tracking algorithm contains
        % all necessary preparations to the data and applies them.
        % This was due to a design that allows to use the tracking
        % algorithm in separate from the rest of the program.
        % If this should be subject to change, it is required to remove all
        % adjustments to the TOA data in the tracking algorithm below.
        toaData = artoaWorkspace.toaData;
        toaData.toa = artoaDataInput.toaData.toa;

        [ ...
            trajectory, ...
            trajectoryDates, ...
            trajectoryClockError, ...
            trajectoryResiduals, ...
            trajectoryVelocities, ...
            trajectoryTimeDivergenceToGps, ...
            trajectorySegmentSize, ...
            trajectoryVariationResults ...
        ] = artoa.trajectory.calculate( ...
            artoaWorkspace.float, ...
            pressureAndDate, ...
            artoaWorkspace.satData, ...
            toaData, ...
            artoaWorkspace.filteredSoundsources, ...
            pTrackingParameter, ...
            artoaWorkspace.editOffsets, ...
            artoaConfig.leapseconds, ...
            artoaConfig.offsetvariations, ...
            pStartEndPosition ...
        );

        if trajectory == false
            errordlg([ ...
                'The trajectory could not be calculated. ' ...
                'Please check the inputs of the tracking parameter window and make sure ' ...
                ' the combinations you chose have applied TOAs!' ...
                ], ...
                'Trajectory error' ...
            );
            return;
        end
    end