diff options
Diffstat (limited to 'macros/Misc')
40 files changed, 5200 insertions, 0 deletions
diff --git a/macros/Misc/AUTOMAT.sci b/macros/Misc/AUTOMAT.sci new file mode 100644 index 00000000..6ef82717 --- /dev/null +++ b/macros/Misc/AUTOMAT.sci @@ -0,0 +1,166 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=AUTOMAT(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + ipar=model.ipar; + NMode=ipar(1) + NX=ipar(3) + while %t do + CX="C1"; + MSG0="''Jump from Mode "; + MSG2=":[..;M_final(Guard=In("; + MSG3=").i);..]''" + MSG=MSG0+"1"+MSG2+"1"+MSG3; + VEC="''mat'',[-1,1]"; + for i=2:NMode + CX=CX+","+"C"+string(i); + MSG=MSG+";"+MSG0+string(i)+MSG2+string(i)+MSG3; + VEC=VEC+","+"''mat'',[-1,1]"; + end + //=========================================== + GTV="[ok,NMode,Minitial,NX,X0,XP,"+CX+",exprs]=scicos_getvalue(''Set Finite state machine model'',.. + [''Number (finite-state) Modes'';''Initial Mode'';''Number of continuous-time states'';''Continuous-time states intial values'';''Xproperties of continuous-time states in each Mode'';"+MSG+"],.. + list(''vec'',1,''vec'',1,''vec'',1,''mat'',[-1,-1],''mat'',[-1,-1],"+VEC+"),exprs)" + execstr(GTV); + if ~ok then + break, + end + NMode_old=size(exprs,"*")-5;//-number of fileds before CX + ModifEncore=%f; + + if (NMode_old>NMode) then + exprs(NMode+6:NMode_old+5)=[];// number of fileds + ModifEncore=%t; + end + if (NMode_old<NMode) then + exprs(NMode_old+6:NMode+5)=exprs(NMode_old+4);// number of fileds + ModifEncore=%t; + end + if (NX<>size(X0,"*")) then + messagebox("the size of intial continuous-time states should be NX="+string(NX),"modal","error"); + ModifEncore=%t; + end + + [rXP,cXP]=size(XP) + if cXP<>NX then + messagebox("Xproperty matrix is not valid: it should have NX="+string(NX)+" columns","modal","error"); + ModifEncore=%t; + elseif ((rXP<>NMode) & (rXP>1)) + messagebox("Xproperty matrix is not valid: it should have NMode="+string(NMode)+" or 1 row(s)","modal","error"); + ModifEncore=%t; + elseif (rXP==1) + for i=1:NMode-1 + XP=[XP;XP(1,:)];// xproprties are identical in modes. + end + end + + if (NMode_old==NMode)&(~ModifEncore) then + XP=matrix(XP',NMode*NX,1);// put XP in column vector to be stocked in ipar + ipar=[NMode;Minitial;NX;XP]; + rpar=matrix(X0,NX,1);// put X0 in a column vector; + INP=ones(NMode,1); + if NX>0 then + OUT=[2;2*NX]; + else + OUT=[2]; + end + MaxModes=1; + nzcross=0; + for i=1:NMode + Ci=evstr(exprs(5+i));// number of fileds + ipar=[ipar;Ci]; + INP(i,1)=2*NX+length(Ci); + if (nzcross<length(Ci)) then + nzcross=length(Ci); + end + if (MaxModes<max(Ci)) then + MaxModes=max(Ci); + imax=i; + end + end + + if MaxModes>NMode then + messagebox(["Number of Modes should be "+string(MaxModes);.. + "A destination Mode in Mode#"+string(imax)+"''s targets is invalid!"],"modal","error"); + ModifEncore=%t; + end + if MaxModes<NMode then + messagebox(["There is an unused Mode or the Number of Modes should be "+string(MaxModes)],"modal","error"); + ModifEncore=%t; + end + end + if ~ModifEncore then + [model,graphics,ok]=check_io(model,graphics,INP,OUT,[],[1]) + if ~ok then + break, + end + model.nzcross=nzcross; + model.state=ones(2*NX,1); + graphics.gr_i(1)(1)="txt=[''Automaton'';''nM="+string(NMode)+",nX="+string(NX)+"''];" + graphics.exprs=exprs; + x.graphics=graphics; + model.ipar=ipar; + model.rpar=rpar; + x.model=model; + break + end + end;//while + //----------------------------------------------- + case "define" then + NMode=2; //number of Modes + Minitial=1; //initial Mode + NX=1; //number of states (NX is identical for all Modes) + X0=[0.0] + XP=[1;1]//xproperties for each Mode + C1=[2];//final_Mode after Jump du to in(2*Nx+i) + C2=[1]; + exprs=[string(NMode);string(Minitial);string(NX);sci2exp(X0);sci2exp(XP);sci2exp(C1);sci2exp(C2)]; + ipar=[NMode;Minitial;NX;XP;C1;C2]; + rpar=[X0]; + + model=scicos_model() + model.sim=list("automat",10004) + model.in=[2*NX+1;2*NX+1];//number of Modes + model.out=[2;2*NX];// [Mode;(x,xd)] + model.state=ones(2*NX,1);// [x;xd] + model.nzcross=1;// max(taille_zc(Mode_i)) + model.blocktype="c"; + model.evtout=1 + model.firing=-1; + model.dep_ut=[%f %t]; + model.ipar=ipar; + model.rpar=rpar; + + gr_i=[] + + x=standard_define([4 2],model,exprs,gr_i); + end +endfunction + diff --git a/macros/Misc/BACKLASH.sci b/macros/Misc/BACKLASH.sci new file mode 100644 index 00000000..9460d57f --- /dev/null +++ b/macros/Misc/BACKLASH.sci @@ -0,0 +1,73 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=BACKLASH(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + rpar=model.rpar + while %t do + [ok,ini,gap,zcr,exprs]=scicos_getvalue("Set backlash parameters",.. + ["initial output"; + "gap";"use zero-crossing (0:no, 1:yes)"],.. + list("vec",1,"vec",1,"vec",1),exprs) + + + if ~ok then + break, + end + if ok then + graphics.exprs=exprs; + rpar(1)=ini; + rpar(2)=gap; + if zcr<>0 then + model.nzcross=2 + else + model.nzcross=0 + end + model.rpar=rpar + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + exprs=["0";"1";"1"] + model=scicos_model() + model.sim=list("backlash",4) + model.in=1 + model.out=1 + model.rpar=[0;1] + model.nzcross=2; + model.blocktype="c" + model.dep_ut=[%t %f] + + gr_i=[] + + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Misc/BOUNCE.sci b/macros/Misc/BOUNCE.sci new file mode 100644 index 00000000..a8ffb2d5 --- /dev/null +++ b/macros/Misc/BOUNCE.sci @@ -0,0 +1,130 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=BOUNCE(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + if size(exprs,"*")<9 then + exprs(8)="9.81"; + exprs(9)="0"; + end + while %t do + [ok,rpar1,rpar2,walls,xt,xd,y,yd,g,C,exprs]=scicos_getvalue(["Set Bounce Block"],.. + ["Mass";"Radius";"[xmin,xmax,ymin,ymax]";"xpos";"xdpos";"ypos";.. + "ydpos";"g (gravity)";"C (aerodynamic coeff"],.. + list("vec",-1,"vec",-1,"vec",-1,"vec",-1,"vec",-1,.. + "vec",-1,"vec",-1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end + xt=xt(:); + y=y(:); + xd=xd(:); + yd=yd(:); + rpar1=rpar1(:); + rpar2=rpar2(:); + n=size(xt,"*"); + walls=walls(:); + if walls(1)>walls(2) then + walls=walls([2,1]); + end + if walls(3)>walls(3) then + walls=walls([3,4]); + end + if n<>size(y,"*")|n<>size(rpar1,"*")|n<>size(rpar2,"*")|.. + n<>size(xd,"*")|n<>size(yd,"*") then + message("All vectors must have equal size") + ok=%f + elseif ~(min([rpar1;rpar2])>0) then + message("Mass and radius must be >0") + ok=%f + end + if ~ok then + break, + end + [model,graphics,ok]=check_io(model,graphics,[],[n,n],[],[]) + if ok then + k=1;ipar=[]; + for i=1:n + for j=i+1:n + ipar(k)=i + k=k+1 + ipar(k)=j + k=k+1 + end + end + model.rpar=[rpar1;rpar2;walls;g;C]; + model.ipar=ipar; + state=[xt,xd,y,yd]; + state=state'; + model.state=state(:) + model.nzcross=n*(n-1)/2+4*n; + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + n=2 + k=1;ipar=[]; + for i=1:n + for j=i+1:n + ipar(k)=i + k=k+1 + ipar(k)=j + k=k+1 + end + end + walls=[0;5;0;5] + x=[2;2.5]; + xd=[0;0]; + y=[3;5]; + yd=[0;0]; + g=9.81; + C=0 + rpar1=ones(n,1); + rpar2=rpar1; + state=[x,xd,y,yd]; + state=state'; + model=scicos_model() + model.sim=list("bounce_ball",4) + model.in=[] + model.out=[n;n] + model.state=state(:) + model.rpar=[rpar1;rpar2;walls;g;C]; + model.ipar=ipar; + model.nzcross=n*(n-1)/2+4*n; + model.blocktype="c" + model.dep_ut=[%f %t] + + exprs=[strcat(sci2exp(rpar1));strcat(sci2exp(rpar2));strcat(sci2exp(walls));strcat(sci2exp(x));strcat(sci2exp(xd));strcat(sci2exp(y));strcat(sci2exp(yd))] + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Misc/BOUNCEXY.sci b/macros/Misc/BOUNCEXY.sci new file mode 100644 index 00000000..50e79eea --- /dev/null +++ b/macros/Misc/BOUNCEXY.sci @@ -0,0 +1,132 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=BOUNCEXY(job,arg1,arg2) + //Scicos 2D animated visualization block + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + dstate=model.dstate + while %t do + [ok,clrs,siz,win,imode,xmin,xmax,ymin,ymax,exprs]=scicos_getvalue(.. + "Set Scope parameters",.. + ["colors"; + "radii"; + "window number (-1 for automatic)"; + "animation mode (0,1)"; + "Xmin"; + "Xmax"; + "Ymin"; + "Ymax"; + ],.. + list("vec",-1,"vec",-1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end //user cancel modification + + mess=[] + if size(clrs,"*")<>size(siz,"*") then + mess=[mess;"colors and radii must have equal size (number of balls)";" "] + ok=%f + end + if win<-1 then + mess=[mess;"Window number cannot be inferior than -1";" "] + ok=%f + end + if ymin>=ymax then + mess=[mess;"Ymax must be greater than Ymin";" "] + ok=%f + end + if xmin>=xmax then + mess=[mess;"Xmax must be greater than Xmin";" "] + ok=%f + end + if ~ok then + message(mess) + else + rpar=[xmin;xmax;ymin;ymax] + ipar=[win;imode;clrs(:)] + z=[] + for i=1:size(clrs,"*") + z(6*(i-1)+1)=0 + z(6*(i-1)+2)=0 + z(6*(i-1)+3)=2*siz(i) + z(6*(i-1)+4)=2*siz(i) + z(6*(i-1)+5)=0.000 + z(6*(i-1)+6)=64.0*360.000; + end + model.dstate=z; + model.rpar=rpar;model.ipar=ipar + graphics.exprs=exprs; + x.graphics=graphics;x.model=model + break + end + end + case "define" then + win=-1; + imode=1; + clrs=[1;2]; + siz=[1;1] + xmin=-5; + xmax=5; + ymin=0; + ymax=15 + + model=scicos_model() + model.sim=list("bouncexy",4) + model.in=[-1;-1] + model.in2=[1;1] + model.intyp = [1;1] + model.evtin=1 + z=[] + for i=1:size(clrs,"*") + z(6*(i-1)+1)=0 + z(6*(i-1)+2)=0 + z(6*(i-1)+3)=2*siz(i) + z(6*(i-1)+4)=2*siz(i) + z(6*(i-1)+5)=0.000 + z(6*(i-1)+6)=64.0*360.000; + end + model.dstate=z + model.rpar=[xmin;xmax;ymin;ymax] + model.ipar=[win;imode;clrs(:)] + model.blocktype="d" + model.firing=[] + model.dep_ut=[%f %f] + + exprs=[strcat(sci2exp(clrs)); + strcat(sci2exp(siz)); + strcat(sci2exp(win)); + strcat(sci2exp(1)); + strcat(sci2exp(xmin)); + strcat(sci2exp(xmax)); + strcat(sci2exp(ymin)); + strcat(sci2exp(ymax))] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Misc/BPLATFORM.sci b/macros/Misc/BPLATFORM.sci new file mode 100644 index 00000000..bc753479 --- /dev/null +++ b/macros/Misc/BPLATFORM.sci @@ -0,0 +1,89 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=BPLATFORM(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + dstate=model.dstate + while %t do + [ok,plen,csiz,phi,xmin,xmax,ymin,ymax,exprs]=scicos_getvalue(.. + "Set Scope parameters",.. + ["pendulum length";"cart size (square side)";"slope"; + "Xmin";"Xmax"; "Ymin"; "Ymax"; ],.. + list("vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end + mess=[] + if plen<=0|csiz<=0 then + mess=[mess;"Pendulum length and cart size must be positive.";" "] + ok=%f + end + if ymin>=ymax then + mess=[mess;"Ymax must be greater than Ymin";" "] + ok=%f + end + if xmin>=xmax then + mess=[mess;"Xmax must be greater than Xmin";" "] + ok=%f + end + if ~ok then + message(mess) + else + rpar=[plen;csiz;phi;xmin;xmax;ymin;ymax] + model.rpar=rpar; + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + plen=2; + csiz=2; + phi=0; + xmin=-5; + xmax=5; + ymin=0; + ymax=15 + + model=scicos_model() + model.sim=list("bplatform2",5) + model.in=[1;1] + model.evtin=1 + model.dstate=0 + model.rpar=[plen;csiz;phi;xmin;xmax;ymin;ymax] + model.blocktype="d" + model.dep_ut=[%f %f] + + exprs=string(model.rpar) + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction + diff --git a/macros/Misc/CBLOCK.sci b/macros/Misc/CBLOCK.sci new file mode 100644 index 00000000..7cd31e65 --- /dev/null +++ b/macros/Misc/CBLOCK.sci @@ -0,0 +1,180 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=CBLOCK(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + model=arg1.model; + graphics=arg1.graphics; + label=graphics.exprs; + while %t do + [ok,function_name,impli,i,o,ci,co,xx,ng,z,rpar,ipar,auto0,depu,dept,lab]=.. + scicos_getvalue("Set C-Block2 block parameters",.. + ["simulation function"; + "is block implicit? (y,n)"; + "input ports sizes"; + "output ports sizes"; + "input event ports sizes"; + "output events ports sizes"; + "initial continuous state"; + "number of zero crossing surfaces"; + "initial discrete state"; + "Real parameters vector"; + "Integer parameters vector"; + "initial firing vector (<0 for no firing)"; + "direct feedthrough (y or n)"; + "time dependence (y or n)"],.. + list("str",1,"str",1,"vec",-1,"vec",-1,"vec",-1,"vec",-1,.. + "vec",-1,"vec",1,"vec",-1,"vec",-1,"vec",-1,"vec","sum(%6)",.. + "str",1,"str",1),label(1)) + if ~ok then + break, + end + label(1)=lab + funam=stripblanks(function_name) + xx=xx(:); + z=z(:); + rpar=rpar(:); + ipar=int(ipar(:)); + nx=size(xx,1); + nz=size(z,1); + i=int(i(:)); + o=int(o(:)); + nout=size(o,1); + ci=int(ci(:)); + nevin=size(ci,1); + co=int(co(:)); + nevout=size(co,1); + if part(impli,1)=="y" then + funtyp=12004, + else + funtyp=2004, + end + if [ci;co]<>[] then + if max([ci;co])>1 then + message("vector event links not supported"); + ok=%f; + end + end + depu=stripblanks(depu); + if part(depu,1)=="y" then + depu=%t; + else + depu=%f; + end + dept=stripblanks(dept); + if part(dept,1)=="y" then + dept=%t; + else + dept=%f; + end + dep_ut=[depu dept]; + + + if funam==" " then + break, + end + + if model.sim(1)<>funam|sign(size(model.state,"*"))<>sign(nx)|.. + sign(size(model.dstate,"*"))<>sign(nz)|model.nzcross<>ng|.. + sign(size(model.evtout,"*"))<>sign(nevout) then + tt=[] + end + + tt=label(2); + while %t + + [ok,tt,cancel]=CFORTR2(funam,tt) + if ~ok then + if cancel then + break, + end + else + [model,graphics,ok]=check_io(model,graphics,i,o,ci,co) + if ok then + model.sim=list(funam,funtyp) + model.in=i + model.out=o + model.evtin=ci + model.evtout=co + model.state=xx + model.dstate=z + model.rpar=rpar + model.ipar=ipar + model.firing=auto0 + model.dep_ut=dep_ut + model.nzcross=ng + label(2)=tt + x.model=model + graphics.exprs=label + x.graphics=graphics + break + end + end + end + if ok|cancel then + break, + end + end + + case "define" then + in=1 + out=1 + clkin=[] + clkout=[] + x0=[] + z0=[] + typ="c" + auto=[] + rpar=[] + ipar=[] + funam="toto" + ng=0 + + model=scicos_model() + model.sim=list(" ",2004) + model.in=in + model.out=out + model.evtin=clkin + model.evtout=clkout + model.state=x0 + model.dstate=z0 + model.rpar=rpar + model.ipar=ipar + model.blocktype=typ + model.firing=auto + model.dep_ut=[%t %f] + model.nzcross=ng + + label=list([funam,"n",sci2exp(in),sci2exp(out),sci2exp(clkin),sci2exp(clkout),.. + sci2exp(x0),sci2exp(0),sci2exp(z0),sci2exp(rpar),sci2exp(ipar),.. + sci2exp(auto),"y","n"]',[]) + + gr_i=[] + x=standard_define([4 2],model,label,gr_i) + end +endfunction + + diff --git a/macros/Misc/CBLOCK4.sci b/macros/Misc/CBLOCK4.sci new file mode 100644 index 00000000..cb1fecaa --- /dev/null +++ b/macros/Misc/CBLOCK4.sci @@ -0,0 +1,196 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// +function [x,y,typ]=CBLOCK4(job,arg1,arg2) + // + // Copyright INRIA + x=[]; + y=[]; + typ=[]; + + select job + case "set" then + x=arg1 + model=arg1.model; + graphics=arg1.graphics; + label=graphics.exprs; + + while %t do + [ok,function_name,impli,in,it,out,ot,ci,co,xx,z,oz,... + rpar,ipar,opar,nmode,nzcr,auto0,depu,dept,lab]=.. + scicos_getvalue("Set C-Block4 block parameters",.. + ["Simulation function"; + "Is block implicit? (y,n)"; + "Input ports sizes"; + "Input ports type"; + "Output port sizes"; + "Output ports type"; + "Input event ports sizes"; + "Output events ports sizes"; + "Initial continuous state"; + "Initial discrete state"; + "Initial object state"; + "Real parameters vector"; + "Integer parameters vector"; + "Object parameters list"; + "Number of modes"; + "Number of zero crossings"; + "Initial firing vector (<0 for no firing)"; + "Direct feedthrough (y or n)"; + "Time dependence (y or n)"],.. + list("str",1,"str",1,"mat",[-1 2],"vec",-1,"mat",[-1 2],"vec",-1,"vec",-1,"vec",-1,.. + "vec",-1,"vec",-1,"lis",-1,"vec",-1,"vec",-1,"lis",-1,"vec",1,"vec",1,"vec","sum(%8)",.. + "str",1,"str",1),label(1)) + if ~ok then + break + end + label(1)=lab + funam=stripblanks(function_name) + xx=xx(:); + z=z(:); + rpar=rpar(:); + ipar=int(ipar(:)); + nx=size(xx,1); + nz=size(z,1); + + ci=int(ci(:)); + nevin=size(ci,1); + co=int(co(:)); + nevout=size(co,1); + if part(impli,1)=="y" then + funtyp=12004 + else + funtyp=2004 + end + if [ci;co]<>[] then + if max([ci;co])>1 then + message("vector event links not supported"); + ok=%f; + end + end + + if ok then + depu=stripblanks(depu); + if part(depu,1)=="y" then + depu=%t; + else + depu=%f; + end + dept=stripblanks(dept); + if part(dept,1)=="y" then + dept=%t; + else + dept=%f; + end + dep_ut=[depu dept]; + + if funam==" " then + break + end + + //cross checking + if model.sim(1)<>funam|sign(size(model.state,"*"))<>sign(nx)|.. + sign(size(model.dstate,"*"))<>sign(nz)|model.nzcross<>nzcr|.. + sign(size(model.evtout,"*"))<>sign(nevout) then + tt=[] + end + + tt=label(2); + + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),ci,co) + end + + if ok then + while %t + [ok,tt,cancel]=CC4(funam,tt) + if ~ok then + if cancel then + break, + end + else + model.sim=list(funam,funtyp) + model.state=xx + model.dstate=z + model.odstate=oz + model.rpar=rpar + model.ipar=ipar + model.opar=opar + model.firing=auto0 + model.nzcross=nzcr + model.nmode=nmode + model.dep_ut=dep_ut + label(2)=tt + x.model=model + graphics.exprs=label + x.graphics=graphics + break + end + end + + if ok|cancel then + break + end + end + end + + case "define" then + + funam="toto" + + model=scicos_model() + model.sim=list(" ",2004) + + model.in=1 + model.in2=1 + model.intyp=1 + model.out=1 + model.out2=1 + model.outtyp=1 + model.dep_ut=[%t %f] + label=list([funam; + "n"; + sci2exp([model.in model.in2]); + sci2exp(model.intyp); + sci2exp([model.out model.out2]); + sci2exp(model.outtyp); + sci2exp(model.evtin); + sci2exp(model.evtout); + sci2exp(model.state); + sci2exp(model.dstate); + sci2exp(model.odstate); + sci2exp(model.rpar); + sci2exp(model.ipar); + sci2exp(model.opar); + sci2exp(model.nmode); + sci2exp(model.nzcross); + sci2exp(model.firing); + "y"; + "n"],... + []); + + gr_i=[] + x=standard_define([4 2],model,label,gr_i) + end +endfunction + + + + + diff --git a/macros/Misc/CONSTRAINT2_c.sci b/macros/Misc/CONSTRAINT2_c.sci new file mode 100644 index 00000000..e0db95f4 --- /dev/null +++ b/macros/Misc/CONSTRAINT2_c.sci @@ -0,0 +1,100 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=CONSTRAINT2_c(job,arg1,arg2) + // Copyright INRIA + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + while %t do + ask_again=%f + + [ok,x0,xd0,id,exprs]=scicos_getvalue("Set Constraint block parameters",["Initial guess values of states x";"Initial guess values of derivative x''";"Id(i)=1: if x''(i) is present in the feedback, else Id(i)=0"],list("vec",-1,"vec",-1,"vec",-1),exprs) + if ~ok then + break, + end + x0=x0(:); + N=size(x0,"*"); + xd0=xd0(:); + Nxd=size(xd0,"*"); + id=id(:); + Nid=size(id,"*"); + + if (N~=Nxd)|(N~=Nid) then + message("incompatible sizes, states, their derivatives, and ID should be the same size ") + ask_again=%t + end + + if (N<=0 & ~ask_again) then + x_message("number of states (constraints) must be > 0 ") + ask_again=%t + end + + if (~ask_again) then + for i=1:N, + if ~((id(i)==0) | (id(i)==1)) then + ask_again=%t + x_message(["Id(i) must be either";"0 when x''(i) is not present in the feedback";"1: when x''(i) is present in the feedback"]) + break + end + if (id(i)==0) then + id(i)=-1; + end; + end + end + + if ~ask_again then + graphics.exprs=exprs + model.state=[x0;xd0]; + model.out=[N;N] + model.in=N + model.ipar=id + x.graphics=graphics; + x.model=model + break + end + end + + case "define" then + x0=[0]; + xd0=[0]; + id=[0]; + model=scicos_model() + model.sim=list("constraint_c",10004) + model.in=1 + model.out=[1;1] + model.state=[x0;xd0] + model.ipar=id + model.blocktype="c" + model.dep_ut=[%f %t] + exprs=list(strcat(sci2exp(x0)),strcat(sci2exp(xd0)),strcat(sci2exp(id))) + + gr_i=[] + + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Misc/CONSTRAINT_c.sci b/macros/Misc/CONSTRAINT_c.sci new file mode 100644 index 00000000..e73a18f6 --- /dev/null +++ b/macros/Misc/CONSTRAINT_c.sci @@ -0,0 +1,78 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=CONSTRAINT_c(job,arg1,arg2) + // Copyright INRIA + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + while %t do + [ok,x0,exprs]=scicos_getvalue("Set solver block parameters",.. + "Initial guess values",list("vec",-1),exprs) + if ~ok then + break, + end + x0=x0(:); + N=size(x0,"*"); + + if N<=0 then + message("number of states (constraints) must be > 0 ") + else + [model,graphics,ok]=check_io(model,graphics,N,N,[],[]) + if ok then + graphics.exprs=exprs + model.state=[x0;zeros(N,1)]; + model.out=N + model.in=N + model.ipar=-1*ones(N,1); + x.graphics=graphics; + x.model=model + break + end + end + end + + + case "define" then + x0=[0;0] + model=scicos_model() + model.sim=list("constraint_c",10004) + model.in=1 + model.out=1 + model.ipar=0 + model.state=x0 + model.blocktype="c" + model.dep_ut=[%f %t] + exprs="0" + + gr_i=[]; + + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction + + diff --git a/macros/Misc/DEADBAND.sci b/macros/Misc/DEADBAND.sci new file mode 100644 index 00000000..ce7a261a --- /dev/null +++ b/macros/Misc/DEADBAND.sci @@ -0,0 +1,74 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=DEADBAND(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + while %t do + [ok,maxp,minp,zeroc,exprs]=scicos_getvalue("Set Deadband parameters",.. + ["End of dead band";"Start of dead band";"zero crossing (0:no, 1:yes)"],list("vec",1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end + if maxp<=minp then + message("Upper limit must be > Lower limit") + else + rpar=[maxp;minp] + model.rpar=rpar + if zeroc<>0 then + model.nzcross=2 + model.nmode=1 + else + model.nzcross=0 + model.nmode=0 + end + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + minp=-.5; + maxp=.5; + rpar=[maxp;minp] + model=scicos_model() + model.sim=list("deadband",4) + model.in=1 + model.nzcross=2 + model.nmode=1 + model.out=1 + model.rpar=rpar + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[string(maxp);string(minp);string(model.nmode)] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Misc/DEBUG.sci b/macros/Misc/DEBUG.sci new file mode 100644 index 00000000..5aceb38a --- /dev/null +++ b/macros/Misc/DEBUG.sci @@ -0,0 +1,73 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=DEBUG(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + textmp=exprs(2) + ok=%t + while 1==1 + [txt]=dialog(["Enter scilab instructions for debugging."; + " Inputs are block and flag, output is block"],.. + textmp); + + if txt<>[] then + tt=["block=debug_scicos(block,flag)"] + + if execstr("deff(tt,txt)","errcatch")==0 then + warnMode = warning("query"); + warning("off"); + save(TMPDIR+"/debug_scicos", debug_scicos) + warning(warnMode); + exprs(2)=txt + if (scicos_debug()<>2 & scicos_debug()<>3) then + scicos_debug(2) + end + break + else + message(["Error in the instructions";lasterror()]) + end + else + ok=%f; + break; + end + end + if ok then + graphics.exprs=exprs; + x.graphics=graphics; + end + + case "define" then + model=scicos_model() + model.sim=list("%debug_scicos",99) + model.blocktype="d" + + exprs=list("","xcos_debug_gui(flag,block);") + gr_i=[] + x=standard_define([8 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Misc/DEBUG_SCICOS.sci b/macros/Misc/DEBUG_SCICOS.sci new file mode 100644 index 00000000..61f390bf --- /dev/null +++ b/macros/Misc/DEBUG_SCICOS.sci @@ -0,0 +1,24 @@ +// +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2014-2014 - Scilab Enterprises - Bruno JOFRET +// +// 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 [x,y,typ]=DEBUG_SCICOS(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + arg1.gui = "DEBUG" + [x,y,typ] = DEBUG("set", arg1); + case "define" then + x = DEBUG("define") + end +endfunction diff --git a/macros/Misc/DIFF_f.sci b/macros/Misc/DIFF_f.sci new file mode 100644 index 00000000..0992a859 --- /dev/null +++ b/macros/Misc/DIFF_f.sci @@ -0,0 +1,61 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=DIFF_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + while %t do + [ok,x0,xd0,exprs]=scicos_getvalue("Set continuous linear system parameters",.. + ["Initial state";"Initial Derivative"],list("vec",1,"vec",1),exprs) + + + if ~ok then + break, + end + graphics.exprs=exprs; + model.state=[x0(:);xd0(:)]; + x.graphics=graphics; + x.model=model + break + end + x.model.firing=[] //compatibility + case "define" then + x0=[0;0] + model=scicos_model() + model.sim=list("diffblk",10001) + model.in=1 + model.out=1 + model.state=x0 + model.blocktype="c" + model.dep_ut=[%f %t] + + exprs=[strcat(sci2exp(x0(1)));strcat(sci2exp(x0(2)))] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Misc/DSUPER.sci b/macros/Misc/DSUPER.sci new file mode 100644 index 00000000..c0a522b6 --- /dev/null +++ b/macros/Misc/DSUPER.sci @@ -0,0 +1,81 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// Copyright (C) DIGITEO - Clément DAVID <clement.david@scilab.org> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ] = DSUPER(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + + select job + case "set" then + y=needcompile // in case leaving with Exit x=arg1 + typ=list() + graphics=arg1.graphics; + if (length(graphics.exprs) == 0) then + warnBlockByUID(arg1.model.label, gettext("Invalid masked block.")); + x=arg1, + return; + end + + exprs=graphics.exprs(1) + exprs0=graphics.exprs(2)(1) + btitre=graphics.exprs(2)(2)(1) + bitems=graphics.exprs(2)(2)(2:$) + if exprs0==[] then + x=arg1, + return, + end + + // First evaluate the diagram context + context = [arg1.model.rpar.props.context]; + [%scicos_context,ierr] = script2var(context,%scicos_context); + + if ierr <> 0 then + x=arg1, + return; + end + + // then update the context with the mask parameters + tt="scicos_context."+exprs0(1); + for i=2:size(exprs0,1) + tt=tt+",scicos_context."+exprs0(i), + end + + ss=graphics.exprs(2)(3); + scicos_context = %scicos_context; + execstr("[ok,"+tt+",exprs]=scicos_getvalue(btitre,bitems,ss,exprs)") + if ok then + x=arg1; + %scicos_context = scicos_context; + sblock=x.model.rpar; + [sblock,%w,needcompile2,ok]=do_eval(sblock,list(),scicos_context); + y=max(2,needcompile,needcompile2) + x.graphics.exprs(1)=exprs; + x.model.rpar=sblock; + else + x = arg1; + end + + case "define" then + // never used + end +endfunction diff --git a/macros/Misc/EDGETRIGGER.sci b/macros/Misc/EDGETRIGGER.sci new file mode 100644 index 00000000..2d6a06a7 --- /dev/null +++ b/macros/Misc/EDGETRIGGER.sci @@ -0,0 +1,60 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=EDGETRIGGER(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + while %t do + [ok,edge,exprs]=scicos_getvalue("Set edge trigger block parameters",.. + ["rising (1), falling (-1), both (0)"],list("vec",1),exprs) + if ~ok then + break, + end + model.ipar=sign(edge) + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + case "define" then + edge=1 + model=scicos_model() + model.sim=list("edgetrig",4) + model.in=1 + model.out=1 + model.dstate=0 + model.nzcross=1 + model.ipar=sign(edge) + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[string(edge)] + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Misc/EDGE_TRIGGER.sci b/macros/Misc/EDGE_TRIGGER.sci new file mode 100644 index 00000000..b0388600 --- /dev/null +++ b/macros/Misc/EDGE_TRIGGER.sci @@ -0,0 +1,223 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=EDGE_TRIGGER(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + // look for the internal edge trigger block + for i=1:length(arg1.model.rpar.objs) do + o = arg1.model.rpar.objs(i); + if typeof(o) == "Block" & o.gui == "EDGETRIGGER" then + ppath = list(i); + break; + end + end + newpar=list(); + y=0; + for path=ppath do + np=size(path,"*") + spath=list() + for k=1:np + spath($+1)="model" + spath($+1)="rpar" + spath($+1)="objs" + spath($+1)=path(k) + end + xx=arg1(spath)// get the block + execstr("xxn="+xx.gui+"(''set'',xx)") + if diffobjs(xxn,xx) then + model=xx.model + model_n=xxn.model + if ~is_modelica_block(xx) then + modified=or(model.sim<>model_n.sim)|.. + ~isequal(model.state,model_n.state)|.. + ~isequal(model.dstate,model_n.dstate)|.. + ~isequal(model.rpar,model_n.rpar)|.. + ~isequal(model.ipar,model_n.ipar)|.. + ~isequal(model.label,model_n.label) + if or(model.in<>model_n.in)|or(model.out<>model_n.out) then + needcompile=1 + end + if or(model.firing<>model_n.firing) then + needcompile=2 + end + if (size(model.in,"*")<>size(model_n.in,"*"))|.. + (size(model.out,"*")<>size(model_n.out,"*")) then + needcompile=4 + end + if model.sim=="input"|model.sim=="output" then + if model.ipar<>model_n.ipar then + needcompile=4 + end + end + if or(model.blocktype<>model_n.blocktype)|.. + or(model.dep_ut<>model_n.dep_ut) then + needcompile=4 + end + if (model.nzcross<>model_n.nzcross)|(model.nmode<>model_n.nmode) then + needcompile=4 + end + if prod(size(model_n.sim))>1 then + if model_n.sim(2)>1000 then + if model.sim(1)<>model_n.sim(1) then + needcompile=4 + end + end + end + else + modified=or(model_n<>model) + eq=model.equations;eqn=model_n.equations; + if or(eq.model<>eqn.model)|or(eq.inputs<>eqn.inputs)|.. + or(eq.outputs<>eqn.outputs) then + needcompile=4 + end + end + // parameter or states changed + arg1(spath)=xxn// Update + newpar(size(newpar)+1)=path// Notify modification + y=max(y,needcompile) + end + end + x=arg1 + typ=newpar + case "define" then + scs_m_1=scicos_diagram(); + scs_m_1.objs(1) = EDGETRIGGER("define"); + scs_m_1.objs(2) = IFTHEL_f("define"); + scs_m_1.objs(3) = IN_f("define"); + scs_m_1.objs(4) = CLKOUTV_f("define"); + scs_m_1.objs(5) = scicos_link(); + scs_m_1.objs(6) = scicos_link(); + scs_m_1.objs(7) = scicos_link(); + + // EDGETRIGGER + blk = scs_m_1.objs(1); + graphics = blk.graphics; + model = blk.model; + + graphics.orig = [60 0]; + graphics.sz = [60 40]; + + graphics.exprs = "0"; + model.ipar = 0; + + graphics.pin = 5; + graphics.pout = 6; + + blk.graphics = graphics; + blk.model = model; + scs_m_1.objs(1) = blk; + + // IFTHEL_f + blk = scs_m_1.objs(2); + graphics = blk.graphics; + model = blk.model; + + graphics.orig = [160 0]; + graphics.sz = [60 40]; + + graphics.exprs = ["0";"0"]; + model.evtin = []; + model.nzcross = 0; + model.nmode = 0; + + graphics.pin = 6; + graphics.peout = [7;0]; + + blk.graphics = graphics; + blk.model = model; + scs_m_1.objs(2) = blk; + + // IN_f + blk = scs_m_1.objs(3); + graphics = blk.graphics; + model = blk.model; + + graphics.orig = [0 10]; + graphics.sz = [20 20]; + + graphics.exprs = ["1"]; + model.ipar = 1; + + graphics.pout = 5; + + blk.graphics = graphics; + blk.model = model; + scs_m_1.objs(3) = blk; + + // CLKOUTV_f + blk = scs_m_1.objs(4); + graphics = blk.graphics; + model = blk.model; + + graphics.orig = [170 -60]; + graphics.sz = [20 20]; + + graphics.exprs = ["1"]; + model.ipar = 1; + + graphics.pein = 7; + + blk.graphics = graphics; + blk.model = model; + scs_m_1.objs(4) = blk; + + // IN_f -> EDGETRIGGER + lnk = scs_m_1.objs(5); + + lnk.from = [3 1 0]; + lnk.to = [1 1 1]; + + scs_m_1.objs(5) = lnk; + + // EDGETRIGGER -> IFTHEL_f + lnk = scs_m_1.objs(6); + + lnk.from = [1 1 0]; + lnk.to = [2 1 1]; + + scs_m_1.objs(6) = lnk; + + // IFTHEL_f -> CLKOUTV_f + lnk = scs_m_1.objs(7); + + lnk.ct = [5 -1]; + lnk.from = [2 1 0]; + lnk.to = [4 1 1]; + + scs_m_1.objs(7) = lnk; + + clear blk lnk + + model=scicos_model(); + model.sim = "csuper"; + model.in = 1; + model.evtout = 1; + model.rpar = scs_m_1; + + gr_i=[]; + x=standard_define([3 2],model,[],gr_i) + end +endfunction + diff --git a/macros/Misc/ENDBLK.sci b/macros/Misc/ENDBLK.sci new file mode 100644 index 00000000..c0f6698b --- /dev/null +++ b/macros/Misc/ENDBLK.sci @@ -0,0 +1,198 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=ENDBLK(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + // look for the internal edge trigger block + for i=1:length(arg1.model.rpar.objs) do + o = arg1.model.rpar.objs(i); + if typeof(o) == "Block" & o.gui == "END_c" then + ppath = list(i); + break; + end + end + newpar=list(); + y=0; + for path=ppath do + np=size(path,"*") + spath=list() + for k=1:np + spath($+1)="model" + spath($+1)="rpar" + spath($+1)="objs" + spath($+1)=path(k) + end + xx=arg1(spath)// get the block + execstr("xxn="+xx.gui+"(''set'',xx)") + if ~isequalbitwise(xxn,xx) then + model=xx.model + model_n=xxn.model + if ~is_modelica_block(xx) then + modified=or(model.sim<>model_n.sim)|.. + ~isequal(model.state,model_n.state)|.. + ~isequal(model.dstate,model_n.dstate)|.. + ~isequal(model.odstate,model_n.odstate)|.. + ~isequal(model.rpar,model_n.rpar)|.. + ~isequal(model.ipar,model_n.ipar)|.. + ~isequal(model.opar,model_n.opar)|.. + ~isequal(model.label,model_n.label) + if or(model.in<>model_n.in)|or(model.out<>model_n.out)|.. + or(model.in2<>model_n.in2)|or(model.out2<>model_n.out2)|.. + or(model.outtyp<>model_n.outtyp)|or(model.intyp<>model_n.intyp) then + needcompile=1 + end + if or(model.firing<>model_n.firing) then + needcompile=2 + end + if (size(model.in,"*")<>size(model_n.in,"*"))|.. + (size(model.out,"*")<>size(model_n.out,"*"))|.. + (size(model.evtin,"*")<>size(model_n.evtin,"*")) then + needcompile=4 + end + if model.sim=="input"|model.sim=="output" then + if model.ipar<>model_n.ipar then + needcompile=4 + end + end + if or(model.blocktype<>model_n.blocktype)|.. + or(model.dep_ut<>model_n.dep_ut) then + needcompile=4 + end + if (model.nzcross<>model_n.nzcross)|(model.nmode<>model_n.nmode) then + needcompile=4 + end + if prod(size(model_n.sim))>1 then + if model_n.sim(2)>1000 then + if model.sim(1)<>model_n.sim(1) then + needcompile=4 + end + end + end + else + modified=or(model_n<>model) + eq=model.equations;eqn=model_n.equations; + if or(eq.model<>eqn.model)|or(eq.inputs<>eqn.inputs)|.. + or(eq.outputs<>eqn.outputs) then + needcompile=4 + end + end + //parameter or states changed + arg1(spath)=xxn// Update + newpar(size(newpar)+1)=path// Notify modification + y=max(y,needcompile) + end + end + x=arg1 + typ=newpar + case "define" then + scs_m_1=scicos_diagram(.. + version="scicos4.2",.. + props=scicos_params(.. + wpar=[-159.096,811.104,-121.216,617.984,1323,1008,331,284,630,480,0,7,1.4],.. + Title="ENDBLK",.. + tol=[0.0001,0.000001,1.000E-10,100001,0,0],.. + tf=100000,.. + context=" ",.. + void1=[],.. + options=tlist(["scsopt","3D","Background","Link","ID","Cmap"],list(%t,33),[8,1],[1,5],.. + list([5,1],[4,1]),[0.8,0.8,0.8]),.. + void2=[],.. + void3=[],.. + doc=list())) + scs_m_1.objs(1)=scicos_block(.. + gui="END_c",.. + graphics=scicos_graphics(.. + orig=[272.104,249.11733],.. + sz=[40,40],.. + flip=%t,.. + theta=0,.. + exprs="1.000E+08",.. + pin=[],.. + pout=[],.. + pein=2,.. + peout=2,.. + gr_i=[],.. + id="",.. + in_implicit=[],.. + out_implicit=[]),.. + model=scicos_model(.. + sim=list("scicosexit",4),.. + in=[],.. + in2=[],.. + intyp=1,.. + out=[],.. + out2=[],.. + outtyp=1,.. + evtin=1,.. + evtout=1,.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(),.. + blocktype="d",.. + firing=1.000E+08,.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m_1.objs(2)=scicos_link(.. + xx=[292.104;292.104;261.83733;261.83733;292.104;292.104],.. + yy=[243.40305;234.45067;234.45067;305.584;305.584;294.83162],.. + id="drawlink",.. + thick=[0,0],.. + ct=[5,-1],.. + from=[1,1,0],.. + to=[1,1,1]) + model=scicos_model(.. + sim="csuper",.. + in=[],.. + in2=[],.. + intyp=1,.. + out=[],.. + out2=[],.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=scs_m_1,.. + ipar=[],.. + opar=list(),.. + blocktype="h",.. + firing=[],.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()) + gr_i=[]; + x=standard_define([2 2],model,[],gr_i) + end +endfunction diff --git a/macros/Misc/EXPRESSION.sci b/macros/Misc/EXPRESSION.sci new file mode 100644 index 00000000..aaf1fd24 --- /dev/null +++ b/macros/Misc/EXPRESSION.sci @@ -0,0 +1,232 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=EXPRESSION(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + model=arg1.model; + graphics=arg1.graphics; + exprs=graphics.exprs + %scicos_context=%scicos_context; + for ii=1:8, + execstr("%scicos_context.u"+string(ii)+"=0"), + end + ieee(2) + while %t do + [ok,%nin,%exx,%usenz,exprs]=scicos_getvalue(.. + ["Give a scalar scilab expression using inputs u1, u2,..."; + "If only one input, input is vector [u1,u2,...] (max 8)"; + "ex: (dd*u1+sin(u2)>0)*u3"; + "Note that here dd must be defined in context"],.. + ["number of inputs";"scilab expression";"use zero-crossing (0: no, 1 yes)"],.. + list("vec",1,"vec",1,"vec",1),exprs) + ieee(0) + clear %scicos_context + + if ~ok then + break, + end + %exx=strsubst(exprs(2)," ","") + if %exx==emptystr() then + %exx="0", + end //avoid empty + //expression + + if %nin==1 then + %nini=8, + else + %nini=%nin + end + %head="%foo(" + for %jji=1:%nini-1, + %head=%head+"u"+string(%jji)+",", + end + %head=%head+"u"+string(%nini)+")" + ok=execstr("deff(%head,%exx)","errcatch")==0 + if ~ok then + message(["Erroneous expression";lasterror()]) + else + if %nin>1 then + [model,graphics,ok]=check_io(model,graphics,ones(1,%nin),1,[],... + []) + else + [model,graphics,ok]=check_io(model,graphics,-1,1,[],... + []) + end + if ok then + + [ok,%ok1,ipar,rpar,%nz]=compiler_expression(%foo) + + if ~ok then + message(["Erroneous expression";lasterror()]) + else + if %ok1 then + model.rpar=rpar + model.ipar=ipar + if %usenz then + model.nzcross=%nz + model.nmode=%nz + else + model.nzcross=0 + model.nmode=0 + end + graphics.exprs=exprs + x.graphics=graphics + x.model=model + break + end + end + end + end + end + case "define" then + in=[1;1] + out=1 + txt="(u1>0)*sin(u2)^2" + deff("%foo(u1,u2)",txt) + [%ok1,ipar,rpar,nz]=compile_expr(%foo) + model=scicos_model() + model.sim=list("evaluate_expr",4) + model.in=in + model.out=out + model.rpar=rpar + model.ipar=ipar + model.nzcross=nz + model.nmode=nz + model.dep_ut=[%t %f] + exprs=[string(size(in,"*"));txt;"1"] + gr_i=[] + x=standard_define([5 2],model,exprs,gr_i) + end +endfunction + +function [ok,%ok1,ipar,rpar,%nz]=compiler_expression(%foo) + ok=%t,%ok1=%f,ipar=[],rpar=[],%nz=[] + if exists("%scicos_context") then + %mm=getfield(1,%scicos_context) + for %mi=%mm(3:$) + if execstr(%mi+"=%scicos_context(%mi)","errcatch")<>0 then + ok=%f + end + end + end + if ok then + ok=execstr("[%ok1,ipar,rpar,%nz]=compile_expr(%foo)","errcatch")==0 + end +endfunction + + +function [ok,%ipar,%rpar,%nz]=compile_expr(%foo) + ok=%t + %lst=macr2lst(%foo); + %mm=macrovar(%foo); + %MM=%mm(3); + %FF=["sin";"cos";"tan";"exp";"log"; + "sinh";"cosh";"tanh"; + "int";"round";"ceil";"floor"; + "sign";"abs";"max";"min"; + "asin";"acos";"atan";"asinh";"acosh";"atanh"; + "atan2"; + "log10"; + ]; // ops above 100 + %num_arg=[1;1;1;1;1; + 1;1;1 + 1;1;1;1; + 1;1;2;2; + 1;1;1;1;1;1; + 2; + 1 + ]; //number of arguments + %ZCR=[16,17,18,19,20,21,28,29,30,109,110,111,112,113,114,115,116]; // ops with zero-crossing + %UU=%mm(1) + %ipar=[] + %rpar=[] + %nrpar=0 + %nz=0 + %ijk=4 + while %ijk<length(%lst) + %ijk=%ijk+1 + select evstr(%lst(%ijk)(1)) + case 2 + %jjk=find(%lst(%ijk)(2)==%FF) + if %jjk<> [] then + if evstr(%lst(%ijk)(4))<>%num_arg(%jjk) then + message(%lst(%ijk)(2)+" must have "+string(%num_arg(%jjk))+" arguments") + ok=%f + return + else + %ipar=[%ipar;5;100+%jjk] + if or(100+%jjk==%ZCR) then + %nz=%nz+1, + end + %ijk=%ijk+1 + end + else + %jjk=find(%lst(%ijk)(2)==%MM) + if %jjk<> [] then + if ~exists(%MM(%jjk)) then + message("Variable "+%MM(%jjk)+" is not defined.") + ok=%f + return + end + %var=evstr(%MM(%jjk)) + if size(%var,"*")<>1 then + message("Variable "+%MM(%jjk)+" is not scalar.") + ok=%f + return + else + %nrpar=%nrpar+1 + %rpar(%nrpar)=%var + %ipar=[%ipar;6;%nrpar] + end + else + %jjk=find(%lst(%ijk)(2)==%UU) + if %jjk<> [] then + %ipar=[%ipar;2;%jjk] + else + message("Unknown variable "+%lst(%ijk)(2)) + ok=%f + end + //%ipar=[%ipar;2;evstr(strsubst(%lst(%ijk)(2),'u',''))] + end + end + case 5 + // case of - with one operand (-u1) + if (evstr(%lst(%ijk)(2))==2)&(evstr(%lst(%ijk)(3))==1) then + %ipar=[%ipar;5;99] + else + %ipar=[%ipar;5;evstr(%lst(%ijk)(2))] + if or(evstr(%lst(%ijk)(2))==%ZCR) then + %nz=%nz+1, + end + end + case 6 + // %ipar=[%ipar;6;evstr(%lst(%ijk)(2))] + %nrpar=%nrpar+1 + %rpar(%nrpar)=evstr(%lst(%ijk)(2)) + %ipar=[%ipar;6;%nrpar] + end + end +endfunction diff --git a/macros/Misc/Extract_Activation.sci b/macros/Misc/Extract_Activation.sci new file mode 100644 index 00000000..0ba2c371 --- /dev/null +++ b/macros/Misc/Extract_Activation.sci @@ -0,0 +1,156 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=Extract_Activation(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + case "define" then + scs_m_1=scicos_diagram(); + scs_m_1.objs(1) = IFTHEL_f("define"); + scs_m_1.objs(2) = CLKSOMV_f("define"); + scs_m_1.objs(3) = IN_f("define"); + scs_m_1.objs(4) = CLKOUTV_f("define"); + scs_m_1.objs(5) = scicos_link(); + scs_m_1.objs(6) = scicos_link(); + scs_m_1.objs(7) = scicos_link(); + scs_m_1.objs(8) = scicos_link(); + + // IFTHEL_f + blk = scs_m_1.objs(1); + graphics = blk.graphics; + model = blk.model; + + graphics.orig = [80 0]; + graphics.sz = [60 40]; + + graphics.exprs = ["0";"0"]; + model.evtin = []; + model.nzcross = 0; + model.nmode = 0; + + graphics.pin = 7; + graphics.peout = [5;6]; + + blk.graphics = graphics; + blk.model = model; + scs_m_1.objs(1) = blk; + + // CLKSOMV_f + blk = scs_m_1.objs(2); + graphics = blk.graphics; + model = blk.model; + + graphics.orig = [80 -80]; + graphics.sz = [80 40]; + + graphics.pein = [5;6]; + graphics.peout = 8; + + blk.graphics = graphics; + blk.model = model; + scs_m_1.objs(2) = blk; + + // IN_f + blk = scs_m_1.objs(3); + graphics = blk.graphics; + model = blk.model; + + graphics.orig = [0 10]; + graphics.sz = [20 20]; + + graphics.exprs = ["1"]; + model.ipar = 1; + + graphics.pout = 7; + + blk.graphics = graphics; + blk.model = model; + scs_m_1.objs(3) = blk; + + // CLKOUTV_f + blk = scs_m_1.objs(4); + graphics = blk.graphics; + model = blk.model; + + graphics.orig = [110 -140]; + graphics.sz = [20 20]; + + graphics.exprs = ["1"]; + model.ipar = 1; + + graphics.pein = 8; + + blk.graphics = graphics; + blk.model = model; + scs_m_1.objs(4) = blk; + + // IFTHEL_f -> CLKSOMV_f + lnk = scs_m_1.objs(5); + + lnk.ct = [5 -1]; + lnk.from = [1 1 0]; + lnk.to = [2 1 1]; + + scs_m_1.objs(5) = lnk; + + // IFTHEL_f -> CLKSOMV_f + lnk = scs_m_1.objs(6); + + lnk.ct = [5 -1]; + lnk.from = [1 2 0]; + lnk.to = [2 2 1]; + + scs_m_1.objs(6) = lnk; + + // IN_f -> IFTHEL_f + lnk = scs_m_1.objs(7); + + lnk.from = [3 1 0]; + lnk.to = [1 1 1]; + + scs_m_1.objs(7) = lnk; + + // CLKSOMV_f -> CLKOUTV_f + lnk = scs_m_1.objs(8); + + lnk.ct = [5 -1]; + lnk.from = [2 1 0]; + lnk.to = [4 1 1]; + + scs_m_1.objs(8) = lnk; + + clear blk lnk + + model=scicos_model(); + model.sim = "csuper"; + model.in = 1; + model.evtout = 1; + model.rpar = scs_m_1; + + gr_i=[]; + x=standard_define([3 2],model,[],gr_i) + end +endfunction + diff --git a/macros/Misc/HYSTHERESIS.sci b/macros/Misc/HYSTHERESIS.sci new file mode 100644 index 00000000..aa9e9b9b --- /dev/null +++ b/macros/Misc/HYSTHERESIS.sci @@ -0,0 +1,77 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=HYSTHERESIS(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + while %t do + [ok,high_lim,low_lim,out_high,out_low,nzz,exprs]=scicos_getvalue("Set parameters",.. + ["switch on at";"switch off at";"output when on"; + "output when off";"use zero crossing: yes (1), no (0)"],.. + list("vec",1,"vec",1,"vec",1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end + if low_lim>high_lim then + message("switch on value must be larger than switch off value") + else + graphics.exprs=exprs; + model.rpar=[high_lim,low_lim,out_high,out_low]' + if nzz>0 then + nzz=2, + end + model.nzcross=nzz + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + in=1 + ipar=[0] // rule + nzz=2 + rpar=[1;0;1;0] + + model=scicos_model() + model.sim=list("hystheresis",4) + model.in=in + model.out=1 + model.rpar=rpar + model.nzcross=nzz + model.nmode=1 + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[string(rpar);string(sign(nzz))] + + + gr_i=[] + + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Misc/IMPSPLIT_f.sci b/macros/Misc/IMPSPLIT_f.sci new file mode 100644 index 00000000..f1759ffd --- /dev/null +++ b/macros/Misc/IMPSPLIT_f.sci @@ -0,0 +1,45 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=IMPSPLIT_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + + select job + case "set" then + x=arg1; + case "define" then + model=scicos_model(); + model.sim = "limpsplit"; + mo=modelica() + mo.model="limpsplit" + mo.inputs="n"; + mo.outputs=["n";"n"] + model.equations=mo + model.in=ones(size(mo.inputs,"*"),1) + model.out=ones(size(mo.outputs,"*"),1) + x=standard_define([1 1]/3,model,[],[]) + x.graphics.in_implicit=["I"] + x.graphics.out_implicit=["I" "I"] + end + +endfunction diff --git a/macros/Misc/LOGICAL_OP.sci b/macros/Misc/LOGICAL_OP.sci new file mode 100644 index 00000000..bc768645 --- /dev/null +++ b/macros/Misc/LOGICAL_OP.sci @@ -0,0 +1,139 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=LOGICAL_OP(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + + if size(exprs,1)==2 then + exprs=[exprs;sci2exp(1);sci2exp(0)]; + end + while %t do + [ok,nin,rule,Datatype,tp,exprs]=scicos_getvalue("Set parameters",.. + ["number of inputs";.. + "Operator: AND (0), OR (1), NAND (2), NOR (3), XOR (4), NOT (5)" + "Datatype (1=double 3=int32 ...)";.. + "Bitwise Rule(0=No 1=yes)"],.. + list("vec",1,"vec",1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end + nin=int(nin); + rule=int(rule); + tp=int(tp) + if nin<1 then + message("Number of inputs must be >=1 "); + ok=%f + elseif (rule<0)|(rule>5) then + message("Incorrect operator "+string(rule)+" ; must be 0 to 5."); + ok=%f + elseif (rule==5)&(nin>1) then + message("Only one input allowed for NOT operation") + nin=1 + elseif ((Datatype==1)&(tp~=0)) + message ("Bitwise Rule is only activated when Data type is integer"); + ok=%f + end + if ok then + if (tp~=0) then + tp=1; + end + if Datatype==1 then + model.sim=list("logicalop",4) + model.ipar=[rule], + else + if Datatype==3 then + model.sim=list("logicalop_i32",4) + elseif Datatype==4 then + model.sim=list("logicalop_i16",4) + elseif Datatype==5 then + model.sim=list("logicalop_i8",4) + elseif Datatype==6 then + model.sim=list("logicalop_ui32",4) + elseif Datatype==7 then + model.sim=list("logicalop_ui16",4) + elseif Datatype==8 then + model.sim=list("logicalop_ui8",4) + else + message ("Datatype is not supported"); + ok=%f; + end + model.ipar=[rule;tp]; + end + if ok then + it=Datatype*ones(nin,1); + ot=Datatype; + in=[-ones(nin,1) -2*ones(nin,1)] + if (rule<>5)&(nin==1) then + out=[1 1] + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + else + out=[-1 -2] + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + end + end + if ok then + if rule == 0 then + label = "AND"; + elseif rule == 1 then + label = "OR"; + elseif rule == 2 then + label = "NAND"; + elseif rule == 3 then + label = "NOR"; + elseif rule == 4 then + label = "XOR"; + elseif rule == 5 then + label = "NOT"; + end + graphics.exprs=exprs; + graphics.style = ["blockWithLabel;displayedLabel="+label]; + x.graphics=graphics; + x.model=model + break + end + end + end + case "define" then + in=[-1;-1] + ipar=[0] + nin=2 + + model=scicos_model() + model.sim=list("logicalop",4) + model.in=in + model.out=-1 + model.ipar=ipar + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[string(nin);string(ipar)] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Misc/MBLOCK.sci b/macros/Misc/MBLOCK.sci new file mode 100644 index 00000000..71ae263c --- /dev/null +++ b/macros/Misc/MBLOCK.sci @@ -0,0 +1,468 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=MBLOCK(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + model=arg1.model + graphics=arg1.graphics + //label=graphics.exprs; + exprs=graphics.exprs + + //Compatibility + if type(exprs)==15 then + paramv=list(); + pprop=[]; + //must do something better than that ! + for i=1:size(model.rpar,"*") + paramv($+1)=string(model.rpar(i)) + pprop($+1) = 0 + end + + exprs = tlist(["MBLOCK","in","intype","out","outtype",... + "param","paramv","pprop","nameF","funtxt"],... + exprs(1)(1),.. + exprs(1)(2),.. + exprs(1)(3),.. + exprs(1)(4),.. + exprs(1)(5),.. + paramv,... + sci2exp(pprop(:)),.. + exprs(1)(7),exprs(2)) + + end + + //lab_1 = [in,intype,out,outtype,param,nameF] + lab_1 = list(exprs.in,.. //1 + exprs.intype,.. //2 + exprs.out,.. //3 + exprs.outtype,.. //4 + exprs.param,.. //5 + exprs.pprop,.. //6 + exprs.nameF) //7 + + //lab_2 = [paramv] + lab_2 = exprs.paramv //already a list + + //store exprs before modif + //exprs.prev_exprs=exprs; + //exprs.prev_exprs.prev_exprs=tlist("MBLOCK"); + + while %t do + // [ok,Tin,Tintype,Tout,Touttype,Tparam,Tparamv,Tfunam,lab]=.. + // scicos_getvalue('Set Modelica generic block parameters',.. + // ['Input variables: ';.. + // 'Input variables types: ';.. + // 'Output variables: ';.. + // 'Output variables types:';.. + // 'Parameters in Modelica:';.. + // 'Parameter values: ';.. + // 'Function name: '],.. + // list('str',-1,'str',-1,'str',-1,'str',-1,'str',-1,'str',-1,'str',-1),label(1)) + + //warning here lab_1 is a list + [ok,Tin,Tintype,Tout,Touttype,Tparam,pprop,Tfunam,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),lab_1) + + //Cancel case + if ~ok then + break + end + // ierr=execstr("in=stripblanks(evstr(Tin));.. + // intype=stripblanks(evstr(Tintype));.. + // out=stripblanks(evstr(Tout));.. + // outtype=stripblanks(evstr(Touttype));.. + // param=stripblanks(evstr(Tparam));.. + // paramv=evstr(Tparamv);.. + // funam=stripblanks(Tfunam)",'errcatch') + // + //first stage of checking variable name + //put string symbolic parameters in variable + 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 then + //You lose! Try again! Insert coin! + //messagebox("Error, try again please!","modal","error"); + messagebox("Error in evaluation of variables.","modal","error"); + ok=%f + //break + end + + //check for valid name variable + //in + if ok then + for i=1:size(in,"*") + r=%f; + ierr=execstr("r=validvar(in(i))","errcatch") + if ~r then + ok=%f + break + end + end + if ~ok then + messagebox(["Invalid variable name for the input "+string(i)+"."; + """"+in(i)+""""; + "Please choose another variable name."],"modal","error"); + end + end + //out + if ok then + for i=1:size(out,"*") + r=%f; + ierr=execstr("r=validvar(out(i))","errcatch") + if ~r then + ok=%f + break + end + end + if ~ok then + messagebox(["Invalid variable name for the output "+string(i)+"."; + """"+out(i)+""""; + "Please choose another variable name."],"modal","error"); + end + end + //param + if ok then + param=param(:) + for i=1:size(param,"*") + r=%f; + ierr=execstr("r=validvar(param(i))","errcatch") + if ~r then + ok=%f + break + end + end + if ~ok then + messagebox(["Invalid variable name for the parameter "+string(i)+"."; + """"+param(i)+""""; + "Please choose another variable name."],"modal","error"); + end + end + + // type checking + //typeok=%t; + if ok then + for i=1:size(intype,"*") + if intype(i)<>"E"&intype(i)<>"I" then + //typeok=%f; + messagebox("Input type should be ''E'' or ''I''!","modal","error"); + ok=%f + break + end + end + end + // if ~typeok then + // ok=%f + // //break + // end + + if ok then + for i=1:size(outtype,"*") + if outtype(i)<>"E"&outtype(i)<>"I" then + //typeok=%f; + messagebox("Output type should be ''E'' or ''I''!","modal","error"); + ok=%f + break + end + end + end + // if ~typeok then break, end + + //cross size checking + if ok then + if or(size(intype)<>size(in)) then + messagebox("Input variables are not well defined!","modal","error"); + ok=%f + //break; + end + end + + if ok then + if or(size(outtype)<>size(out)) then + messagebox("Output variables are not well defined!","modal","error"); + ok=%f + //break; + end + end + + //check param properties + if ok then + pprop = pprop(:) + if (size(param,"*")<>size(pprop,"*")) then + messagebox(["There is differences in"; + "size of param and size "; + "of param properties."],"modal","error"); + ok=%f + //break; + end + end + + if ok then + if max(pprop)>2 | min(pprop)<0 then + messagebox(["Parameters properties must be :"; + "0 : for simple paramater,"; + "1 : for initial state value,"; + "2 : for a fixed initial state value."],"modal","error"); + ok=%f + //break; + end + end + + //check name of modelica file + if ok then + if funam=="" then + messagebox("The filename is not defined!","modal","error"); + ok=%f + //break + end + end + + if ok then + [dirF,nameF,extF]=fileparts(funam); + if (extF<>"" & extF<>".mo")|(dirF<>"" & extF<>".mo") then + messagebox("Filename extention should be ''.mo '' !","modal","error"); + ok=%f + //break + end + end + + if ok then + //set_io checking + intypex=find(intype=="I"); outtypex=find(outtype=="I"); + //[model,graphics,ok]=check_io(model,graphics,ones(in),.. + // ones(out),[],[],intypex,outtypex) + [model,graphics,ok]=set_io(model,graphics,list([ones(in),ones(in)],ones(in)),.. + list([ones(out),ones(out)],ones(out)),.. + [],[],intypex,outtypex) + end + + //***************************************************************************** + //generate second dialog box from Tparam + if ok then + + Tparam_lab=evstr(Tparam) //labels + Tparam_sz=size(Tparam_lab,"*") //numbers of labels + + //adjust size of lab_2 according to size of Tparam + if Tparam_sz>lstsize(lab_2) then + for i=1:(Tparam_sz-lstsize(lab_2)) + lab_2($+1)="0" + end + elseif Tparam_sz<lstsize(lab_2) then + lab_2_tmp=list() + if Tparam_sz<>0 then //if param + for i=1:(lstsize(lab_2)-Tparam_sz) + lab_2_tmp(i)=lab_2(i) + end + end + lab_2=lab_2_tmp + end + + //generate lhs, label and rhs txt for scicos_getvalue + if Tparam_sz<>0 then //if param + lhs_txt="" //lhs txt + lab_txt="" //label txt + rhs_txt="" //rhs txt + for i=1:Tparam_sz + lhs_txt=lhs_txt+"%v"+string(i)+"," + if pprop(i) == 0 then + lab_txt=lab_txt+"''"+Tparam_lab(i)+"'';" + elseif pprop(i) == 1 then + lab_txt=lab_txt+"''"+Tparam_lab(i)+" (state) '';" + elseif pprop(i) == 2 then + lab_txt=lab_txt+"''"+Tparam_lab(i)+" (fixed state) '';" + end + rhs_txt=rhs_txt+"''vec'',-1," + end + 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) + + //generate main scicos_getvalue cmd + //warning here lab_2 is a list in input and a string in output + getvalue_txt = "[ok,"+lhs_txt+",lab_2]=scicos_getvalue(''Set parameters values'',["+.. + lab_txt+"],"+.. + "list("+rhs_txt+"),lab_2)" + + //display the second dialog box + execstr(getvalue_txt) + + //restore original lab_2 if not ok + if ~ok then + lab_2 = exprs.paramv + end + end + end + + //put output param in the form of a list + //in paramv + if ok then + paramv=list(); + for i=1:Tparam_sz + execstr("paramv("+string(i)+")=%v"+string(i)) + end + end + //***************************************************************************** + + //============================---------MBLOCK2 + if ok then + if extF==".mo" & fileinfo(funam)<>[] then + tt=mgetl(funam) + else + tt=exprs.funtxt + mo=model.equations + //if model.sim(1)<>nameF then + if mo.model<>nameF then + tt=[] + end + end + //============================ + [ok,tt]=MODCOM(funam,tt,in,out,param,paramv,pprop) + if ~ok then + break + end + end + + if ok then + //------------------ + mo=modelica() + mo.model=nameF + mo.inputs=in; + mo.outputs=out; + if max(pprop)>0 then + mo.parameters=list(param',paramv,pprop') + else + mo.parameters=list(param',paramv) + end + model.equations=mo + //------------------ + //model.rpar=paramv; + model.rpar=[] + for i=1:lstsize(paramv) + model.rpar=[model.rpar; + paramv(i)(:)]//value + end + model.sim(1)=funam + //------------------ + exprs.in=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 then //if param + if type(lab_2)==15 then //for eval + for i=1:lstsize(lab_2) + exprs.paramv(i)=lab_2(i);//string + end + else + for i=1:size(lab_2,"*") + exprs.paramv(i)=lab_2(i); + end + end + end + exprs.pprop=lab_1(6) + exprs.nameF=lab_1(7) + exprs.funtxt=tt + //label(2)=tt + //------------------ + x.model=model + graphics.gr_i(1)(1)="txt=[''Modelica'';'' " + nameF + " ''];" + graphics.in_implicit =intype + graphics.out_implicit=outtype + //graphics.exprs=label + graphics.exprs=exprs + x.graphics=graphics + break + end + end + + //Define + case "define" then + in=["u1"] + intype=["I"] + out=["y1";"y2"] + outtype=["I";"E"] + param=["R";"L"]; + //paramv=[0.1;0.0001]; + paramv=list(0.1,.0001) + pprop=[0;0]; + nameF="generic" + + //label=list([sci2exp(in),sci2exp(intype,sci2exp(out),.. + // sci2exp(outtype),sci2exp(param),sci2exp(paramv),nameF]',[]) + + exprs = tlist(["MBLOCK","in","intype","out","outtype",... + "param","paramv","pprop","nameF","funtxt"],... + sci2exp(in(:)),.. + sci2exp(intype(:)),.. + sci2exp(out(:)),.. + sci2exp(outtype(:)),.. + sci2exp(param(:)),.. + list(string(0.1),string(.0001)),... + sci2exp(pprop(:)),.. + nameF,[]) + + model=scicos_model() + model.blocktype="c" + model.dep_ut=[%f %t] + //model.rpar=paramv; + model.rpar=[] + for i=1:lstsize(paramv) + model.rpar=[model.rpar; + paramv(i)(:)] + end + + mo=modelica() + mo.model=nameF + mo.parameters=list(param,paramv) + model.sim=list(mo.model,30004) + mo.inputs=in + mo.outputs=out + model.in=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,label,gr_i) + x=standard_define([3 2],model,exprs,gr_i) + x.graphics.in_implicit =intype + x.graphics.out_implicit=outtype + end +endfunction + diff --git a/macros/Misc/MEMORY_f.sci b/macros/Misc/MEMORY_f.sci new file mode 100644 index 00000000..d4aef072 --- /dev/null +++ b/macros/Misc/MEMORY_f.sci @@ -0,0 +1,77 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=MEMORY_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + while %t do + [ok,a,inh,exprs]=scicos_getvalue("Set memory block parameters",.. + ["initial condition";"Inherit (1: no, 0: yes)"],list("vec",-1,"vec",1),exprs) + if ~ok then + break, + end + if inh==0 then + inh=[]; + else + inh=1; + end + [model,graphics,ok]=check_io(model,graphics,-1,-1,inh,[]) + out=size(a,"*"); + if out==0 then + ok=%f, + messagebox("Initial condition empty","modal","error"); + end + in=out + if ok then + graphics.exprs=exprs; + model.rpar=a; + model.in=in; + model.out=out + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + z=0 + in=1 + exprs=[string(z);string(1)] + model=scicos_model() + model.sim="memo" + model.in=in + model.out=in + model.evtin=1 + model.dstate=0 + model.rpar=z + model.blocktype="m" + model.dep_ut=[%f %f] + + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Misc/MPBLOCK.sci b/macros/Misc/MPBLOCK.sci new file mode 100644 index 00000000..a249e9ba --- /dev/null +++ b/macros/Misc/MPBLOCK.sci @@ -0,0 +1,459 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=MPBLOCK(job,arg1,arg2) + // + // Copyright INRIA Oct 2006 + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + model=arg1.model + graphics=arg1.graphics + //label=graphics.exprs; + exprs=graphics.exprs + + //Compatibility + if type(exprs)==15 then + paramv=list(); + pprop=[]; + //must do something better than that ! + for i=1:size(model.rpar,"*") + paramv($+1)=string(model.rpar(i)) + pprop($+1) = 0 + end + + exprs = tlist(["MPBLOCK","in","intype","out","outtype",... + "param","paramv","pprop","nameF","funtxt"],... + exprs(1)(1),.. + exprs(1)(2),.. + exprs(1)(3),.. + exprs(1)(4),.. + exprs(1)(5),.. + paramv,... + sci2exp(pprop(:)),.. + exprs(1)(7),exprs(2)) + + end + + //lab_1 = [in,intype,out,outtype,param,nameF] + lab_1 = list(exprs.in,.. //1 + exprs.intype,.. //2 + exprs.out,.. //3 + exprs.outtype,.. //4 + exprs.param,.. //5 + exprs.pprop,.. //6 + exprs.nameF) //7 + + //lab_2 = [paramv] + lab_2 = exprs.paramv //already a list + + //store exprs before modif + //exprs.prev_exprs=exprs; + //exprs.prev_exprs.prev_exprs=tlist("MPBLOCK"); + + while %t do + // [ok,Tin,Tintype,Tout,Touttype,Tparam,Tparamv,Tfunam,lab]=.. + // getvalue('Set Modelica generic block parameters',.. + // ['Input variables: ';.. + // 'Input variables types: ';.. + // 'Output variables: ';.. + // 'Output variables types:';.. + // 'Parameters in Modelica:';.. + // 'Parameter values: ';.. + // 'Function name: '],.. + // list('str',-1,'str',-1,'str',-1,'str',-1,'str',-1,'str',-1,'str',-1),label(1)) + //warning here lab_1 is a list + [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) + + //Cancel case + if ~ok then + break + end + // ierr=execstr("in=stripblanks(evstr(Tin));.. + // intype=stripblanks(evstr(Tintype));.. + // out=stripblanks(evstr(Tout));.. + // outtype=stripblanks(evstr(Touttype));.. + // param=stripblanks(evstr(Tparam));.. + // paramv=evstr(Tparamv);.. + // funam=stripblanks(Tfunam)",'errcatch') + // + //first stage of checking variable name + //put string symbolic parameters in variable + 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 then + //You lose! Try again! Insert coin! + //x_message("Error, try again please!") + x_message("Error in evaluation of variables.") + ok=%f + //break + end + + //check for valid name variable + //in + if ok then + for i=1:size(in,"*") + r=%f; + ierr=execstr("r=validvar(in(i))","errcatch") + if ~r then + ok=%f + break + end + end + if ~ok then + x_message(["Invalid variable name for the input "+string(i)+"."; + """"+in(i)+""""; + "Please choose another variable name."] ); + end + end + //out + if ok then + for i=1:size(out,"*") + r=%f; + ierr=execstr("r=validvar(out(i))","errcatch") + if ~r then + ok=%f + break + end + end + if ~ok then + x_message(["Invalid variable name for the output "+string(i)+"."; + """"+out(i)+""""; + "Please choose another variable name."] ); + end + end + //param + if ok then + param=param(:) + for i=1:size(param,"*") + r=%f; + ierr=execstr("r=validvar(param(i))","errcatch") + if ~r then + ok=%f + break + end + end + if ~ok then + x_message(["Invalid variable name for the parameter "+string(i)+"."; + """"+param(i)+""""; + "Please choose another variable name."] ); + end + end + + // type checking + //typeok=%t; + if ok then + for i=1:size(intype,"*") + if intype(i)<>"E"&intype(i)<>"I" then + //typeok=%f; + x_message("Input type should be ''E'' or ''I''!"); + ok=%f + break + end + end + end + // if ~typeok then + // ok=%f + // //break + // end + + if ok then + for i=1:size(outtype,"*") + if outtype(i)<>"E"&outtype(i)<>"I" then + //typeok=%f; + x_message("Output type should be ''E'' or ''I''!"); + ok=%f + break + end + end + end + // if ~typeok then break, end + + //cross size checking + if ok then + if or(size(intype)<>size(in)) then + x_message("Input variables are not well defined!"); + ok=%f + //break; + end + end + + if ok then + if or(size(outtype)<>size(out)) then + x_message("Output variables are not well defined!"); + ok=%f + //break; + end + end + + //check param properties + if ok then + pprop = pprop(:) + if (size(param,"*")<>size(pprop,"*")) then + x_message(["There is differences in"; + "size of param and size "; + "of param properties." ]) + ok=%f + //break; + end + end + + if ok then + if max(pprop)>2 | min(pprop)<0 then + 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=%f + //break; + end + end + + //check name of modelica file + if ok then + if funam=="" then + x_message("The model name is not defined!") + ok=%f + //break + end + end + + if ok then + [dirF,nameF,extF]=fileparts(funam); + if (extF<>"" )|(dirF<>"") then + x_message("Invalid model name!") + ok=%f + //break + end + end + + if ok then + //set_io checking + intypex=find(intype=="I"); outtypex=find(outtype=="I"); + //[model,graphics,ok]=check_io(model,graphics,ones(in),.. + // ones(out),[],[],intypex,outtypex) + [model,graphics,ok]=set_io(model,graphics,list([ones(in),ones(in)],ones(in)),.. + list([ones(out),ones(out)],ones(out)),.. + [],[],intypex,outtypex) + end + + //***************************************************************************** + //generate second dialog box from Tparam + if ok then + + Tparam_lab=evstr(Tparam) //labels + Tparam_sz=size(Tparam_lab,"*") //numbers of labels + + //adjust size of lab_2 according to size of Tparam + if Tparam_sz>lstsize(lab_2) then + for i=1:(Tparam_sz-lstsize(lab_2)) + lab_2($+1)="0" + end + elseif Tparam_sz<lstsize(lab_2) then + lab_2_tmp=list() + if Tparam_sz<>0 then //if param + for i=1:Tparam_sz + ee=evstr(exprs.param) + for j=1:size(ee,"r") + if ee(j)==Tparam_lab(i) then + lab_2_tmp(i)=lab_2(j) + end + end + end + lab_2=lab_2_tmp + end + end + //generate lhs, label and rhs txt for getvalue + if Tparam_sz<>0 then //if param + lhs_txt="" //lhs txt + lab_txt="" //label txt + rhs_txt="" //rhs txt + for i=1:Tparam_sz + lhs_txt=lhs_txt+"%v"+string(i)+"," + if pprop(i) == 0 then + lab_txt=lab_txt+"''"+Tparam_lab(i)+"'';" + elseif pprop(i) == 1 then + lab_txt=lab_txt+"''"+Tparam_lab(i)+" (state) '';" + elseif pprop(i) == 2 then + lab_txt=lab_txt+"''"+Tparam_lab(i)+" (fixed state) '';" + end + rhs_txt=rhs_txt+"''vec'',-1," + end + 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) + + //generate main getvalue cmd + //warning here lab_2 is a list in input and a string in output + getvalue_txt = "[ok,"+lhs_txt+",lab_2]=scicos_getvalue(''Set parameters values'',["+.. + lab_txt+"],"+.. + "list("+rhs_txt+"),lab_2)" + + //display the second dialog box + execstr(getvalue_txt) + + //restore original lab_2 if not ok + if ~ok then + lab_2 = exprs.paramv + end + end + end + + //put output param in the form of a list + //in paramv + if ok then + paramv=list(); + for i=1:Tparam_sz + execstr("paramv("+string(i)+")=%v"+string(i)) + end + end + //***************************************************************************** + + //============================---------MPBLOCK + + if ok then + //------------------ + mo=modelica() + mo.model=nameF + mo.inputs=in; + mo.outputs=out; + if pprop~=[] then + if max(pprop)>0 then + mo.parameters=list(param',paramv,pprop') + else + mo.parameters=list(param',paramv) + end + end + model.equations=mo + //------------------ + //model.rpar=paramv; + model.rpar=[] + for i=1:lstsize(paramv) + model.rpar=[model.rpar; + double(paramv(i)(:))]//value + end + + model.sim(1)=funam + //------------------ + exprs.in=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 then //if param + if type(lab_2)==15 then //for eval + for i=1:lstsize(lab_2) + exprs.paramv(i)=lab_2(i);//string + end + else + for i=1:size(lab_2,"*") + exprs.paramv(i)=lab_2(i); + end + end + end + exprs.pprop=lab_1(6) + exprs.nameF=lab_1(7) + exprs.funtxt="" // model is defined in the a package + //label(2)=tt + //------------------ + x.model=model + graphics.gr_i(1)(1)="txt=['' " + nameF + " ''];" + graphics.in_implicit =intype + graphics.out_implicit=outtype + //graphics.exprs=label + graphics.exprs=exprs + x.graphics=graphics + break + end + end + + //Define + case "define" then + in=["u"] + intype=["I"] + out=["y1";"y2"] + outtype=["I";"I"] + param=[]; + paramv=list() + pprop=[]; + nameF="myModel" + + //label=list([sci2exp(in),sci2exp(intype,sci2exp(out),.. + // sci2exp(outtype),sci2exp(param),sci2exp(paramv),nameF]',[]) + + exprs = tlist(["MPBLOCK","in","intype","out","outtype",... + "param","paramv","pprop","nameF","funtxt"],... + sci2exp(in(:)),.. + sci2exp(intype(:)),.. + sci2exp(out(:)),.. + sci2exp(outtype(:)),.. + sci2exp(param(:)),.. + list(string(0.1),string(.0001)),... + sci2exp(pprop(:)),.. + nameF,[]) + + model=scicos_model() + model.blocktype="c" + model.dep_ut=[%t %t] + //model.rpar=paramv; + model.rpar=[] + for i=1:lstsize(paramv) + model.rpar=[model.rpar; + paramv(i)(:)] + end + + mo=modelica() + mo.model=nameF + mo.parameters=list(param,paramv) + model.sim=list(mo.model,10004) + mo.inputs=in + mo.outputs=out + model.in=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 + end +endfunction + + + diff --git a/macros/Misc/PAL_f.sci b/macros/Misc/PAL_f.sci new file mode 100644 index 00000000..2d0a7d29 --- /dev/null +++ b/macros/Misc/PAL_f.sci @@ -0,0 +1,55 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=PAL_f(job,arg1,arg2) + // Copyright INRIA + x=[]; + y=[]; + typ=[]; + + select job + case "set" then + [x,newparameters,needcompile,edited]=scicos(arg1.model.rpar) + arg1.graphics.id=x.props.title(1); + arg1.model.rpar=x; + x=arg1 + y=[] + typ=[] + %exit=resume(%f) + + case "define" then + scs=scicos_diagram(); + scs.props.title="Palette"; + model=scicos_model(); + model.sim="palette"; + model.in=[]; + model.out=[]; + model.rpar=scs; + model.blocktype="h"; + model.dep_ut=[%f %f]; + + gr_i=[] + + x=standard_define([2 2],model,[],gr_i) + x.graphics.id=scs.props.title(1); + end + +endfunction diff --git a/macros/Misc/PENDULUM_ANIM.sci b/macros/Misc/PENDULUM_ANIM.sci new file mode 100644 index 00000000..dec193c9 --- /dev/null +++ b/macros/Misc/PENDULUM_ANIM.sci @@ -0,0 +1,90 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// +///withoutPrompt +function [x,y,typ]=PENDULUM_ANIM(job,arg1,arg2) + // Animation of the cart-pendulum problem + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + dstate=model.dstate + while %t do + [ok,plen,csiz,phi,xmin,xmax,ymin,ymax,exprs]=scicos_getvalue(.. + "Set Scope parameters",.. + ["pendulum length";"cart size (square side)";"slope"; + "Xmin";"Xmax"; "Ymin"; "Ymax"; ],.. + list("vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end + mess=[] + if plen<=0|csiz<=0 then + mess=[mess;"Pendulum length and cart size must be positive.";" "] + ok=%f + end + if ymin>=ymax then + mess=[mess;"Ymax must be greater than Ymin";" "] + ok=%f + end + if xmin>=xmax then + mess=[mess;"Xmax must be greater than Xmin";" "] + ok=%f + end + + if ~ok then + message(mess) + else + rpar=[plen;csiz;phi;xmin;xmax;ymin;ymax] + model.rpar=rpar; + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + plen=2; + csiz=2; + phi=0; + xmin=-5; + xmax=5; + ymin=-5; + ymax=5 + model=scicos_model() + model.sim=list("anim_pen",5) + model.in=[1;1] + model.evtin=1 + model.dstate=0 + model.rpar=[plen;csiz;phi;xmin;xmax;ymin;ymax] + model.blocktype="d" + model.dep_ut=[%f %f] + + exprs=string(model.rpar) + gr_i=[] + x=standard_define([3 3],model,exprs,gr_i) + end + +endfunction ///\withPrompt{} diff --git a/macros/Misc/RATELIMITER.sci b/macros/Misc/RATELIMITER.sci new file mode 100644 index 00000000..c7cbed4e --- /dev/null +++ b/macros/Misc/RATELIMITER.sci @@ -0,0 +1,65 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=RATELIMITER(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + while %t do + [ok,maxp,minp,exprs]=scicos_getvalue("Set rate limiter parameters",.. + ["max slope";"min slope";],list("vec",1,"vec",1),exprs) + if ~ok then + break, + end + if maxp<=minp|maxp<=0|minp>=0 then + message("We must have max_slope> 0 > min_slope.") + else + rpar=[maxp;minp] + model.rpar=rpar + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + minp=-1; + maxp=1; + rpar=[maxp;minp] + model=scicos_model() + model.sim=list("ratelimiter",4) + model.in=1 + model.out=1 + model.rpar=rpar + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[string(maxp);string(minp)] + gr_i=[] + x=standard_define([3.5 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Misc/RELATIONALOP.sci b/macros/Misc/RELATIONALOP.sci new file mode 100644 index 00000000..8c0c44b5 --- /dev/null +++ b/macros/Misc/RELATIONALOP.sci @@ -0,0 +1,116 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ] = RELATIONALOP(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + if size(exprs,1)==2 then + exprs=[exprs;sci2exp(1)]; + end + while %t do + [ok,rule,zcr,Datatype,exprs]=scicos_getvalue("Set parameters",.. + ["Operator: == (0), ~= (1), < (2), <= (3), > (4), >= (5)";.. + "Use zero crossing (no: 0), (yes: 1)" + "Datatype (1=double 3=int32 ...)"],.. + list("vec",1,"vec",1,"vec",1),exprs) + if ~ok then + break, + end + rule=int(rule); + if zcr<>0 then + zcr=1, + end + if (rule<0)|(rule>5) then + message("Incorrect operator "+string(rule)+" ; must be 0 to 5.") + ok=%f; + end + if (Datatype==1) then + model.sim=list("relational_op",4) + elseif (Datatype==3|Datatype==9) then + model.sim=list("relational_op_i32",4) + elseif(Datatype==4) then + model.sim=list("relational_op_i16",4) + elseif(Datatype==5) then + model.sim=list("relational_op_i8",4) + elseif(Datatype==6) then + model.sim=list("relational_op_ui32",4) + elseif(Datatype==7) then + model.sim=list("relational_op_ui16",4) + elseif(Datatype==8) then + model.sim=list("relational_op_ui8",4) + else + message("Datatype is not supported"); + ok=%f; + end + if ok then + it=Datatype*ones(1,2) + ot=Datatype + in=[-1 -2;-1 -2] + out=[-1 -2] + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[]) + end + if ok then + if rule == 0 then + label = "=="; + elseif rule == 1 then + label = "~="; + elseif rule == 2 then + label = "<"; // < + elseif rule == 3 then + label = "≤"; // <= + elseif rule == 4 then + label = ">"; // > + elseif rule == 5 then + label = "≥"; // >= + end + graphics.exprs=exprs; + graphics.style=["fontSize=13;fontStyle=1;displayedLabel="+label]; + model.ipar=[rule], + model.nzcross=zcr, + model.nmode=zcr, + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + ipar=[2] + label="<"; + model=scicos_model() + model.sim=list("relationalop",4) + model.in=[1;1] + model.out=1 + model.ipar=ipar + model.blocktype="c" + model.dep_ut=[%t %f] + exprs=[string(ipar);string(0)] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + x.graphics.style=["fontSize=13;fontStyle=1;displayedLabel="+label]; + end +endfunction diff --git a/macros/Misc/SPLIT_f.sci b/macros/Misc/SPLIT_f.sci new file mode 100644 index 00000000..49c757c6 --- /dev/null +++ b/macros/Misc/SPLIT_f.sci @@ -0,0 +1,47 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +//** 23 Jun 2006 + +function [x,y,typ] = SPLIT_f(job,arg1,arg2) + + + x=[]; + y=[]; + typ=[]; + + select job + + case "set" then + x=arg1; + + case "define" then + model=scicos_model() ; + model.sim = "lsplit" ; + model.in = -1 ; + model.out = [-1;-1;-1] ; + model.blocktype = "c" ; + model.dep_ut = [%t %f] ; + //** + x=standard_define([1 1]/3,model,[],[]) + end + +endfunction diff --git a/macros/Misc/SUPER_f.sci b/macros/Misc/SUPER_f.sci new file mode 100644 index 00000000..1eee3a59 --- /dev/null +++ b/macros/Misc/SUPER_f.sci @@ -0,0 +1,60 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// Copyright (C) DIGITEO - 2010-2010 - Clément DAVID <clement.david@scilab.org> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=SUPER_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + + select job + case "set" then + // not used on Xcos, re-implemented for compatibility + xcos(arg1.model.rpar); + + case "define" then + // nested diagram settings (2 ports) + scs=scicos_diagram(); + scs.props.title="Super Block"; + + in = IN_f("define"); + in.graphics.orig = [40, 40]; + in.graphics.sz = [20, 20]; + out = OUT_f("define"); + out.graphics.orig = [240, 40]; + out.graphics.sz = [20, 20]; + + scs.objs(1) = in; + scs.objs(2) = out; + + // block settings + model=scicos_model(); + model.sim="super"; + model.in=1; + model.out=1; + model.rpar=scs; + model.blocktype="h"; + model.dep_ut=[%f %f]; + + gr_i=[] + x=standard_define([2 2],model,[],gr_i) + end +endfunction diff --git a/macros/Misc/TEXT_f.sci b/macros/Misc/TEXT_f.sci new file mode 100644 index 00000000..de7d62fb --- /dev/null +++ b/macros/Misc/TEXT_f.sci @@ -0,0 +1,117 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=TEXT_f(job,arg1,arg2) + //** 22-23 Aug 2006: some carefull adjustements for the fonts + //** inside the new graphics datastructure + x=[]; + y=[]; + typ=[]; + + select job + + case "set" then + x = arg1 ; + graphics = arg1.graphics ; + orig = graphics.orig ; + exprs = graphics.exprs ; + model = arg1.model ; + if size(exprs,"*")==1 then + exprs = [exprs;"3";"1"] + end // compatibility + + while %t do + [ok,txt,font,siz,exprs] = scicos_getvalue("Set Text block parameters",.. + ["Text";"Font number";"Font size"], list("str",-1,"vec",1,"vec",1),exprs) + + if ~ok then + break, + end //** + + if font<=0|font>6 then + message("Font number must be greater than 0 and less than 7") + ok=%f + end + + if siz<0 then + message("Font size must be positive") + ok=%f + end + + if ok then + graphics.exprs = exprs + + //** save the font + //** oldfont = xget('font') + gh_winpal = gca(); //** get the current Axes proprieties + default_font_style = gh_winpal.font_style ; + default_font_size = gh_winpal.font_size ; + default_font_color = gh_winpal.font_color ; + + //** set the new font + //** xset('font',font,siz) + gh_winpal.font_style = font ; + gh_winpal.font_size = siz ; + + + //** store the box coordinate that contains the string + r = xstringl(0,0,exprs(1),evstr(exprs(2)),evstr(exprs(3))); + + //** restore the old font + //** xset('font',oldfont(1),oldfont(2)); + gh_winpal.font_style = default_font_style ; + gh_winpal.font_size = default_font_size ; + gh_winpal.font_color = default_font_color ; + + sz = r(3:4) ; + graphics.sz = sz ; + x.graphics = graphics ; + ipar = [font;siz] + model.rpar = txt ; + model.ipar = ipar ; + x.model = model ; + break + end + + end //** of while + + + case "define" then + font = 2 ; + siz = 1 ; + + model = scicos_model() + model.sim = "text" + model.rpar= "Text" + model.ipar=[font;siz] + + exprs = ["Text";string(font); string(siz)] + graphics = scicos_graphics(); + graphics.orig = [0,0]; + graphics.sz =[2 1]; + graphics.exprs = exprs + + + x = mlist(["Text","graphics","model","void","gui"],graphics,model," ","TEXT_f") + + end + +endfunction diff --git a/macros/Misc/c_block.sci b/macros/Misc/c_block.sci new file mode 100644 index 00000000..a6695407 --- /dev/null +++ b/macros/Misc/c_block.sci @@ -0,0 +1,109 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=c_block(job,arg1,arg2) + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + model=arg1.model; + graphics=arg1.graphics; + label=graphics.exprs; + while %t do + [ok,i,o,rpar,funam,lab]=.. + scicos_getvalue("Set C_block parameters",.. + ["input ports sizes"; + "output port sizes"; + "System parameters vector"; + "function name"],.. + list("vec",-1,"vec",-1,"vec",-1,"str",-1),label(1)) + if ~ok then + break, + end + if funam==" " then + break, + end + label(1)=lab + rpar=rpar(:) + i=int(i(:)); + ni=size(i,1); + o=int(o(:)); + no=size(o,1); + tt=label(2); + if model.sim(1)<>funam|size(model.in,"*")<>size(i,"*").. + |size(model.out,"*")<>size(o,"*") then + tt=[] + end + [ok,tt]=CFORTR(funam,tt,i,o) + if ~ok then + break, + end + [model,graphics,ok]=check_io(model,graphics,i,o,[],[]) + if ok then + model.sim(1)=funam + model.rpar=rpar + label(2)=tt + x.model=model + graphics.exprs=label + x.graphics=graphics + break + end + end + case "define" then + in=1 + out=1 + clkin=[] + clkout=[] + x0=[] + z0=[] + typ="c" + auto=[] + rpar=[] + funam="toto" + //chek + + //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ + //model=list(list(' ',2001),in,out,clkin,clkout,x0,z0,rpar,0,typ,auto,[%t %f],.. + // ' ',list()); + + model=scicos_model() + model.sim=list(" ",2001) + model.in=in + model.out=out + model.evtin=clkin + model.evtout=clkout + model.state=x0 + model.dstate=z0 + model.rpar=rpar + model.ipar=0 + model.blocktype=typ + model.firing=auto + model.dep_ut=[%t %f] + //********************************************************************************** + label=list([sci2exp(in);sci2exp(out); strcat(sci2exp(rpar));funam],.. + list([])) + gr_i=[] + x=standard_define([3 2],model,label,gr_i) + end +endfunction diff --git a/macros/Misc/fortran_block.sci b/macros/Misc/fortran_block.sci new file mode 100644 index 00000000..f3abb85d --- /dev/null +++ b/macros/Misc/fortran_block.sci @@ -0,0 +1,93 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=fortran_block(job,arg1,arg2) + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + model=arg1.model; + graphics=arg1.graphics; + label=graphics.exprs; + while %t do + [ok,i,o,rpar,funam,lab]=.. + scicos_getvalue("Set fortran_block parameters",.. + ["input ports sizes"; + "output port sizes"; + "System parameters vector"; + "function name"],.. + list("vec",-1,"vec",-1,"vec",-1,"str",-1),label(1)) + if ~ok then + break, + end + if funam==" " then + break, + end + label(1)=lab + rpar=rpar(:) + i=int(i(:)); + ni=size(i,1); + o=int(o(:)); + no=size(o,1); + tt=label(2); + if model.sim(1)<>funam|size(model.in,"*")<>size(i,"*").. + |size(model.out,"*")<>size(o,"*") then + tt=[] + end + [ok,tt]=FORTR(funam,tt,i,o) + if ~ok then + break, + end + [model,graphics,ok]=check_io(model,graphics,i,o,[],[]) + if ok then + model.sim(1)=funam + model.rpar=rpar + label(2)=tt + x.model=model + graphics.exprs=label + x.graphics=graphics + break + end + end + case "define" then + model=scicos_model() + model.sim=list(" ",1001) + model.in=1 + model.out=1 + model.evtin=[] + model.evtout=[] + model.state=[] + model.dstate=[] + model.rpar=[] + model.ipar=0 + model.blocktype="c" + model.firing=[] + model.dep_ut=[%t %f] + funam="forty" + label=list([sci2exp(model.in);sci2exp(model.out);.. + strcat(sci2exp(model.rpar));funam],list([])) + gr_i=[] + x=standard_define([4 2],model,label,gr_i) + end +endfunction diff --git a/macros/Misc/func_block.sci b/macros/Misc/func_block.sci new file mode 100644 index 00000000..03a1adec --- /dev/null +++ b/macros/Misc/func_block.sci @@ -0,0 +1,98 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=func_block(job,arg1,arg2) + //%Description + // job=='plot' : block drawing + // arg1 is block data structure + // arg2 :unused + // job=='getinputs' : return position and type of inputs ports + // arg1 is block data structure + // x : x coordinates of ports + // x : y coordinates of ports + // typ: type of ports + // job=='getoutputs' : return position and type of outputs ports + // arg1 is block data structure + // x : x coordinates of ports + // x : y coordinates of ports + // typ: type of ports + // job=='getorigin' : return block origin coordinates + // x : x coordinates of block origin + // x : y coordinates of block origin + // job=='set' : block parameters acquisition + // arg1 is block data structure + // x is returned block data structure + // job=='define' : corresponding block data structure initialisation + // arg1: name of block parameters acquisition macro + // x : block data structure + //%Block data-structure definition + // bl=list('Block',graphics,model,init,'standard_block') + // graphics=list([xo,yo],[l,h],orient,exprs) + // xo - x coordinate of block origin + // yo - y coordinate of block origin + // l - block width + // h - block height + // orient - boolean, specifies if block is tilded + // exprs - string block exprs + // model=list(eqns,#input,#output,#clk_input,#clk_output,state,.. + // rpar,ipar,typ [,firing]) + // eqns - function name (in string form if fortran routine) + // #input - number of inputs + // #output - number of outputs + // #clk_input - number of clock inputs + // #clk_output - number of clock outputs + // state - vector (column) of initial condition + // rpar - vector (column) of real parameters + // ipar - vector (column) of integer parameters + // typ - string: 'c' if block is continuous, 'd' if discrete + // 'z' if zero-crossing. + // firing - boolean initial clock firing if true + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + model=arg1.model; + graphics=arg1.graphics; + exprs=graphics.exprs + x=arg1 + model=x.model + [ok,mac,exprs]=genfunc(exprs) + if ok then + model.sim=mac + graphics.exprs=exprs + x.model=model + x.graphics=graphics + end + case "define" then + model=scicos_model() + model.sim=" " + model.in=1 + model.out=1 + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs="v=sin(u);y=u*v" + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Misc/generic_block.sci b/macros/Misc/generic_block.sci new file mode 100644 index 00000000..f40a589c --- /dev/null +++ b/macros/Misc/generic_block.sci @@ -0,0 +1,143 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=generic_block(job,arg1,arg2) + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + model=arg1.model; + graphics=arg1.graphics; + label=graphics.exprs + if size(label,"*")==14 then + label(9)=[], + end //compatiblity + while %t do + [ok,function_name,funtyp,i,o,ci,co,xx,z,rpar,ipar,auto0,depu,dept,lab]=.. + scicos_getvalue("Set GENERIC block parameters",.. + ["simulation function"; + "function type (0,1,2,..)"; + "input ports sizes"; + "output port sizes"; + "input event ports sizes"; + "output events ports sizes"; + "initial continuous state"; + "initial discrete state"; + "Real parameters vector"; + "Integer parameters vector"; + "initial firing vector (<0 for no firing)"; + "direct feedthrough (y or n)"; + "time dependence (y or n)"],.. + list("str",1,"vec",1,"vec",-1,"vec",-1,"vec",-1,"vec",-1,.. + "vec",-1,"vec",-1,"vec",-1,"vec",-1,"vec","sum(%6)",.. + "str",1,"str",1),label) + if ~ok then + break, + end + label=lab + function_name=stripblanks(function_name) + xx=xx(:); + z=z(:); + rpar=rpar(:); + ipar=int(ipar(:)); + i=int(i(:)); + o=int(o(:)); + ci=int(ci(:)); + co=int(co(:)); + funtyp=int(funtyp) + if funtyp<0 then + message("function type cannot be negative"); + ok=%f; + end + if [ci;co]<>[] then + if max([ci;co])>1 then + message("vector event links not supported"); + ok=%f; + end + end + depu=stripblanks(depu); + if part(depu,1)=="y" then + depu=%t; + else + depu=%f; + end + dept=stripblanks(dept); + if part(dept,1)=="y" then + dept=%t; + else + dept=%f; + end + dep_ut=[depu dept]; + if ok then + [model,graphics,ok]=check_io(model,graphics,i,o,ci,co) + end + if ok then + // AVERIFIER + if funtyp==3 then + needcompile=4; + end + model.sim=list(function_name,funtyp); + model.state=xx + model.dstate=z + model.rpar=rpar + model.ipar=ipar + // needcompile=4 AVERIFIER CANEMARCHEQUAVECFORTRAN + model.firing=auto0 + model.dep_ut=dep_ut + arg1.model=model + graphics.exprs=label + arg1.graphics=graphics + x=arg1 + break + end + end + needcompile=resume(needcompile) + case "define" then + model=scicos_model() + function_name="sinblk"; + funtyp=1; + model.sim=list(function_name,funtyp) + + model.in=1 + model.out=1 + model.evtin=[] + model.evtout=[] + model.state=[] + model.dstate=[] + model.rpar=[] + model.ipar=[] + model.blocktype="c" + model.firing=[] + model.dep_ut=[%t %f] + label=[function_name;sci2exp(funtyp); + sci2exp(model.in);sci2exp(model.out); + sci2exp(model.evtin);sci2exp(model.evtout); + sci2exp(model.state);sci2exp(model.dstate); + sci2exp(model.rpar);sci2exp(model.ipar); + sci2exp(model.firing);"y";"n"]; + gr_i=[] + x=standard_define([2 2],model,label,gr_i) + end +endfunction + diff --git a/macros/Misc/generic_block2.sci b/macros/Misc/generic_block2.sci new file mode 100644 index 00000000..ae05dc2b --- /dev/null +++ b/macros/Misc/generic_block2.sci @@ -0,0 +1,148 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=generic_block2(job,arg1,arg2) + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + model=arg1.model; + graphics=arg1.graphics; + label=graphics.exprs + if size(label,"*")==14 then + label(9)=[], + end //compatiblity + while %t do + [ok,function_name,funtyp,i,o,ci,co,xx,z,rpar,ipar,nmode,nzcr,auto0,depu,dept,lab]=.. + scicos_getvalue("Set GENERIC block parameters",.. + ["simulation function"; + "function type (0,1,2,..)"; + "input ports sizes"; + "output port sizes"; + "input event ports sizes"; + "output events ports sizes"; + "initial continuous state"; + "initial discrete state"; + "Real parameters vector"; + "Integer parameters vector"; + "number of modes"; + "number of zero_crossings"; + "initial firing vector (<0 for no firing)"; + "direct feedthrough (y or n)"; + "time dependence (y or n)"],.. + list("str",1,"vec",1,"vec",-1,"vec",-1,"vec",-1,"vec",-1,.. + "vec",-1,"vec",-1,"vec",-1,"vec",-1,"vec",1,"vec",1,"vec","sum(%6)",.. + "str",1,"str",1),label) + if ~ok then + break, + end + label=lab + function_name=stripblanks(function_name) + xx=xx(:); + z=z(:); + rpar=rpar(:); + ipar=int(ipar(:)); + i=int(i(:)); + o=int(o(:)); + ci=int(ci(:)); + co=int(co(:)); + funtyp=int(funtyp) + if funtyp<0 then + message("function type cannot be negative"); + ok=%f; + end + if [ci;co]<>[] then + if max([ci;co])>1 then + message("vector event links not supported"); + ok=%f; + end + end + depu=stripblanks(depu); + if part(depu,1)=="y" then + depu=%t; + else + depu=%f; + end + dept=stripblanks(dept); + if part(dept,1)=="y" then + dept=%t; + else + dept=%f; + end + dep_ut=[depu dept]; + if ok then + [model,graphics,ok]=check_io(model,graphics,i,o,ci,co) + end + if ok then + // AVERIFIER + if funtyp==3 then + needcompile=4; + end + model.sim=list(function_name,funtyp); + model.state=xx + model.dstate=z + model.rpar=rpar + model.ipar=ipar + // needcompile=4 AVERIFIER CANEMARCHEQUAVECFORTRAN + model.firing=auto0 + model.nzcross=nzcr + model.nmode=nmode + model.dep_ut=dep_ut + arg1.model=model + graphics.exprs=label + arg1.graphics=graphics + x=arg1 + break + end + end + needcompile=resume(needcompile) + case "define" then + model=scicos_model() + function_name="sinblk"; + funtyp=1; + model.sim=list(function_name,funtyp) + + model.in=1 + model.out=1 + model.evtin=[] + model.evtout=[] + model.state=[] + model.dstate=[] + model.rpar=[] + model.ipar=[] + model.blocktype="c" + model.firing=[] + model.dep_ut=[%t %f] + label=[function_name;sci2exp(funtyp); + sci2exp(model.in);sci2exp(model.out); + sci2exp(model.evtin);sci2exp(model.evtout); + sci2exp(model.state);sci2exp(model.dstate); + sci2exp(model.rpar);sci2exp(model.ipar); + sci2exp(model.nmode);sci2exp(model.nzcross); + sci2exp(model.firing);"y";"n"]; + gr_i=[] + x=standard_define([2 2],model,label,gr_i) + end +endfunction + diff --git a/macros/Misc/generic_block3.sci b/macros/Misc/generic_block3.sci new file mode 100644 index 00000000..1ed616d1 --- /dev/null +++ b/macros/Misc/generic_block3.sci @@ -0,0 +1,164 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=generic_block3(job,arg1,arg2) + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + model=arg1.model; + graphics=arg1.graphics; + label=graphics.exprs + if size(label,"*")==14 then + label(9)=[], + end //compatiblity + while %t do + [ok,function_name,funtyp,in,it,out,ot,ci,co,xx,z,oz,... + rpar,ipar,opar,nmode,nzcr,auto0,depu,dept,lab]=.. + scicos_getvalue("Set GENERIC block parameters",.. + ["Simulation function"; + "Function type (0,1,2,..)"; + "Input ports sizes"; + "Input ports type"; + "Output port sizes"; + "Output ports type"; + "Input event ports sizes"; + "Output events ports sizes"; + "Initial continuous state"; + "Initial discrete state"; + "Initial object state"; + "Real parameters vector"; + "Integer parameters vector"; + "Object parameters list"; + "Number of modes"; + "Number of zero crossings"; + "Initial firing vector (<0 for no firing)"; + "Direct feedthrough (y or n)"; + "Time dependence (y or n)"],.. + list("str",1,"vec",1,"mat",[-1 2],"vec",-1,"mat",[-1 2],"vec",-1,"vec",-1,"vec",-1,.. + "vec",-1,"vec",-1,"lis",-1,"vec",-1,"vec",-1,"lis",-1,"vec",1,"vec",1,"vec","sum(%8)",.. + "str",1,"str",1),label) + if ~ok then + break, + end + label=lab + function_name=stripblanks(function_name) + xx=xx(:); + z=z(:); + rpar=rpar(:); + ipar=int(ipar(:)); + ci=int(ci(:)); + co=int(co(:)); + funtyp=funtyp + if funtyp<0 then + message("function type cannot be negative"); + ok=%f; + end + if [ci;co]<>[] then + if max([ci;co])>1 then + message("vector event links not supported"); + ok=%f; + end + end + if type(opar)<>15 then + message("object parameter must be a list"); + ok=%f; + end + if type(oz)<>15 then + message("discrete object state must be a list"); + ok=%f; + end + depu=stripblanks(depu); + if part(depu,1)=="y" then + depu=%t; + else + depu=%f; + end + dept=stripblanks(dept); + if part(dept,1)=="y" then + dept=%t; + else + dept=%f; + end + dep_ut=[depu dept]; + if ok then + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),ci,co) + end + if ok then + if funtyp==3 then + needcompile=4; + end + model.sim=list(function_name,funtyp); + model.state=xx + model.dstate=z + model.odstate=oz + model.rpar=rpar + model.ipar=ipar + model.opar=opar + model.firing=auto0 + model.nzcross=nzcr + model.nmode=nmode + model.dep_ut=dep_ut + arg1.model=model + graphics.exprs=label + arg1.graphics=graphics + x=arg1 + break + end + end + needcompile=resume(needcompile) + case "define" then + model=scicos_model() + function_name="sinblk"; + funtyp=4; + model.sim=list(function_name,funtyp) + + model.in=1 + model.in2=1 + model.intyp=1 + model.out=1 + model.out2=1 + model.outtyp=1 + model.dep_ut=[%t %f] + label=[function_name;sci2exp(funtyp); + sci2exp([model.in model.in2]); + sci2exp(model.intyp); + sci2exp([model.out model.out2]) + sci2exp(model.outtyp); + sci2exp(model.evtin); + sci2exp(model.evtout); + sci2exp(model.state); + sci2exp(model.dstate); + sci2exp(model.odstate); + sci2exp(model.rpar); + sci2exp(model.ipar); + sci2exp(model.opar); + sci2exp(model.nmode); + sci2exp(model.nzcross); + sci2exp(model.firing);"y";"n"]; + gr_i=[] + x=standard_define([4 2],model,label,gr_i) + end +endfunction + diff --git a/macros/Misc/scifunc_block.sci b/macros/Misc/scifunc_block.sci new file mode 100644 index 00000000..6407be95 --- /dev/null +++ b/macros/Misc/scifunc_block.sci @@ -0,0 +1,161 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=scifunc_block(job,arg1,arg2) + //%Description + // job=='set' : block parameters acquisition + // arg1 is block data structure + // x is returned block data structure + // job=='define' : corresponding block data structure initialisation + // arg1: name of block parameters acquisition macro + // x : block data structure + //%Block data-structure definition + // bl=list('Block',graphics,model,init,'standard_block') + // graphics=list([xo,yo],[l,h],orient,label) + // xo - x coordinate of block origin + // yo - y coordinate of block origin + // l - block width + // h - block height + // orient - boolean, specifies if block is tilded + // label - string block label + // model=list(eqns,#input,#output,#clk_input,#clk_output,state,.. + // rpar,ipar,typ [,firing]) + // eqns - function name (in string form if fortran routine) + // #input - vector of input port sizes + // #output - vector of output port sizes + // #clk_input - vector of clock inputs port sizes + // #clk_output - vector of clock output port sizes + // state - vector (column) of initial condition + // rpar - vector (column) of real parameters + // ipar - vector (column) of integer parameters + // typ - string: 'c' if block is continuous, 'd' if discrete + // 'z' if zero-crossing. + // firing - vector of initial output event firing times + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + needcompile=0 + x=arg1 + model=arg1.model; + graphics=arg1.graphics; + exprs=graphics.exprs + + if size(exprs(1),"*")==8 then + exprs(1)(9)="0"; + end + while %t do + [ok,i,o,ci,co,xx,z,rpar,auto0,deptime,lab]=scicos_getvalue(.. + ["Set scifunc_block parameters";"only regular blocks supported"],.. + ["input ports sizes"; + "output port sizes"; + "input event ports sizes"; + "output events ports sizes"; + "initial continuous state"; + "initial discrete state"; + "System parameters vector"; + "initial firing vector (<0 for no firing)"; + "is block always active (0:no, 1:yes)" ],.. + list("vec",-1,"vec",-1,"vec",-1,"vec",-1,"vec",-1,"vec",-1,.. + "vec",-1,"vec","sum(%4)","vec",1),exprs(1)) + if ~ok then + break, + end + exprs(1)=lab + xx=xx(:); + z=z(:); + rpar=rpar(:) + nrp=prod(size(rpar)) + // create simulator + i=int(i(:)); + ni=size(i,1); + o=int(o(:)); + no=size(o,1); + ci=int(ci(:)); + nci=size(ci,1); + co=int(co(:)); + nco=size(co,1); + [ok,tt,dep_ut]=genfunc1(exprs(2),i,o,nci,nco,size(xx,1),size(z,1),.. + nrp,"c") + dep_ut(2)=(1==deptime) + if ~ok then + break, + end + [model,graphics,ok]=check_io(model,graphics,i,o,ci,co) + if ok then + auto=auto0 + model.state=xx + model.dstate=z + model.rpar=rpar + if model.ipar <> 0 then + model.opar=model.ipar; + model.ipar=0; + end + if or(model.opar<>tt) then + needcompile=4, + end + model.opar=tt + model.firing=auto + model.dep_ut=dep_ut + x.model=model + exprs(2)=tt + graphics.exprs=exprs + x.graphics=graphics + break + end + end + needcompile=resume(needcompile) + case "define" then + in=1 + out=1 + clkin=[] + clkout=[] + x0=[] + z0=[] + typ="c" + auto=[] + rpar=[] + + model=scicos_model() + model.sim=list("scifunc",3) + model.in=in + model.out=out + model.evtin=clkin + model.evtout=clkout + model.state=x0 + model.dstate=z0 + model.rpar=rpar + model.ipar=0 + model.opar=list() + model.blocktype=typ + model.firing=auto + model.dep_ut=[%t %f] + + exprs=list([sci2exp(in);sci2exp(out);sci2exp(clkin);sci2exp(clkout); + strcat(sci2exp(x0));strcat(sci2exp(z0)); + strcat(sci2exp(rpar));sci2exp(auto)],.. + list("y1=sin(u1)"," "," ","y1=sin(u1)"," "," "," ")) + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Misc/scifunc_block_m.sci b/macros/Misc/scifunc_block_m.sci new file mode 100644 index 00000000..be0b17ae --- /dev/null +++ b/macros/Misc/scifunc_block_m.sci @@ -0,0 +1,143 @@ +// Scicos +// +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See the file ../license.txt +// + +function [x,y,typ]=scifunc_block_m(job,arg1,arg2) + //%Description + // job=='set' : block parameters acquisition + // arg1 is block data structure + // x is returned block data structure + // job=='define' : corresponding block data structure initialisation + // arg1: name of block parameters acquisition macro + // x : block data structure + // + x=[]; + y=[]; + typ=[]; + select job + case "set" then + needcompile=0 + x=arg1 + model=arg1.model; + graphics=arg1.graphics; + exprs=graphics.exprs + + while %t do + [ok,i,o,ci,co,xx,z,rpar,auto0,deptime,lab]=scicos_getvalue(.. + ["Set scifunc_block parameters";"only regular blocks supported"],.. + ["input ports sizes"; + "output port sizes"; + "input event ports sizes"; + "output events ports sizes"; + "initial continuous state"; + "initial discrete state"; + "System parameters vector"; + "initial firing vector (<0 for no firing)"; + "is block always active (0:no, 1:yes)"],.. + list("mat",[-1 2],"mat",[-2 2],"vec",-1,"vec",-1,"vec",-1,"vec",-1,.. + "vec",-1,"vec",-1,"vec",1),exprs(1)) + if ~ok then + break, + end + exprs(1)=lab + xx=xx(:); + z=z(:); + rpar=rpar(:) + it=ones(1,size(i,1)) + ot=ones(1,size(o,1)) + nrp=prod(size(rpar)) + // create simulator + //i=int(i(:)); + ni=size(i,1); + //o=int(o(:)); + no=size(o,1); + ci=int(ci(:)); + nci=size(ci,1); + co=int(co(:)); + nco=size(co,1); + [ok,tt,dep_ut]=genfunc2(exprs(2),i,o,nci,nco,size(xx,1),size(z,1),.. + nrp,"c") + dep_ut(2)=(1==deptime) + if ~ok then + break, + end + //[model,graphics,ok]=check_io(model,graphics,i,o,ci,co) + [model,graphics,ok]=set_io(model,graphics,list(i,it),list(o,ot),ci,co) + if ok then + auto=auto0 + model.state=xx + model.dstate=z + model.rpar=rpar + if model.ipar <> 0 then + model.opar=model.ipar; + model.ipar=0; + end + if or(model.opar<>tt) then + needcompile=4, + end + model.opar=tt + model.firing=auto + model.dep_ut=dep_ut + x.model=model + exprs(2)=tt + graphics.exprs=exprs + x.graphics=graphics + break + end + end + needcompile=resume(needcompile) + case "define" then + in=1 + out=1 + clkin=[] + clkout=[] + x0=[] + z0=[] + typ="c" + auto=[] + rpar=[] + it=1 + model=scicos_model() + model.sim=list("scifunc",3) + model.in=in + model.in2=in + model.intyp=it + model.out=out + model.out2=out + model.outtyp=it + model.evtin=clkin + model.evtout=clkout + model.state=x0 + model.dstate=z0 + model.rpar=rpar + model.ipar=0; + model.opar=list(); + model.blocktype=typ + model.firing=auto + model.dep_ut=[%t %f] + + exprs=list([sci2exp([in in]);sci2exp([out out]);sci2exp(clkin);sci2exp(clkout); + strcat(sci2exp(x0));strcat(sci2exp(z0)); + strcat(sci2exp(rpar));sci2exp(auto);sci2exp(0)],.. + list("y1=sin(u1)"," "," ","y1=sin(u1)"," "," "," ")) + gr_i=[] + x=standard_define([4 2],model,exprs,gr_i) + end +endfunction |