21 Language and data translation tools
21.1 ascii string ascii conversions
CALLING SEQUENCE :
a=ascii(txt)
txt=ascii(a)
PARAMETERS :
- txt
: character string.
- a
: vector of integer ascii codes
DESCRIPTION :
This function convert Scilab string to a vector of ascii code or
vector of ascii code to Scilab strings
See Also :
code2str
X, str2code
X
21.2 excel2sci reads ascii Excel files
CALLING SEQUENCE :
M=excel2sci(fname [,sep])
PARAMETERS :
- fname
: character string. The file path
- sep
: character string. Excel separator used, default value is ","
- M
: matrix of strings
DESCRIPTION :
Given an ascii file created by Excel using "Text and comma" format
exel2sci(fname) returns the corresponding Scilab matrix of
strings. Use exel2sci(fname,sep ) for an other choice of
separator.
Note: You may eval all or part ot M using function evstr.
See Also :
read
X, evstr
X
21.3 mfile2sci Matlab M_file to scilab translation function
CALLING SEQUENCE :
mfile2sci(M_file_path [,result_path [,Imode [,Recmode]]])
PARAMETERS :
- M_file_path
: a character string which gives the path of Matlab M_file to
translate
- result_path
: a character string which gives the directory where the result has to
be written. Default value is current directory.
- Imode
: Boolean flag, If true mfile2sci ask user for variable type and sizes
when he cannot infer them. Default value : %f
- Recmode
: Boolean flag, used by translatepaths function. Must be %f to
translate a single mfile.
DESCRIPTION :
mfile2sci, is Matlab M-file to Scilab function traduction tools. It
tries whenever possible to replace call to Matlab functions by the
equivalent scilab primitives and functions.
To translate a Matlab M-file just enter the scilab instruction:
mfile2sci(file)
where file is a character string giving the path name of the M-file
mfile2sci will generate three files in the same directory
<function_name>.sci : the scilab equivalent of the m_file
<function_name>.cat : the scilab help file associated to the function
sci_<function_name>.sci : the scilab function required to translate
the calls to this Matlab M_file in other Matlab M_files.
this function may be improved "by hand".
Some functions like eye, ones, size, sum,... behave differently
according to the dimension of their arguments. When mfile2sci cannot
infer dimensions it replaces these function call by a call to an
emulation function named mtlb_<function_name>. For efficiency these
functions may be replaced by the proper scilab equivalent instructions.
Some other functions like plot, has no straightforward translation in
scilab. They are also replaced by an emulation function named
mtlb_<function_name>.
When translation may be incorrect or may be improved mfile2sci adds a
comment which began by "//!"
REMARKS :
This function is a still under developpement and is delivered as beta
test.
Some Matlab4 basic functions are not yet translated. It is quite simple to
add it. See <SCIDIR>/macros/m2sci/README for more details.
KNOWN BUGS :
- 1-
: m_files scripts are translated but sci_<Matlab function name>
replaces the call to the m_file by an exec of
an exec (.sce) file, the .sce file path may be incorrect.
- 2-
: eval function instructions passed as strings are not translated.
- 3-
: most of plot function are not yet translated
- 4-
: globals are not translated
- 5-
: if, for, endded by the end of file produce an error, add the closing
end's
- 6-
: Loop variable of for clause is available afterwards if loops terminates
normally in matlab; it is cleared in Scilab generated code.
- 7-
: inequality comparison which implies complex numbers produce a run
time error such as "undefined variable : %s_2_s". User can define
these operation with Matlab meaning with the following function definition:
deff('r=%s_1_s(a,b)','r=real(a)<real(b)')
deff('r=%s_2_s(a,b)','r=real(a)>real(b)')
deff('r=%s_3_s(a,b)','r=real(a)<=real(b)')
deff('r=%s_4_s(a,b)','r=real(a)>=real(b)')
- 8-
: When i is a vector, Matlab allows insertions like a(i)=v for any
v. In scilab v must have the same shape as a(i). This produces run
time errors "submatrix incorrectly defined". Rewrite them as
a(i)=v.' .
EXAMPLE :
//create a simple m_file
write(TMPDIR+'rot90.m',['function B = rot90(A,k)'
'[m,n] = size(A);'
'if nargin == 1'
' k = 1;'
'else'
' k = rem(k,4);'
' if k < 0'
' k = k + 4;'
' end'
'end'
'if k == 1'
' A = A.'';'
' B = A(n:-1:1,:);'
'elseif k == 2'
' B = A(m:-1:1,n:-1:1);'
'elseif k == 3'
' B = A(m:-1:1,:);'
' B = B.'';'
'else'
' B = A;'
'end']);
// translate it dor scilab
mfile2sci(TMPDIR+'rot90.m',TMPDIR)
// show the new code
write(%io(2),read(TMPDIR+'rot90.sci',-1,1,'(a)'))
// get it into scilab
getf(TMPDIR+'rot90.sci')
//execute it
m=rand(4,2);rot90(m,1)
See Also :
translatepaths
X
Author :
Serge Steer, INRIA
21.4 mtlb_load load variables from file with matlab4 format.
CALLING SEQUENCE :
mtlb_load fname
mtlb_load xxx.yyy
mtlb_load fname -ascii
PARAMETERS :
- fname
: a file name
- xxx.yyy
: a file name with extension
DESCRIPTION :
mtlb_load load variables on file with matlab4 formats.
- mtlb_load fname
loads in scilab all variables stored in
file binary fname.mat .
- mtlb_load fname -ascii
loads in scilab variable stored in ascii file fname,
which must contain a
rectangular array of numeric data, arranged in m lines with n values
in each line. The result is an m-by-n matrix named fname .
- mtlb_load xxx.yyy
reads the ascii file xxx.yyy, which must contain a
rectangular array of numeric data, arranged in m lines with n values
in each line. The result is an m-by-n matrix named xxx.
- "stdio" value for fname doesnt redirect load from standard input.
See Also :
mtlb_save
X, save
X, load
X
21.5 mtlb_save save variables on file with matlab4 format.
CALLING SEQUENCE :
mtlb_save fname
mtlb_save fname X
mtlb_save fname X Y Z
mtlb_save fname X Y Z -ascii
mtlb_save fname X Y Z -ascii -double
mtlb_save fname X Y Z -ascii -double -tabs
PARAMETERS :
- fname
: a file name
- X Y Z
: variable names
DESCRIPTION :
mtlb_save save variables on file with matlab4 formats.
- mtlb_save fname saves all the current scilab variables which
have corresponding matlab type to the binary "MAT-file" named
fname.mat. The data may be retrieved with mtlb_load.
- mtlb_save fname X
saves only variable X.
- mtlb_save fname X Y Z
saves variables X, Y, and Z.
- mtlb_save fname X Y Z -ascii
uses 8-digit ASCII form instead
of binary.
- mtlb_save fname X Y Z -ascii -double
uses 16-digit ASCII form.
- mtlb_save fname X Y Z -ascii -double -tabs
delimits with tabs.
- "stdio" value for fname doesnt redirect save to standard output.
See Also :
mtlb_load
X, save
X, load
X
21.6 pol2tex convert polynomial to TeX format
CALLING SEQUENCE :
[y]=pol2tex(x)
PARAMETERS :
DESCRIPTION :
Latex source code for the polynomial x.
(For use with texprint)
EXAMPLE :
s=poly(0,'s');
p=s^3+2*s-5;
pol2tex(p)
See Also :
texprint
X
21.7 sci2for scilab function to Fortran routine conversion
CALLING SEQUENCE :
txt=sci2for(fun,nam,vtps)
PARAMETERS :
- fun
: Scilab function
- nam
: character string, the name of generated subroutine
- vtps
: list
- txt
: string, text of the subroutine Fortran code
DESCRIPTION :
The elements of the list vtps give the type and dimensions
of variables of the calling sequence :
vtps(i)=list(typ,row_dim,col_dim)
where :
1
- typ
: is a character string giving the type of the variable :
2
- "0"
: constant,integer vector or matrix
- "1"
: constant,double precision vector or matrix
- "10"
: character string
1
- row_dim
: character string (row dimension)
- col_dim
: character string (column dimension)
0
- txt
: Fortran code
Generated code may use routines of scilab libraries and some others
whose source code may be found in <SCIDIR>/util/sci2for.f
REMARKS :
This function is just a try. Only simple function may be
translated. Many function calls have not yet Fortran equivalent, to add the
translation of a new function call you may define a scilab function.
whose name is f_<name of function>. see
<SCIDIR>/macros/sci2for/f_*.sci files for examples.
The following keywords :
work,iwork,ierr
iw* iiw*
ilbN (N integer)
may not appear in the function code.
See Also :
function
X
21.8 texprint TeX output of Scilab object
CALLING SEQUENCE :
[text]= texprint(a)
PARAMETERS :
- a
: Scilab object
- text
: list
DESCRIPTION :
returns the Tex source code of the Scilab variable a.
a is a matrix (constant, polynomial, rational) or a linear system
(syslin list).
EXAMPLE :
s=poly(0,'s');
texprint([1/s,s^2])
See Also :
pol2tex
X, pol2str
X
21.9 translatepaths translate a set of Matlab M_file directories to scilab
CALLING SEQUENCE :
translatepaths(dirs_path [,res_path])
PARAMETERS :
- dir_path
: a character string vector which gives the paths of Matlab M_file
directories to translate
- res_path
: a character string which gives the path of the
directory where the scilab functions are written to.
DESCRIPTION :
translatepaths, translate all Matlab M-file contained in a set of directories to
Scilab functions. Each function is translated by mfile2sci.
See Also :
mfile2sci
X
Author :
Serge Steer, INRIA