1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) ???? - INRIA - Scilab
4 // Copyright (C) 2012 - 2016 - Scilab Enterprises
6 // This file is hereby licensed under the terms of the GNU GPL v2.0,
7 // pursuant to article 5.3.4 of the CeCILL v.2.1.
8 // This file was originally licensed under the terms of the CeCILL v2.1,
9 // and continues to be available under such terms.
10 // For more information, see the COPYING file which you should have received
11 // along with this program.
13 function sci_equiv = getvar2sci(var,lhslist)
14 // Translate the named variable acquisition
16 // Global variable for M2SCI
21 error(gettext("Wrong number of inputs."))
24 // Search variable name in variable name table
25 [boolval,index]=isdefinedvar(var)
28 // Variable is not defined yet
32 // If Matlab variable name is a function name in Scilab
33 if funptr(varname)<>0 then
37 // Undefined variable may be a M-file or a global variable
38 // Check if a corresponding M-file exists here
39 if isanmfile(varname) then
40 // A M-file without parameter
41 if verbose_mode<0 then
42 m2sci_info(msprintf(gettext("L.%d: Unknown variable %s is a M-file."),nblines,varname),-1);
44 sci_equiv=Funcall(varname,size(lhslist),list(),lhslist)
45 elseif exists("sci_"+varname)==1 then
46 // A translated function without parameter
47 if verbose_mode<0 then
48 m2sci_info(msprintf(gettext("L.%d: Unknown variable %s is a M-file (sci_%s exists)."),nblines,varname,varname),-1);
50 sci_equiv=Funcall(varname,size(lhslist),list(),lhslist)
51 elseif or(varname==["i","j"]) then
52 if verbose_mode<0 then
53 m2sci_info(msprintf(gettext("Variable %s supposed to be the Imaginary unit."),varname),-1);
55 sci_equiv=Variable("%i",Infer(list(1,1),Type(Double,Complex)))
57 // Try to find what is 'varname'
58 sci_equiv=get_unknown(varname,lhslist)
59 if verbose_mode<0 then
60 m2sci_info(msprintf(gettext("L.%d: Unknown variable %s."),nblines,varname),-1);
64 sci_equiv=Variable(varname,Infer(varslist(index).dims,varslist(index).type))
68 // -----------------------------------------------------------------------------
70 function sci_equiv = get_unknown(varname,lhslist)
71 // Private function called only within getvar2sci()
73 // Handle cases where varname appear in an expression while it is not known.
76 // - a variable created in another clause part
77 // - a M-file called without args
78 // - a variable created by an eval
82 // Check if it is a Matlab function not converted yet
83 if or(varname==not_yet_converted()) then
84 set_infos(msprintf(gettext("Matlab function %s not yet converted."),varname),2)
85 tmpvar=Variable(varname,Infer())
86 sci_equiv=Funcall("mtlb",1,Rhs_tlist(tmpvar),lhslist)
88 // Other cases: I am not able to determine what is nam
89 set_infos(msprintf(gettext("mtlb(%s) can be replaced by %s() or %s whether %s is an M-file or not."),varname,varname,varname,varname),1)
90 tmpvar=Variable(varname,Infer())
91 sci_equiv=Funcall("mtlb",1,Rhs_tlist(tmpvar),lhslist)