function sldvData = addInportUsage(sldvData, forceUsed)
%

%   Copyright 2010-2014 The MathWorks, Inc.

    % Adds 'Used = true' field to all leaf-level signals (in Inport/Outport 
    % Info in sldvData) if that field is absent. If 'forceUsed' parameter 
    % is true, this field will be added even if the existing value of 'Used' 
    % field is false.

    if nargin<2
        forceUsed = false;
    end

    inportInfo = sldvData.AnalysisInformation.InputPortInfo;
    outportInfo = sldvData.AnalysisInformation.OutputPortInfo;    
    sldvData.AnalysisInformation.InputPortInfo = addUsedFieldForPorts(inportInfo, forceUsed);
    sldvData.AnalysisInformation.OutputPortInfo = addUsedFieldForPorts(outportInfo, forceUsed);
end

function portInfo = addUsedFieldForPorts(portInfo, forceUsed)
    for idx=1:length(portInfo)
        portInfo{idx} = addUsedFieldForPort(portInfo{idx}, forceUsed);
    end
end

function portInfo = addUsedFieldForPort(portInfo, forceUsed)
    if isstruct(portInfo) && (~isfield(portInfo, 'Used') || forceUsed)        
        portInfo.Used = true;        
    else
        for idx=2:length(portInfo)
            portInfosub = addUsedFieldForPort(portInfo{idx}, forceUsed);
            portInfo{idx} = portInfosub;
        end
    end
end