#!/usr/bin/perl # # m2sci.pl is a simple program which will try to translate # matlab code to non-optimized scilab code. # Known weaknesses are: # # Torbjørn Pettersen October 2003. (Torbjorn.Pettersen@broadpark.no) # $Id: m2sci.pl,v 1.1 2003/10/11 20:39:02 top Exp top $ # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); $mon=$mon+1;$year=$year+1900; $TAG = "//---------------------------------------------------------------//\n"; $TAG = $TAG . "// Translated from @ARGV[0] using m2sci.pl at $hour:$min $mday/$mon/$year.\n"; $TAG = $TAG . "//---------------------------------------------------------------//\n\n\n"; $tmp=$_; $_=@ARGV[0]; if (/\/(\w*).m$/) { $outfile = $1 . ".sci"; } else { if (/(\w*).m$/) { $outfile = $1 . ".sci"; }} $_=$tmp; print "Reading from @ARGV[0]\n"; open(OUT,">$outfile") || die "m2sci.pl: Unable to create $outfile: $!\n"; print "\t Writing script to $outfile\n"; $NESTEFUNKSJON = 0; while (<>) { if ((/^\w*function/) & $NESTEFUNKSJON) { print OUT "endfunction\n" . $TAG; # add endfunction } else { $NESTEFUNKSJON = 1;}; unless (/\w*fprintf\w*/) { s/%/\/\//g; # Comments are replaced } s/nargout/argn(1)/g; # Outputarguments to function s/nargin/argn(2)/g; # Inputarguments to function s/isempty\((\w*)\)/($1==[])/g; s/\r$//g; # Replacing matlab functions with corresponding scilab commands. s/\bchar\b/ascii/; s/\bcompan\b/companion/g; s/\bfclose\b/mclose/g; s/\bfigure\b/xbasc/g; s/\bfopen\b/mopen/g; s/\breshape\b/matrix/g; print OUT; } print OUT "endfunction\n"; close(OUT); # steng siste outputfil.