diff options
author | Sunil Shetye | 2018-07-11 13:05:13 +0530 |
---|---|---|
committer | Sunil Shetye | 2018-07-11 15:21:08 +0530 |
commit | 079d0b4a3ec15a4d7d2644484d116df9d1c694bb (patch) | |
tree | 785ed59b5b238203a9e91f3e323da59d1083d86e /js/Misc/MBLOCK.js | |
parent | 0e9bc36f45fa1bb598c6ebb0febc1989439a8d98 (diff) | |
download | sci2js-079d0b4a3ec15a4d7d2644484d116df9d1c694bb.tar.gz sci2js-079d0b4a3ec15a4d7d2644484d116df9d1c694bb.tar.bz2 sci2js-079d0b4a3ec15a4d7d2644484d116df9d1c694bb.zip |
fix assignment to list
Diffstat (limited to 'js/Misc/MBLOCK.js')
-rw-r--r-- | js/Misc/MBLOCK.js | 126 |
1 files changed, 67 insertions, 59 deletions
diff --git a/js/Misc/MBLOCK.js b/js/Misc/MBLOCK.js index c1aaa528..dde93d71 100644 --- a/js/Misc/MBLOCK.js +++ b/js/Misc/MBLOCK.js @@ -5,11 +5,11 @@ function MBLOCK() { this.intype = ["I"]; this.out = [["y1"],["y2"]]; this.outtype = [["I"],["E"]]; - param = [["R"],["L"]]; - paramv = list(0.1,.0001); + var param = [["R"],["L"]]; + var paramv = list(0.1,.0001); this.pprop = [[0],[0]]; - nameF = "generic"; - 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,[]); + var nameF = "generic"; + var 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 = [false,true]; @@ -17,7 +17,7 @@ function MBLOCK() { for (i=1;i<=lstsize(paramv);i+=1) { this.model.rpar = new ScilabDouble([this.model.rpar],[paramv[i-1].slice()]); } - mo = modelica(); + var mo = modelica(); mo.model = nameF; mo.parameters = list(param,paramv); this.model.sim = list(new ScilabString([mo.model]), new ScilabDouble([30004])); @@ -26,7 +26,7 @@ function MBLOCK() { this.model.in1 = new ScilabDouble([ones(size(mo.inputs,"r"),1)]); this.model.out = new ScilabDouble([ones(size(mo.outputs,"r"),1)]); this.model.equations = mo; - gr_i = []; + var gr_i = []; this.x = standard_define([3,2],this.model,exprs,gr_i); this.x.graphics.in_implicit = this.intype; this.x.graphics.out_implicit = this.outtype; @@ -58,35 +58,35 @@ function MBLOCK() { this.lab_1 = arguments[0]["lab_1"] this.x = arg1; this.model = arg1.model; - graphics = arg1.graphics; - exprs = graphics.exprs; + var graphics = arg1.graphics; + var exprs = graphics.exprs; if (this.type[exprs-1]==15) { - paramv = list(); + 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; } - exprs = tlist(["MBLOCK","in","intype","out","outtype","param","paramv","pprop","nameF","funtxt"],exprs[1-1][1-1],exprs[1-1][2-1],exprs[1-1][3-1],exprs[1-1][4-1],exprs[1-1][5-1],paramv,sci2exp(this.pprop.slice()),exprs[1-1][7-1],exprs[2-1]); + var exprs = tlist(["MBLOCK","in","intype","out","outtype","param","paramv","pprop","nameF","funtxt"],exprs[1-1][1-1],exprs[1-1][2-1],exprs[1-1][3-1],exprs[1-1][4-1],exprs[1-1][5-1],paramv,sci2exp(this.pprop.slice()),exprs[1-1][7-1],exprs[2-1]); } this.lab_1 = list(exprs.in1,exprs.intype,exprs.out,exprs.outtype,exprs.param,exprs.pprop,exprs.nameF); - lab_2 = exprs.paramv; + var lab_2 = 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; } - 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"); + 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"); - ok = false; + var ok = false; } if (ok) { for (i=1;i<=size(this.in1,"*");i+=1) { - r = false; - ierr = execstr("r=validvar(in(i))","errcatch"); + var r = false; + var ierr = execstr("r=validvar(in(i))","errcatch"); if (!r) { - ok = false; + var ok = false; break; } } @@ -96,10 +96,10 @@ function MBLOCK() { } if (ok) { for (i=1;i<=size(this.out,"*");i+=1) { - r = false; - ierr = execstr("r=validvar(out(i))","errcatch"); + var r = false; + var ierr = execstr("r=validvar(out(i))","errcatch"); if (!r) { - ok = false; + var ok = false; break; } } @@ -108,12 +108,12 @@ function MBLOCK() { } } if (ok) { - param = param.slice(); + var param = param.slice(); for (i=1;i<=size(param,"*");i+=1) { - r = false; - ierr = execstr("r=validvar(param(i))","errcatch"); + var r = false; + var ierr = execstr("r=validvar(param(i))","errcatch"); if (!r) { - ok = false; + var ok = false; break; } } @@ -125,7 +125,7 @@ function MBLOCK() { 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"); - ok = false; + var ok = false; break; } } @@ -134,7 +134,7 @@ function MBLOCK() { 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"); - ok = false; + var ok = false; break; } } @@ -142,110 +142,118 @@ function MBLOCK() { if (ok) { if (or(size(this.intype)!=size(this.in1))) { messagebox("Input variables are not well defined!","modal","error"); - ok = false; + var ok = false; } } if (ok) { if (or(size(this.outtype)!=size(this.out))) { messagebox("Output variables are not well defined!","modal","error"); - ok = false; + 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"); - ok = false; + 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"); - ok = false; + var ok = false; } } if (ok) { if (this.funam=="") { messagebox("The filename is not defined!","modal","error"); - ok = false; + var ok = false; } } if (ok) { - [dirF,nameF,extF] = fileparts(this.funam); + 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"); - ok = false; + var ok = false; } } if (ok) { - intypex = find(this.intype=="I"); - outtypex = find(this.outtype=="I"); - [this.model,graphics,ok] = set_io(this.model,graphics,list([ones(this.in1),ones(this.in1)],ones(this.in1)),list([ones(this.out),ones(this.out)],ones(this.out)),[],[],intypex,outtypex); + var intypex = find(this.intype=="I"); + var outtypex = find(this.outtype=="I"); + var tmpvar1 = set_io(this.model,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] + var graphics = tmpvar1[1] + var ok = tmpvar1[2]; } if (ok) { - Tparam_lab = evstr(this.Tparam); - Tparam_sz = size(Tparam_lab,"*"); + 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)) { - lab_2_tmp = list(); + 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]; } } - lab_2 = lab_2_tmp; + var lab_2 = lab_2_tmp; } if (Tparam_sz!=0) { - lhs_txt = ""; - lab_txt = ""; - rhs_txt = ""; + var lhs_txt = ""; + var lab_txt = ""; + var rhs_txt = ""; for (i=1;i<=Tparam_sz;i+=1) { - lhs_txt = lhs_txt+"%v"+string(i)+","; + var lhs_txt = lhs_txt+"%v"+string(i)+","; if (this.pprop[i-1]==0) { - lab_txt = lab_txt+"\'"+Tparam_lab[i-1]+"\';"; + var lab_txt = lab_txt+"\'"+Tparam_lab[i-1]+"\';"; } else if (this.pprop[i-1]==1) { - lab_txt = lab_txt+"\'"+Tparam_lab[i-1]+" (state) \';"; + var lab_txt = lab_txt+"\'"+Tparam_lab[i-1]+" (state) \';"; } else if (this.pprop[i-1]==2) { - lab_txt = lab_txt+"\'"+Tparam_lab[i-1]+" (fixed state) \';"; + var lab_txt = lab_txt+"\'"+Tparam_lab[i-1]+" (fixed state) \';"; } - rhs_txt = rhs_txt+"\'vec\',-1,"; + var rhs_txt = rhs_txt+"\'vec\',-1,"; } - lhs_txt = part(lhs_txt,1,length(lhs_txt)-1); - lab_txt = part(lab_txt,1,length(lab_txt)-1); - rhs_txt = part(rhs_txt,1,length(rhs_txt)-1); - getvalue_txt = "[ok,"+lhs_txt+",lab_2]=scicos_getvalue(\'Set parameters values\',["+lab_txt+"],"+"list("+rhs_txt+"),lab_2)"; + 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) { - lab_2 = exprs.paramv; + var lab_2 = exprs.paramv; } } } if (ok) { - paramv = list(); + 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)!=[]) { - tt = mgetl(this.funam); + var tt = mgetl(this.funam); } else { - tt = exprs.funtxt; - mo = this.model.equations; + var tt = exprs.funtxt; + var mo = this.model.equations; if (mo.model!=nameF) { - tt = []; + var tt = []; } } - [ok,tt] = MODCOM(this.funam,tt,this.in1,this.out,param,paramv,this.pprop); + 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) { - mo = modelica(); + var mo = modelica(); mo.model = nameF; mo.inputs = this.in1; mo.outputs = this.out; |