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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
|
/* autogenerated from "macros/Misc/MBLOCK.sci" */
function MBLOCK() {
MBLOCK.prototype.define = function MBLOCK() {
this.in1 = ["u1"];
this.intype = ["I"];
this.out = [["y1"],["y2"]];
this.outtype = [["I"],["E"]];
var param = [["R"],["L"]];
var paramv = list(0.1,.0001);
this.pprop = [[0],[0]];
var nameF = "generic";
this.exprs = tlist(["MBLOCK","in","intype","out","outtype","param","paramv","pprop","nameF","funtxt"],sci2exp(this.in1.slice()),sci2exp(this.intype.slice()),sci2exp(this.out.slice()),sci2exp(this.outtype.slice()),sci2exp(param.slice()),list(string(0.1),string(.0001)),sci2exp(this.pprop.slice()),nameF,[]);
this.model = scicos_model();
this.model.blocktype = new ScilabString(["c"]);
this.model.dep_ut = new ScilabBoolean([false,true]);
this.model.rpar = new ScilabDouble([]);
for (i=1;i<=lstsize(paramv);i+=1) {
this.model.rpar = new ScilabDouble([this.model.rpar],[paramv[i-1].slice()]);
}
var mo = modelica();
mo.model = nameF;
mo.parameters = list(param,paramv);
this.model.sim = list(new ScilabString([mo.model]), new ScilabDouble([30004]));
mo.inputs = this.in1;
mo.outputs = this.out;
this.model.in = new ScilabDouble([ones(size(mo.inputs,"r"),1)]);
this.model.out = new ScilabDouble([ones(size(mo.outputs,"r"),1)]);
this.model.equations = mo;
this.gr_i = new ScilabString(["xstringb(orig(1),orig(2),\"MBLOCK\",sz(1),sz(2));"]);
this.x = new standard_define(new ScilabDouble([3,2]),this.model,this.exprs,this.gr_i);
this.x.graphics.in_implicit = this.intype;
this.x.graphics.out_implicit = this.outtype;
return new BasicBlock(this.x);
}
MBLOCK.prototype.details = function MBLOCK() {
return this.x;
}
MBLOCK.prototype.get = function MBLOCK() {
var options = {
Tin:["Input variables: ",this.Tin],
Tintype:["Input variables types: ",this.Tintype],
Tout:["Output variables: ",this.Tout],
Touttype:["Output variables types:",this.Touttype],
Tparam:["Parameters in Modelica:",this.Tparam],
pprop:["Parameters properties: ",this.pprop],
Tfunam:["Function name: ",this.Tfunam],
}
return options;
}
MBLOCK.prototype.set = function MBLOCK() {
this.Tin = arguments[0]["Tin"]
this.Tintype = arguments[0]["Tintype"]
this.Tout = arguments[0]["Tout"]
this.Touttype = arguments[0]["Touttype"]
this.Tparam = arguments[0]["Tparam"]
this.pprop = inverse(arguments[0]["pprop"])
this.Tfunam = arguments[0]["Tfunam"]
this.lab_1 = arguments[0]["lab_1"]
this.exprs = this.graphics.exprs;
if (this.type[this.exprs-1]==15) {
var paramv = list();
this.pprop = [];
for (i=1;i<=size(this.model.rpar,"*");i+=1) {
paramv[$+1-1] = string(this.model.rpar[i-1]);
this.pprop[$+1-1] = 0;
}
this.exprs = tlist(["MBLOCK","in","intype","out","outtype","param","paramv","pprop","nameF","funtxt"],this.exprs[1-1][1-1],this.exprs[1-1][2-1],this.exprs[1-1][3-1],this.exprs[1-1][4-1],this.exprs[1-1][5-1],paramv,sci2exp(this.pprop.slice()),this.exprs[1-1][7-1],this.exprs[2-1]);
}
this.lab_1 = list(this.exprs.in,this.exprs.intype,this.exprs.out,this.exprs.outtype,this.exprs.param,this.exprs.pprop,this.exprs.nameF);
var lab_2 = this.exprs.paramv;
while (true) {
[ok,this.Tin,this.Tintype,this.Tout,this.Touttype,this.Tparam,this.pprop,this.Tfunam,this.lab_1] = scicos_getvalue("Set Modelica generic block parameters",["Input variables: ","Input variables types: ","Output variables: ","Output variables types:","Parameters in Modelica:","Parameters properties: ","Function name: "],list("str",-1,"str",-1,"str",-1,"str",-1,"str",-1,"vec",-1,"str",-1),this.lab_1);
if (!ok) {
break;
}
var ierr = execstr("in=stripblanks(evstr(Tin)); intype=stripblanks(evstr(Tintype)); out=stripblanks(evstr(Tout)); outtype=stripblanks(evstr(Touttype)); param=stripblanks(evstr(Tparam)); funam=stripblanks(Tfunam)","errcatch");
if (ierr!=0) {
messagebox("Error in evaluation of variables.","modal","error");
var ok = false;
}
if (ok) {
for (i=1;i<=size(this.in1,"*");i+=1) {
var r = false;
var ierr = execstr("r=validvar(in(i))","errcatch");
if (!r) {
var ok = false;
break;
}
}
if (!ok) {
messagebox([["Invalid variable name for the input "+string(i)+"."],["\""+this.in1[i-1]+"\""],["Please choose another variable name."]],"modal","error");
}
}
if (ok) {
for (i=1;i<=size(this.out,"*");i+=1) {
var r = false;
var ierr = execstr("r=validvar(out(i))","errcatch");
if (!r) {
var ok = false;
break;
}
}
if (!ok) {
messagebox([["Invalid variable name for the output "+string(i)+"."],["\""+this.out[i-1]+"\""],["Please choose another variable name."]],"modal","error");
}
}
if (ok) {
var param = param.slice();
for (i=1;i<=size(param,"*");i+=1) {
var r = false;
var ierr = execstr("r=validvar(param(i))","errcatch");
if (!r) {
var ok = false;
break;
}
}
if (!ok) {
messagebox([["Invalid variable name for the parameter "+string(i)+"."],["\""+param[i-1]+"\""],["Please choose another variable name."]],"modal","error");
}
}
if (ok) {
for (i=1;i<=size(this.intype,"*");i+=1) {
if (this.intype[i-1]!="E"&&this.intype[i-1]!="I") {
messagebox("Input type should be \'E\' or \'I\'!","modal","error");
var ok = false;
break;
}
}
}
if (ok) {
for (i=1;i<=size(this.outtype,"*");i+=1) {
if (this.outtype[i-1]!="E"&&this.outtype[i-1]!="I") {
messagebox("Output type should be \'E\' or \'I\'!","modal","error");
var ok = false;
break;
}
}
}
if (ok) {
if (or(size(this.intype)!=size(this.in1))) {
messagebox("Input variables are not well defined!","modal","error");
var ok = false;
}
}
if (ok) {
if (or(size(this.outtype)!=size(this.out))) {
messagebox("Output variables are not well defined!","modal","error");
var ok = false;
}
}
if (ok) {
this.pprop = this.pprop.slice();
if ((size(param,"*")!=size(this.pprop,"*"))) {
messagebox([["There is differences in"],["size of param and size "],["of param properties."]],"modal","error");
var ok = false;
}
}
if (ok) {
if (max(this.pprop)>2||min(this.pprop)<0) {
messagebox([["Parameters properties must be :"],["0 : for simple paramater,"],["1 : for initial state value,"],["2 : for a fixed initial state value."]],"modal","error");
var ok = false;
}
}
if (ok) {
if (this.funam=="") {
messagebox("The filename is not defined!","modal","error");
var ok = false;
}
}
if (ok) {
var tmpvar0 = fileparts(this.funam);
var dirF = tmpvar0[0];
var nameF = tmpvar0[1];
var extF = tmpvar0[2];
if ((extF!=""&&extF!=".mo")||(dirF!=""&&extF!=".mo")) {
messagebox("Filename extention should be \'.mo \' !","modal","error");
var ok = false;
}
}
if (ok) {
var intypex = find(this.intype=="I");
var outtypex = find(this.outtype=="I");
var tmpvar1 = set_io(this.model,this.graphics,list([ones(this.in1),ones(this.in1)],ones(this.in1)),list([ones(this.out),ones(this.out)],ones(this.out)),[],[],intypex,outtypex);
this.model = tmpvar1[0];
this.graphics = tmpvar1[1];
var ok = tmpvar1[2];
}
if (ok) {
var Tparam_lab = evstr(this.Tparam);
var Tparam_sz = size(Tparam_lab,"*");
if (Tparam_sz>lstsize(lab_2)) {
for (i=1;i<=(Tparam_sz-lstsize(lab_2));i+=1) {
lab_2[$+1-1] = "0";
}
} else if (Tparam_sz<lstsize(lab_2)) {
var lab_2_tmp = list();
if (Tparam_sz!=0) {
for (i=1;i<=(lstsize(lab_2)-Tparam_sz);i+=1) {
lab_2_tmp[i-1] = lab_2[i-1];
}
}
var lab_2 = lab_2_tmp;
}
if (Tparam_sz!=0) {
var lhs_txt = "";
var lab_txt = "";
var rhs_txt = "";
for (i=1;i<=Tparam_sz;i+=1) {
var lhs_txt = lhs_txt+"%v"+string(i)+",";
if (this.pprop[i-1]==0) {
var lab_txt = lab_txt+"\'"+Tparam_lab[i-1]+"\';";
} else if (this.pprop[i-1]==1) {
var lab_txt = lab_txt+"\'"+Tparam_lab[i-1]+" (state) \';";
} else if (this.pprop[i-1]==2) {
var lab_txt = lab_txt+"\'"+Tparam_lab[i-1]+" (fixed state) \';";
}
var rhs_txt = rhs_txt+"\'vec\',-1,";
}
var lhs_txt = part(lhs_txt,1,length(lhs_txt)-1);
var lab_txt = part(lab_txt,1,length(lab_txt)-1);
var rhs_txt = part(rhs_txt,1,length(rhs_txt)-1);
var getvalue_txt = "[ok,"+lhs_txt+",lab_2]=scicos_getvalue(\'Set parameters values\',["+lab_txt+"],"+"list("+rhs_txt+"),lab_2)";
execstr(getvalue_txt);
if (!ok) {
var lab_2 = this.exprs.paramv;
}
}
}
if (ok) {
var paramv = list();
for (i=1;i<=Tparam_sz;i+=1) {
execstr("paramv("+string(i)+")=%v"+string(i));
}
}
if (ok) {
if (extF==".mo"&&fileinfo(this.funam)!=[]) {
var tt = mgetl(this.funam);
} else {
var tt = this.exprs.funtxt;
var mo = this.model.equations;
if (mo.model!=nameF) {
var tt = [];
}
}
var tmpvar2 = MODCOM(this.funam,tt,this.in1,this.out,param,paramv,this.pprop);
var ok = tmpvar2[0];
var tt = tmpvar2[1];
if (!ok) {
break;
}
}
if (ok) {
var mo = modelica();
mo.model = nameF;
mo.inputs = this.in1;
mo.outputs = this.out;
if (max(this.pprop)>0) {
mo.parameters = list(transpose(param),paramv,transpose(this.pprop));
} else {
mo.parameters = list(transpose(param),paramv);
}
this.model.equations = new ScilabDouble([mo]);
this.model.rpar = new ScilabDouble([]);
for (i=1;i<=lstsize(paramv);i+=1) {
this.model.rpar = new ScilabDouble([this.model.rpar],[paramv[i-1].slice()]);
}
this.model.sim[1-1] = new ScilabDouble([this.funam]);
this.exprs.in = this.lab_1[1-1];
this.exprs.intype = this.lab_1[2-1];
this.exprs.out = this.lab_1[3-1];
this.exprs.outtype = this.lab_1[4-1];
this.exprs.param = this.lab_1[5-1];
this.exprs.paramv = list();
if (Tparam_sz!=0) {
if (this.type[lab_2-1]==15) {
for (i=1;i<=lstsize(lab_2);i+=1) {
this.exprs.paramv[i-1] = lab_2[i-1];
}
} else {
for (i=1;i<=size(lab_2,"*");i+=1) {
this.exprs.paramv[i-1] = lab_2[i-1];
}
}
}
this.exprs.pprop = this.lab_1[6-1];
this.exprs.nameF = this.lab_1[7-1];
this.exprs.funtxt = tt;
this.x.model = this.model;
this.graphics.gr_i[1-1][1-1] = new ScilabString(["txt=[\'Modelica\';\' "+nameF+" \'];"]);
this.graphics.in_implicit = new ScilabString(this.intype);
this.graphics.out_implicit = new ScilabDouble(this.outtype);
this.graphics.exprs = this.exprs;
this.x.graphics = this.graphics;
break;
}
}
return new BasicBlock(this.x);
}
}
|