Skip to content
Snippets Groups Projects
solve.m 3.25 KiB
function [a, b, x] = solve(pRfb, pSoundsources, pSatData, pAppliedTemperature, pAppliedPressure, pSoundspeedMethod, pLeapsecondsMatrix)
%UNTITLED Summary of this function goes here
%   Detailed explanation goes here

%% Initialize required variables
%pSoundsources = artoa.controller.getSoundsourcesWithAppliedToa();
satPositions = [pSatData.lat_sat, pSatData.lon_sat];
satDates = artoa.convert.dmy2rd(pSatData.day_sat, pSatData.month_sat, pSatData.year_sat);
toaDates = [];
satToas = [];
satDistances = [];
floatDetails = pRfb.FLOAT;

%% Create table
results = struct();

%% Calculate SAT TOAs for every soundsource
fnames = fieldnames(pSoundsources);
for i = 1:length(fnames)
    results.(fnames{i}) = table();
    [date, toa] = artoa.toa.predictFromGps( ...
        pRfb, ...
        pSoundsources.(fnames{i}), ...
        struct( ...
            'temperature', pAppliedTemperature, ...
            'pressure', pAppliedPressure, ...
            'method', pSoundspeedMethod, ...
            'soundSource', NaN ...
        ), ...
        pLeapsecondsMatrix ...
    );
    results.(fnames{i}).satDate = date;
    results.(fnames{i}).satToa = toa;
    results.(fnames{i}).daysSinceStart = ...
        date ...
        - artoa.convert.dmy2rd( ...
            pSoundsources.(fnames{i}).begemis(3), ...
            pSoundsources.(fnames{i}).begemis(2), ...
            pSoundsources.(fnames{i}).begemis(1) ...
        );
    tmpDistances = [];
    % calculate distances
    for oDistance = 1:length(toa)
        if isnan(toa(oDistance)) | any(isnan(satPositions(oDistance, :)))
            tmpDistances = [tmpDistances; NaN];
            continue;
        end
        tmpDistances = [ ...
            tmpDistances; ...
            artoa.data.calculateGeodist( ...
                satPositions(oDistance, :), ...
                pSoundsources.(fnames{i}).position ...
            ) ...
        ];
    end
    results.(fnames{i}).satDistances = tmpDistances;
    clear tmpDistances;
end

%% Construct matrices A and B

rowCount = length(satDates) * length(fnames);

aCore = zeros(rowCount, 2 * length(fnames));
b = zeros(rowCount, 1);
distances = zeros(rowCount, 1);
daysSinceFloatStart = NaN(rowCount, 1);
soundVelocity = NaN(rowCount, 1);
soundVelocity(:) = artoa.data.calculateSoundVelocity( ...
    pAppliedTemperature, ...