1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2002-2004 - INRIA - Vincent COUVERT
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution. The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
function r=mtlb_eval(%s1,%s2)
// Emulation function for Matlab eval()
[lhs,rhs]=argn()
%prot=funcprot();
funcprot(0)
// Init all variables useful to launch mfile2sci()
deff("r=isanmfile(s)","r=%f");
res_path=[];
logfile=-1;
batch=%t;
fnam="%fun";
dquote="''";
lcount=1;
level=[0,0];
sciexp=0;
load("SCI/modules/m2sci/macros/kernel/lib");
sciparam();
// Scilab variable types
Double=1;
Boolean=4; // Boolean type can also be 6
Sparse=5;
Int=8;
Handle=9;
String=10;
Cell=17;
Struct=16;
Void=0;
Unknown=-1; // Unknown type or dimension
SupToOne=-2; // Dimension >1
NotNull=-3; // Dimension >0
Complex=1 //"Complex"
Real=0 //"Real"
Units=["pixels","centimeters","points","inches","normalized"]
margin=" "
verbose_mode = 0;
logfile=file("open",res_path+"m2sci_fun.log","unknown")
varslist=m2sci_init()
// Define a function which contains expression/instruction to eval and convert it
deff("%fun()",%s1)
mtlbtree=macr2tree(%fun);
[scitree,%txt]=mtlbtree2sci(mtlbtree,%T)
//%txt=tree2code(scitree)
%txt(find(part(%txt,1:2)=="//"))=[]
%txt(1)=[];
%txt($)=[];
%r=0
%nold=size(who("get"),"*")
%r=execstr(%txt,"errcatch")
if %r<>0&rhs==2 then
deff("%fun()",%s2)
mtlbtree=macr2tree(%fun);
[scitree,varslist]=mtlbtree2sci(mtlbtree,varslist)
%txt=tree2code(scitree)
%txt(find(part(%txt,1:2)=="//"))=[]
%txt(1)=[];
%txt($)=[];
disp(%txt)
%nold=size(who("get"),"*")
%r=execstr(%txt,"errcatch")
else
%nold=%nold+1
end
file("close", logfile);
nams=who("get");
if size(nams,"*")<=%nold then
r=0
return
end
nams=nams(1:$-%nold)
%r=funcprot(%prot);
if nams=="ans" then
r=ans
else
r=[];
execstr("["+strcat(nams,",")+"]"+"=resume"+"("+strcat(nams,",")+")")
end
endfunction
function [varslist]=m2sci_init()
varslist=list()
varslist($+1)=M2scivar("%i","i",Infer(list(1,1),Type(1,Complex)))
varslist($+1)=M2scivar("%i","j",Infer(list(1,1),Type(1,Complex)))
varslist($+1)=M2scivar("%nan","NaN",Infer(list(1,1),Type(1,Real)))
varslist($+1)=M2scivar("%nan","nan",Infer(list(1,1),Type(1,Real)))
varslist($+1)=M2scivar("%inf","Inf",Infer(list(1,1),Type(1,Real)))
varslist($+1)=M2scivar("%inf","inf",Infer(list(1,1),Type(1,Real)))
varslist($+1)=M2scivar("$","end",Infer(list(1,1),Type(1,Real)))
varslist($+1)=M2scivar("%pi","pi",Infer(list(1,1),Type(1,Real)))
varslist($+1)=M2scivar("%eps","eps",Infer(list(1,1),Type(1,Real)))
endfunction
|