function helpDir = docroot
%DOCROOT A utility to determine the root directory of MATLAB Help

%   Copyright 1984-2000 The MathWorks, Inc.
%   $Revision: 1.12 $  $Date: 2000/08/10 15:52:36 $

% get user docpath
if usejava('mwt')
    helpDir = char(com.mathworks.ide.help.HelpPrefs.getDocRoot);
else
    if (strncmp(computer,'PC',2))
        helpDir = getprofl('Matlab Settings', 'Help Dir', '', 'matlab.ini');
    elseif (strncmp(computer,'MAC',3))
        helpDir = system_dependent(17);
    else
        [doccmd,options,helpDir] = docopt;
    end
    % try default if helpDir is still empty
    % we need this for UNIX if the studio bit is off
    if(isempty(helpDir))
       helpDir = fullfile(matlabroot,'help','');
    end
end
    
% verify user docpath
if (~isempty(helpDir))
    % remove trailing directory separator
    if (helpDir(end)==filesep)
        helpDir = helpDir(1:end-1);
    end
    % see if user docpath is valid
    if ((exist(fullfile(helpDir,'toolbox')) ~= 7)	& (exist(fullfile(helpDir,'techdoc','ref')) ~= 7))
        helpDir = '';
    end
end
