% This script is called Comsol Multiphysics is started with MATLAB
%
% See also: mphdoc, mphload, mphversion

% Copyright (C) 2011 COMSOL

% Write some general information in the Command Window
fprintf('\nStarting the COMSOL Multiphysics LiveLink(TM) for MATLAB(R).\n\n')

% Try to find the user's startup file. Such file must have the
% name "comsolstartup.m" and be placed in the user's home
% directory or on the Matlab path.
if ispc
    userdir = getenv('userprofile');
else
    userdir = getenv('HOME');
end
startpath = fullfile(userdir, 'comsolstartup.m');
fprintf('Checking for additional startup script (comsolstartup.m)\n');
fprintf('  in: %s\n', userdir);
flag = false;
if exist(startpath, 'file')==2
    fprintf('\nRunning: %s\n\n', startpath)
    flag = true;
    run(startpath)
end

if flag==false
    fprintf('\nChecking for startup script on the MATLAB path\n');
    startpath = which('comsolstartup.m');
    if length(startpath)
        fprintf('Running: %s\n\n', startpath)
        run(startpath)
    end
end

if desktop('-inuse')
    fprintf('\n\nType <a href="matlab:mphdoc">mphdoc</a> or <a href="matlab:help mli">help mli</a> for more information\n\n')
else
    fprintf('\n\nType mphdoc or help mli for more information\n\n')
end

clear flag startpath userdir
