function simrangesdata = getsimrangesdata(modelName, run, isDispAllResults)
    %GETSIMRANGESDATA Generate a cell array of the records in model's
    %dataset. The records are obtained from dataset and output in a struct containing:
    % results.Path                          simrangesdata.Path
    %         PathItem                                    SignalName
    %         SimMin                                      MinValue
    %         SimMax                                      MaxValue
    %         OvfWrap                                     OverflowOccurred
    %         OvfSat                                      SaturationOccurred
    %         DivByZero                                   DivisionByZeroOccurred
    %         ParamSat                                    ParameterSaturationOccurred
    %         SimDT                                       DataTypeName
    % Last argument (isDispAllResults) determines whether the results without simulation Min/Max
    % information is reported or not.
    
    %   Copyright 2007-2016 The MathWorks, Inc.
    if nargin < 3
        isDispAllResults = false;
    end
    
    appData = SimulinkFixedPoint.getApplicationData(modelName);
    
    %Disable warning
    warn_state = warning('query','MATLAB:structOnObject');
    warning('off','MATLAB:structOnObject');
    
    dsresults = appData.dataset.getResultsFromRun(run);
    simrangesdata = cell(1, numel(dsresults));
    idx = 1;
    % Convert one by one from dataset record to simragesdata struct
    for i = 1:length(dsresults)
        if(isempty(dsresults(i).SimMin) && isempty(dsresults(i).SimMax) && ~isDispAllResults); continue; end
        simrangesdata{idx}.Path = dsresults(i).getUniqueIdentifier.getObject.getFullName;
        simrangesdata{idx}.PathItem = dsresults(i).getElementName;
        if ~strcmpi(simrangesdata{idx}.PathItem, '1')
            simrangesdata{idx}.SignalName =  simrangesdata{idx}.PathItem;
        end
        
        dresult_struct = struct(dsresults(i));
        simrangesdata{idx}.MinValue = dresult_struct.SimMin;
        simrangesdata{idx}.MaxValue = dresult_struct.SimMax;
        
        if ~isempty(dresult_struct.OverflowWrap)
            simrangesdata{idx}.OverflowOccurred = dresult_struct.OverflowWrap;
        end
        if ~isempty(dresult_struct.OverflowSaturation)
            simrangesdata{idx}.SaturationOccurred = dresult_struct.OverflowSaturation;
        end
        if ~isempty(dresult_struct.DivideByZero)
            simrangesdata{idx}.DivisionByZeroOccurred = dresult_struct.DivideByZero;
        end
        if ~isempty(dresult_struct.ParameterSaturation)
            simrangesdata{idx}.ParameterSaturationOccurred = dresult_struct.ParameterSaturation;
        end
        if isempty(dresult_struct.ReplaceOutDataType)
            simrangesdata{idx}.ReplaceOutDataType = [];
        else
            simrangesdata{idx}.ReplaceOutDataType = dresult_struct.ReplaceOutDataType;
        end
        if isempty(dresult_struct.ReplacementOutDTName)
            simrangesdata{idx}.ReplacementOutDTName = '';
        else
            simrangesdata{idx}.ReplacementOutDTName = dresult_struct.ReplacementOutDTName;
        end
        if ~isempty(dsresults(i).RepresentableMin)
            simrangesdata{idx}.RepresentableMinProposed = dsresults(i).RepresentableMin;
        end
        if ~isempty(dsresults(i).RepresentableMax)
            simrangesdata{idx}.RepresentableMaxProposed = dsresults(i).RepresentableMax;
        end
        if isfield(simrangesdata{idx},'RepresentableMaxProposed') && isequal(simrangesdata{idx}.RepresentableMaxProposed, 0) && isequal(simrangesdata{idx}.RepresentableMinProposed, 0)
            simrangesdata{idx}.RepresentableMaxProposed = [];
            simrangesdata{idx}.RepresentableMinProposed = [];
        end
        if ~isempty(dresult_struct.ProposedDT)
            simrangesdata{idx}.ProposedDT = dresult_struct.ProposedDT;
        end
        if ~isempty(dresult_struct.IsVisible)
            simrangesdata{idx}.isVisible = dresult_struct.IsVisible;
        end
        
        simrangesdata{idx}.CompiledDT = dresult_struct.CompiledDT;
        
        if ~isempty(dresult_struct.IsScaledDouble)
            simrangesdata{idx}.isScaledDouble = dresult_struct.IsScaledDouble;
        end
        
        
        idx = idx + 1;
    end
    
    % remove unused cell elements
    simrangesdata(idx:end) = [];
    % Restore state of warning
    warning(warn_state.state,'MATLAB:structOnObject');
    
end

% LocalWords:  simrangesdata Ovf simragesdata
