%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% startup script
%
% Adds all MATLAB and Java function recursively to the MATLAB path
%
% Aaron Ponti, 2005/04/11
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%--------------------------------------------------------------------------
%
%   The contents of this file are subject to the Mozilla Public License
%   Version 1.1 (the "License"); you may not use this file except in
%   compliance with the License. You may obtain a copy of the License at 
%   http://www.mozilla.org/MPL/
% 
%   Software distributed under the License is distributed on an "AS IS"
%   basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
%   License for the specific language governing rights and limitations 
%   under the License.
% 
%   The Original Code is "Qu for MATLAB".
% 
%   The Initial Developer of the Original Code is Aaron Ponti.
%   All Rights Reserved.
%
%--------------------------------------------------------------------------

% Get MATLABHOME environment variable
home=getenv('MATLABHOME');
if isempty(home)
    disp('Error: the environment variable ''MATLABHOME'' was not set.');
    disp('Only MATLAB''s standard functions and toolboxes will be accessible for this session.');
    return  
end

% Create path recursively
home=[home,filesep,'matlab'];

fprintf(1,'Please wait while the dynamic MATLAB and JAVA paths are built.\n');
try
    
    % This is the modified version of genpath
    [MATLABPATH,JAVAPATH]=cgenpath(home);
    
    % Add dynamic MATLAB path
    addpath(MATLABPATH);
    
    % Add dynamic JAVA path
    javaaddpath(JAVAPATH);
    
catch
    disp('Error: could not create the dynamic MATLAB path specified by the environment variable ''MATLABHOME''.');
    disp('Only MATLAB''s standard functions and toolboxes will be accessible for this session.');
    return
end

% Change to MATLABHOME directory
cd(home);

% Clear variables
clear home MATLABPATH JAVAPATH

% Inform
fprintf(1,'Ready.\n\n');

