function s = procread(filename)
%PROCREAD Install a Maple procedure.
%	PROCREAD(FILENAME) reads the specified file, which should
%	contain the source text for a Maple procedure.  It deletes any
%	comments and newline characters, then sends the resulting string
%	to Maple.  The Extended Symbolic Toolbox is required.
%
%	Example.
%
%	    Suppose the file "check.src" contains the following
%	    source text for a Maple procedure.
%
%	        check := proc(A)
%	        #   check(A) computes A*inverse(A)
%	            local X;
%	            X := inverse(A):
%	            evalm(A &* X);
%	        end;
%
%	    Then the statement
%
%	        procread('check.src')
%
%	    installs the procedure.  It can be accessed with 
%
%	        maple('check',magic(3))
%
%	    or
%
%	        maple('check',vpa(magic(3)))
%
%	See also MAPLE.

%	Copyright (c) 1993-95 by The MathWorks, Inc.
%	$Revision: 1.4 $  $Date: 1995/03/01 21:38:55 $

% Open the file and read the text.

f = fopen(filename);
if f < 0
   error(['Could not open ' filename])
end
s = fread(f)';

% Delete comments and newlines.

e = find(s==10);
for j = fliplr(find(s=='#'))
   k = min(e(e>j));
   s(j:k) = [];
end
e = find(s==10);
s(e) = ' '*ones(size(e));

% Send the string to Maple.

s = setstr(s);
s = maple(s);
