function goals = getBlockGoals(blocks, goals)
% Returns the goals associated with the input blocks
% Input : 
% blocks - List of model objects
% goals - List of  empty goals. Length - totalGoalCount
% Output :
% goals - Updated goals list 
% Used by
%  * sldvData creation with all the blocks as input
%  * Proximity data creation with only specific SF blocks as input. 

%   Copyright 2023 The MathWorks, Inc.

% In case of proximity calculation, the input goals will be an empty list

startCount = 1;
for blk = blocks(:)'
    blkGoals = Sldv.DataUtils.processInternalGoals(blk);
    blkGoalCount = numel(blkGoals);
    if blkGoalCount > 0
        endCount = (startCount + blkGoalCount)-1;
        goals(startCount:endCount) = blkGoals;
        startCount = endCount + 1;
    end
end
numGoals = startCount;
if startCount > 1
    totalGoalCount = numel(goals);
    % Remove unused memory from array
    if totalGoalCount>=numGoals
        goals(numGoals:totalGoalCount) = [];
    end
else
    goals = [];
end

end
