No BSD License  

Highlights from
maple2matlab

from maple2matlab by Dirk Tenne
This replaces the "**n" to "^n" and glues the continuing lines together.

maple2matlab2(in,out)
function maple2matlab2(in,out)
% MAPLE2MATLAB: Converts Maple generated Fortran code into Matlab
% suitable format. 
% Converts:
%          **n   --> ^n
%           #    --> ...
%          alog  --> log
%
% Converting rules may be custumized in 'out = replace_gadgets(in)'
% at the end of the file. Please notify me for any additions! Thanks! 
%
% Usage: maple2matlab(input_file,output_file)         
%
% Dirk Tenne, 15th of May 2001
% tenne@eng.buffalo.edu

% TODO: linebreaks within variable names.

fid_in = fopen(in,'r');
fid_out = fopen(out,'w');


line2 = fgetl(fid_in);
while ~feof(fid_in)
   % reading phase
   line1 = line2;
   line2 = fgetl(fid_in);
   ind_co = findstr(line1,'%');
   ind_br = findstr(line2,'#');
   % writing phase
   if isempty(ind_co)
     if isempty(ind_br)
       output = [line1,';'];
     else
       output = line1;
       while ~isempty(ind_br)
	 output = [output, line2(ind_br(1)+1:end)];
	 line2 = fgetl(fid_in);
	 ind_br = findstr(line2,'#');
	 if isempty(ind_br)
	   output = [output,';'];
	 end
       end
     end
   else  % prints the comment
     output = ['%',line1(ind_co:end)];
   end
   output = replace_gadgets(output);
   fprintf(fid_out,[output,'\n']);
end
% last line gets cut off, workaround:
 output = [line2,';'];
 output = replace_gadgets(output);
 fprintf(fid_out,[output,'\n']);
 
fclose(fid_in);
fclose(fid_out);



function output_mod = replace_gadgets(output)
  
  % Replaces:   '**n' with '^n'.
  %             'alog' with 'log'
    
    output_mod = output;
    
    % Replacing "**n" with "^n":
    ind = findstr(output_mod,'**');
    while ~isempty(ind)
      output_mod(ind(1):ind(1)+1) = ['^',output_mod(ind(1)+2)];
      output_mod = [output_mod(1:ind(1)+1),output_mod(ind(1)+3: ...
						      end)];
      ind = findstr(output_mod,'**');
    end    

    
    % Replaceing "alog" to "log":
    ind = findstr(output_mod,'alog');
    while ~isempty(ind)
      output_mod(ind(1):ind(1)+2) = 'log';
      output_mod = [output_mod(1:ind(1)+2),output_mod(ind(1)+4: ...
						      end)];
      ind = findstr(output_mod,'alog');
    end    

    
    

Contact us at files@mathworks.com