function [varargout] = mcrversion
% MCRVERSION Return the version number of the MCR.
%
% The MCR version number consists of three digits, separated by
% decimal points. This function returns each digit as a separate output
% variable.  The update number (3rd digit) is optional.  If not coded, update
% is returned as 0.
%
%    [major, minor, update] = mcrversion;
%
% Major, minor and update are returned as integers. If the version number ever
% increases to more than three digits, simply call mcrversion with more
% outputs:
%
%    [major, minor, update, point] = mcrversion;
%
% However, at this time, all outputs past "update" will be returned as zeros.

% Copyright 2010 The MathWorks, Inc.

    % Get the MCR version number from mcrversion.ver in toolbox/compiler.

    versionFile = fullfile(matlabroot, 'toolbox', 'compiler', ...
                           'mcrversion.ver');

    if ~exist(versionFile, 'file')
        error(message('Compiler:mcrversion:MissingMCRVersionFile',versionFile));
    end

    % ssegench 10-19-15
    % modify to use textscan
    versionString =fileread(versionFile);
    % use textscan (recommended) to parse the string
    % this will return up to 3 values in a single 1x1 cell
    % Without the ".0" in "%.0d" it treats the first dot as a decimal
    % instead of a delimiter
    v = textscan(versionString, '%.0d', 3, 'Delimiter', '.');
    
    % initialize the 3 version parts (major, minor, update) to 0
    versionParts(1:3) = 0;
    
    % now set the parts to the values returned from textscan
    versionParts(1:length(v{1})) = v{1};
    
    if nargout >= 0
        varargout{1} = versionParts(1); % major
    end
    if nargout > 1
        varargout{2} = versionParts(2); % minor
    end
    if nargout > 2
        varargout{3} = versionParts(3); % update
    end
    for k=4:nargout
        varargout{k} = 0;
    end

