function mapleinit
%MAPLEINIT Initialize MAPLE.
%	MAPLEINIT is called by MAPLEMEX to initialize the Maple Kernel.
%	MAPLEINIT determines the path to the directory containing the Maple
%	Library, loads the linear algebra package, initializes Digits,
%	and establishes several aliases.
%
%	This M-file, "symbolic/mapleinit.m", may be modified to access
%	a copy of the Maple V, Release 3, Library available elsewhere.

%	Copyright (c) 1993-95 by The MathWorks, Inc.
%	$Revision: 1.16 $  $Date: 1995/03/17 20:58:04 $

% If you already have a copy of the Library for Maple V, Release 3,
% you may modify the following code to set "maplelib" to the full
% path name of that library, e.g. maplelib = '/usr/local/Maple/lib',
% or maplelib = 'C:\MAPLE\LIB', or maplelib = 'MyDisk:Maple:Lib'.
% You can then delete the copy of the Maple Library that is distributed
% with MATLAB.
%
% EXCEPTION: DEC Alpha OSF/1 requires a separate Maple V, Release 3 Library
%            called lib64. Both lib and lib64 can coexist in the same
%            directory.
%

already_have_Maple = 0;
if (already_have_Maple)
   maplelib = '.....';
else
%  Find 'symbolic' or 'symbolic_lib' in the MATLAB path.
%  Append '_lib' if necessary.
   p = path;
   k = min(findstr(p,'general'));
   pathsep = p(k+7);         % Path separator, ':', ';' or ','.
   dirsep = p(k-1);          % Directory separator, '/', '\' or ':'.
   p = [pathsep p pathsep];
%
% ALPHA requires a 64 bit library
%
   libname ='lib';
   com = computer;
   if length(com) == 5
      if com == 'ALPHA';
	 libname='lib64';
      end
   end
%
   k = findstr(lower(p),['symbolic' dirsep libname pathsep]);
   if length(k) == 1
      lib = [];
   else
      k = findstr(lower(p),['toolbox' dirsep 'symbolic' pathsep]);
      if length(k) ~= 1
         error('MATLAB path should have exactly one symbolic toolbox.')
      end
      lib = [dirsep libname];
   end
   c = find(p == pathsep);
   i = max(c(c<k))+1;
   j = min(c(c>k))-1;
   maplelib = [p(i:j) lib];
end

% Inform Maple of path to its library.
maplemex(maplelib,0);

% Load linear algebra package, set digits.
maplemex('with(linalg):');
maplemex('readlib(ifactor):');
maplemex('Digits := 16;');

% Establish aliases.
maplemex('alias(I=I, i=sqrt(-1), pi=Pi);');
maplemex('alias(log=ln, inf=infinity, Inf=infinity, fix=trunc);');
maplemex('alias(asin=arcsin, acos=arccos, atan=arctan);');
maplemex('alias(asinh=arcsinh, acosh=arccosh, atanh=arctanh);');
maplemex('alias(acsc=arccsc, asec=arcsec, acot=arccot);');
maplemex('alias(acsch=arccsch, asech=arcsech, acoth=arccoth);');
maplemex('alias(sinint=Si, cosint=Ci, lambertw=W, zeta=Zeta);');
maplemex('alias(eye=&*());');

% Turn off "bytes used" and garbage collection messages.
maplemex('words(0);');
maplemex('gc(0);');
