/* autogenerated from "macros/Misc/MPBLOCK.sci" */ function MPBLOCK() { MPBLOCK.prototype.define = function MPBLOCK() { in1=["u"]; intype=["I"]; out=[["y1"],["y2"]]; outtype=[["I"],["I"]]; param=[]; paramv=list(); pprop=[]; nameF="myModel"; exprs=tlist(["MPBLOCK","in","intype","out","outtype","param","paramv","pprop","nameF","funtxt"],sci2exp(in1.slice()),sci2exp(intype.slice()),sci2exp(out.slice()),sci2exp(outtype.slice()),sci2exp(param.slice()),list(string(0.1),string(.0001)),sci2exp(pprop.slice()),nameF,[]); model=scicos_model(); model.blocktype="c"; model.dep_ut=[true,true]; model.rpar=[]; for (i=1;i<=lstsize(paramv);i+=1) { model.rpar=[[model.rpar],[paramv[i-1].slice()]]; } mo=modelica(); mo.model=nameF; mo.parameters=list(param,paramv); model.sim=list(mo.model,10004); mo.inputs=in1; mo.outputs=out; model.in1=ones(size(mo.inputs,"r"),1); model.out=ones(size(mo.outputs,"r"),1); model.equations=mo; gr_i=[]; x=standard_define([3,2],model,exprs,gr_i); x.graphics.in_implicit=intype; x.graphics.out_implicit=outtype; } MPBLOCK.prototype.details = function MPBLOCK() { } MPBLOCK.prototype.get = function MPBLOCK() { } MPBLOCK.prototype.set = function MPBLOCK() { x=arg1; model=arg1.model; graphics=arg1.graphics; exprs=graphics.exprs; if (type(exprs)==15) { paramv=list(); pprop=[]; for (i=1;i<=size(model.rpar,"*");i+=1) { paramv[$+1-1]=string(model.rpar(i)); pprop[$+1-1]=0; } exprs=tlist(["MPBLOCK","in","intype","out","outtype","param","paramv","pprop","nameF","funtxt"],exprs[1-1](1),exprs[1-1](2),exprs[1-1](3),exprs[1-1](4),exprs[1-1](5),paramv,sci2exp(pprop.slice()),exprs[1-1](7),exprs[2-1]); } lab_1=list(exprs.in1,exprs.intype,exprs.out,exprs.outtype,exprs.param,exprs.pprop,exprs.nameF); lab_2=exprs.paramv; while (true) { [ok,Tin,Tintype,Tout,Touttype,Tparam,pprop,Tfunam,lab_1]=getvalue("Set Modelica generic block parameters",[["Input variables: "],["Input variables types: "],["Output variables: "],["Output variables types:"],["Parameters in Modelica:"],["Parameters properties: "],["Model name in packages:"]],list("str",-1,"str",-1,"str",-1,"str",-1,"str",-1,"vec",-1,"str",-1),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"); if (ierr!=0) { x_message("Error in evaluation of variables."); ok=false; } if (ok) { for (i=1;i<=size(in1,"*");i+=1) { r=false; ierr=execstr("r=validvar(in(i))","errcatch"); if (!r) { ok=false; break; } } if (!ok) { x_message([["Invalid variable name for the input "+string(i)+"."],["\""+in1(i)+"\""],["Please choose another variable name."]]); } } if (ok) { for (i=1;i<=size(out,"*");i+=1) { r=false; ierr=execstr("r=validvar(out(i))","errcatch"); if (!r) { ok=false; break; } } if (!ok) { x_message([["Invalid variable name for the output "+string(i)+"."],["\""+out(i)+"\""],["Please choose another variable name."]]); } } if (ok) { param=param.slice(); for (i=1;i<=size(param,"*");i+=1) { r=false; ierr=execstr("r=validvar(param(i))","errcatch"); if (!r) { ok=false; break; } } if (!ok) { x_message([["Invalid variable name for the parameter "+string(i)+"."],["\""+param[i-1]+"\""],["Please choose another variable name."]]); } } if (ok) { for (i=1;i<=size(intype,"*");i+=1) { if (intype(i)!="E"&&intype(i)!="I") { x_message("Input type should be \'E\' or \'I\'!"); ok=false; break; } } } if (ok) { for (i=1;i<=size(outtype,"*");i+=1) { if (outtype(i)!="E"&&outtype(i)!="I") { x_message("Output type should be \'E\' or \'I\'!"); ok=false; break; } } } if (ok) { if (or(size(intype)!=size(in1))) { x_message("Input variables are not well defined!"); ok=false; } } if (ok) { if (or(size(outtype)!=size(out))) { x_message("Output variables are not well defined!"); ok=false; } } if (ok) { pprop=pprop.slice(); if ((size(param,"*")!=size(pprop,"*"))) { x_message([["There is differences in"],["size of param and size "],["of param properties."]]); ok=false; } } if (ok) { if (max(pprop)>2||min(pprop)<0) { x_message([["Parameters properties must be :"],["0 : if it is a paramaters"],["1 : if it is an initial value of state,"],["2 : it it is a fixed initial state value."]]); ok=false; } } if (ok) { if (funam=="") { x_message("The model name is not defined!"); ok=false; } } if (ok) { [dirF,nameF,extF]=fileparts(funam); if ((extF!="")||(dirF!="")) { x_message("Invalid model name!"); ok=false; } } if (ok) { intypex=find(intype=="I"); outtypex=find(outtype=="I"); [model,graphics,ok]=set_io(model,graphics,list([ones(in1),ones(in1)],ones(in1)),list([ones(out),ones(out)],ones(out)),[],[],intypex,outtypex); } if (ok) { Tparam_lab=evstr(Tparam); 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_sz0) { mo.parameters=list(transpose(param),paramv,transpose(pprop)); } else { mo.parameters=list(transpose(param),paramv); } } model.equations=mo; model.rpar=[]; for (i=1;i<=lstsize(paramv);i+=1) { model.rpar=[[model.rpar],[double(paramv[i-1].slice())]]; } model.sim[1-1]=funam; exprs.in1=lab_1(1); exprs.intype=lab_1(2); exprs.out=lab_1(3); exprs.outtype=lab_1(4); exprs.param=lab_1(5); exprs.paramv=list(); if (Tparam_sz!=0) { if (type(lab_2)==15) { for (i=1;i<=lstsize(lab_2);i+=1) { exprs.paramv[i-1]=lab_2[i-1]; } } else { for (i=1;i<=size(lab_2,"*");i+=1) { exprs.paramv[i-1]=lab_2[i-1]; } } } exprs.pprop=lab_1(6); exprs.nameF=lab_1(7); exprs.funtxt=""; x.model=model; graphics.gr_i[1-1][1-1]="txt=[\' "+nameF+" \'];"; graphics.in_implicit=intype; graphics.out_implicit=outtype; graphics.exprs=exprs; x.graphics=graphics; break; } } } }