function [offsetTable] = generateOffsetTable(pFloatDetails, pSoundsources)
%GETDEFAULTOFFSETTABLE Summary of this function goes here
%   Detailed explanation goes here

%% Get required variables
variableNames = artoa.offsets.getDefaultVariableNames();

%% Initialize return variable
offsetTable = cell2table( ...
    artoa.offsets.getDefaultRowValues(), ...
    'VariableNames', variableNames ...
);

%% Setup rows

% float
offsetTable.Properties.RowNames(1) = {'Float'};
floatOffsets = artoa.data.getMember(pFloatDetails, {'offset'}, false);
startDate = NaN;
endDate = NaN;
startOffset = NaN;
endOffset = NaN;
drift = NaN;
if ~islogical(floatOffsets)
    sizeOffsets = size(floatOffsets);
    if sizeOffsets(1) >= 1 && sizeOffsets(2) >= 3 % start date can be calculated
        startDate = artoa.convert.dmy2rd( ...
            floatOffsets(1, 3), ...
            floatOffsets(1, 2), ...
            floatOffsets(1, 1) ...
        );
    end
    if sizeOffsets(1) >= 2 && sizeOffsets(2) >= 3 % end date can be calculated
        endDate = artoa.convert.dmy2rd( ...
            floatOffsets(2, 3), ...
            floatOffsets(2, 2), ...
            floatOffsets(2, 1) ...
        );
    end
    if sizeOffsets(1) >= 1 && sizeOffsets(2) >= 7 % start offset can be stored
        startOffset = floatOffsets(1, 7);
    end
    if sizeOffsets(1) >= 2 && sizeOffsets(2) >= 7
        % end offset can be stored and drift can be calculated
        endOffset = floatOffsets(2, 7);
        % calculate drift per day
        drift = (endOffset - startOffset) / (endDate - startDate);
    end
end

offsetTable{1, variableNames{1}} = startDate;
offsetTable{1, variableNames{2}} = startOffset;
offsetTable{1, variableNames{3}} = endDate;
offsetTable{1, variableNames{4}} = endOffset;
offsetTable{1, variableNames{5}} = drift;
clear startDate startOffset endDate endOffset drift;

if nargin == 1
    return;
end

if iscell(pSoundsources)
    for i = 1:length(pSoundsources)
        offsetTable(i + 1, :) = artoa.offsets.getDefaultRowValues();
        offsetTable.Properties.RowNames(i + 1) = {pSoundsources{i}.sourcename};
        [ ...
            offsetTable{i + 1, variableNames{1}}, ...
            offsetTable{i + 1, variableNames{2}}, ...
            offsetTable{i + 1, variableNames{3}}, ...
            offsetTable{i + 1, variableNames{4}}, ...
            offsetTable{i + 1, variableNames{5}} ...
            ] = extract(pSoundsources{i});
    end
end

if isstruct(pSoundsources)
    fnames = fieldnames(pSoundsources);
    for i = 1:length(fnames)
        offsetTable(i + 1, :) = artoa.offsets.getDefaultRowValues();
        offsetTable.Properties.RowNames(i + 1) = {pSoundsources.(fnames{i}).sourcename};
        [ ...
            offsetTable{i + 1, variableNames{1}}, ...
            offsetTable{i + 1, variableNames{2}}, ...
            offsetTable{i + 1, variableNames{3}}, ...
            offsetTable{i + 1, variableNames{4}}, ...
            offsetTable{i + 1, variableNames{5}} ...
            ] = extract(pSoundsources.(fnames{i}));
    end
end

    function [startDate, startOffset, endDate, endOffset, drift] = extract(pSoundsource)
        startDate = NaN;
        startOffset = NaN;
        endDate = NaN;
        endOffset = NaN;
        drift = NaN;
        % start date and offset
        paramOffset = artoa.data.getMember(pSoundsource, {'offset'}, false);
        if ~islogical(paramOffset)
            sizeOffset = size(paramOffset);
            if sizeOffset(1) >= 1 && sizeOffset(2) >= 3 % start date can be calculated
                startDate = artoa.convert.dmy2rd( ...
                    paramOffset(1, 3), ...
                    paramOffset(1, 2), ...
                    paramOffset(1, 1) ...
                );
            end
            if sizeOffset(1) >= 1 && sizeOffset(2) >= 4 % start offset can be stored
                startOffset = paramOffset(1, 4);
            end
        end

        % end date, offset and drift calculation
        paramRcvOffset = artoa.data.getMember(pSoundsource, {'rcv_offset'}, false);
        if ~islogical(paramRcvOffset)
            sizeRcvOffset = size(paramRcvOffset);
            if sizeRcvOffset(1) >= 1 && sizeRcvOffset(2) >= 3 % end date can be calculated
                endDate = artoa.convert.dmy2rd( ...
                    paramRcvOffset(1, 3), ...
                    paramRcvOffset(1, 2), ...
                    paramRcvOffset(1, 1) ...
                );
            end
            if sizeRcvOffset(1) >= 1 && sizeRcvOffset(2) >= 4 % end offset can be stored
                endOffset = paramRcvOffset(1, 4);
                if ~isnan(startOffset)
                    % calculate drift per day
                    drift = (endOffset - startOffset) / (endDate - startDate);
                end
            end
        end
    end

end