%

% Copyright 2017-2018 The MathWorks, Inc.
function ds = readMetadata(this, sourceType, simIndex)
    if nargin == 1
        sourceType = xls.internal.SourceTypes.Unset;
        simIndex = 0;
    elseif nargin == 2
        simIndex = 0;
    elseif isempty(simIndex)
        simIndex = 0;
    end

    validateattributes(sourceType,["xls.internal.SourceTypes","string"],{'scalar'});
    validateattributes(simIndex,"numeric",{'scalar'});
    sourceType = xls.internal.SourceTypes(sourceType);

    this.resetTable;
    for idx = 1:length(this.Sheets)
        this.resetTable(true);
        this.readMetadataHelper(idx);
        range = this.getRange;
        if ~isempty(range)
            sheetName = this.getSheetFromIdx(idx);
            this.readDataHelper(sheetName, getParamRange(range));
            this.readSignalData(range, sourceType, simIndex);
        end
    end

    ds = this.ds;
end

function paramRange = getParamRange(range)
    simulations = range.getSimulations;
    if isscalar(simulations)
        paramRange = simulations.getParametersRange;
    else
        paramRange = xls.internal.ParametersRange.empty;
    end
end
