diff options
Diffstat (limited to 'macros/Linear')
36 files changed, 3904 insertions, 0 deletions
diff --git a/macros/Linear/BIGSOM_f.sci b/macros/Linear/BIGSOM_f.sci new file mode 100644 index 00000000..abfb8f35 --- /dev/null +++ b/macros/Linear/BIGSOM_f.sci @@ -0,0 +1,68 @@ +// 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]=BIGSOM_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics + model=arg1.model + exprs=graphics.exprs + while %t do + [ok,sgn,exprs]=scicos_getvalue("Set sum block parameters",.. + "Inputs ports signs/gain",list("vec",-1),exprs) + if ~ok then + break + end + + in = -ones(size(sgn,"*"),1) + + //** Patch: check added + [model,graphics,ok] = check_io(model,graphics,in,-1,[],[]); + if ok then + model.rpar = sgn(:); + graphics.exprs = exprs; + + x.graphics = graphics; + x.model = model ; + break + end + + end + case "define" then + sgn=[1;1] + model=scicos_model() + model.sim=list("sum",2) + model.in=[-1;-1] + model.out=-1 + model.rpar=sgn + model.blocktype="c" + model.dep_ut=[%t %f] + + + exprs=sci2exp(sgn) + gr_i=[] + x=standard_define([2 3],model, exprs,gr_i) + end +endfunction diff --git a/macros/Linear/CLINDUMMY_f.sci b/macros/Linear/CLINDUMMY_f.sci new file mode 100644 index 00000000..5fea8b0c --- /dev/null +++ b/macros/Linear/CLINDUMMY_f.sci @@ -0,0 +1,41 @@ +// 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]=CLINDUMMY_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + case "define" then + x0=0; + model=scicos_model() + model.sim=list("cdummy",4) + model.state=x0 + model.blocktype="c" + model.firing=[] + model.dep_ut=[%f %t] + + gr_i=[] + x=standard_define([3 2],model,[],gr_i) + end +endfunction diff --git a/macros/Linear/CLR.sci b/macros/Linear/CLR.sci new file mode 100644 index 00000000..22238125 --- /dev/null +++ b/macros/Linear/CLR.sci @@ -0,0 +1,99 @@ +// 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]=CLR(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics;exprs=graphics.exprs + model=arg1.model; + x0=model.state + rpar=model.rpar + ns=prod(size(x0));nin=1;nout=1 + %scicos_context=%scicos_context; //copy the semi-global variable locally + %scicos_context.s=%s //add s definition to the context + while %t do + [ok,num,den,exprs]=scicos_getvalue("Set continuous SISO transfer parameters",.. + ["Numerator (s)"; + "Denominator (s)"],.. + list("pol",1,"pol",1),exprs) + + + if ~ok then + break, + end + if degree(num)>degree(den) then + message("Transfer function must be proper or strictly proper.") + ok=%f + end + if ok then + H=cont_frm(num,den) + [A,B,C,D]=H(2:5); + graphics.exprs=exprs; + [ns1,ns1]=size(A) + rpar=[matrix(A,ns1*ns1,1); + matrix(B,ns1,1); + matrix(C,ns1,1); + D] + if norm(D,1)<>0 then + mmm=[%t %t]; + else + mmm=[%f %t]; + end + if or(model.dep_ut<>mmm) then + model.dep_ut=mmm, + end + if ns1<=ns then + x0=x0(1:ns1) + else + x0(ns1,1)=0 + end + model.state=x0 + model.rpar=rpar + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + x0=0; + A=-1; + B=1; + C=1; + D=0; + exprs=["1";"1+s"] + model=scicos_model() + model.sim=list("csslti4",4) + model.in=1 + model.out=1 + model.state=x0 + model.rpar=[A(:);B(:);C(:);D(:)] + model.blocktype="c" + model.dep_ut=[%f %t] + + gr_i=[] + + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/CLR_f.sci b/macros/Linear/CLR_f.sci new file mode 100644 index 00000000..6574f0be --- /dev/null +++ b/macros/Linear/CLR_f.sci @@ -0,0 +1,103 @@ +// 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]=CLR_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + x0=model.state + rpar=model.rpar + ns=prod(size(x0)); + nin=1; + nout=1 + %scicos_context=%scicos_context; //copy the semi-global variable locally + %scicos_context.s=%s //add s definition to the context + + while %t do + [ok,num,den,exprs]=scicos_getvalue("Set continuous SISO transfer parameters",.. + ["Numerator (s)"; + "Denominator (s)"],.. + list("pol",1,"pol",1),exprs) + + + if ~ok then + break, + end + if degree(num)>degree(den) then + message("Transfer must be proper or strictly proper") + ok=%f + end + if ok then + H=cont_frm(num,den) + [A,B,C,D]=H(2:5); + graphics.exprs=exprs; + [ns1,ns1]=size(A) + rpar=[matrix(A,ns1*ns1,1); + matrix(B,ns1,1); + matrix(C,ns1,1); + D] + if norm(D,1)<>0 then + mmm=[%t %t]; + else + mmm=[%f %t]; + end + if or(model.dep_ut<>mmm) then + model.dep_ut=mmm, + end + if ns1<=ns then + x0=x0(1:ns1) + else + x0(ns1,1)=0 + end + model.state=x0 + model.rpar=rpar + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + x0=0; + A=-1; + B=1; + C=1; + D=0; + exprs=["1";"1+s"] + model=scicos_model() + model.sim=list("csslti",1) + model.in=1 + model.out=1 + model.state=x0 + model.rpar=[A(:);B(:);C(:);D(:)] + model.blocktype="c" + model.dep_ut=[%f %t] + + gr_i=[] + + x=standard_define([2.5 2.5],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/CLSS.sci b/macros/Linear/CLSS.sci new file mode 100644 index 00000000..f7a36b97 --- /dev/null +++ b/macros/Linear/CLSS.sci @@ -0,0 +1,123 @@ +// 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]=CLSS(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + graphics=arg1.graphics; + exprs=graphics.exprs + if size(exprs,"*")==7 then + exprs=exprs([1:4 7]), + end //compatibility + model=arg1.model; + while %t do + [ok,A,B,C,D,x0,exprs]=scicos_getvalue("Set continuous linear system parameters",.. + ["A matrix"; + "B matrix"; + "C matrix"; + "D matrix"; + "Initial state"],.. + list("mat",[-1,-1],.. + "mat",["size(%1,2)","-1"],.. + "mat",["-1","size(%1,2)"],.. + "mat",[-1 -1],.. + "vec","size(%1,2)"),.. + exprs) + if ~ok then + break, + end + out=size(C,1); + if out==0 then + out=[], + end + in=size(B,2); + if in==0 then + in=[], + end + [ms,ns]=size(A) + okD=%t + if size(D,"*")<>size(C,1)*size(B,2) then + if size(D,"*")==1 then + D = D*ones(C*B) ; + elseif size(D,"*")==0 then + D = zeros(C*B) ; + else + okD = %f ; + end + end + if ms<>ns|~okD then + message(_("Matrix A is not square or D has wrong dimension")) + else + [model,graphics,ok]=check_io(model,graphics,in,out,[],[]) + if ok then + graphics.exprs=exprs; + rpar=[A(:);B(:);C(:);D(:)]; + if D<>[] then + if norm(D,1)<>0 then + mmm=[%t %t]; + else + mmm=[%f %t]; + end + if or(model.dep_ut<>mmm) then + model.dep_ut=mmm, + end + else + model.dep_ut=[%f %t]; + end + model.state=x0(:); + model.rpar=rpar + x.graphics=graphics; + x.model=model + break + end + end + end + case "define" then + x0=0; + A=-1; + B=1; + C=1; + D=0; + in=1; + out=1 + + model=scicos_model() + model.sim=list("csslti4",4) + model.in=in + model.out=out + model.state=x0 + model.rpar=[A(:);B(:);C(:);D(:)]; + model.blocktype="c" + model.dep_ut=[%f %t] + + exprs=[strcat(sci2exp(A)); + strcat(sci2exp(B)); + strcat(sci2exp(C)); + strcat(sci2exp(D)); + strcat(sci2exp(x0))] + gr_i=[] + x=standard_define([4 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/CLSS_f.sci b/macros/Linear/CLSS_f.sci new file mode 100644 index 00000000..279ffbfb --- /dev/null +++ b/macros/Linear/CLSS_f.sci @@ -0,0 +1,113 @@ +// 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]=CLSS_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + graphics=arg1.graphics; + exprs=graphics.exprs + if size(exprs,"*")==7 then + exprs=exprs([1:4 7]), + end //compatibility + model=arg1.model; + while %t do + [ok,A,B,C,D,x0,exprs]=scicos_getvalue("Set continuous linear system parameters",.. + ["A matrix"; + "B matrix"; + "C matrix"; + "D matrix"; + "Initial state"],.. + list("mat",[-1,-1],.. + "mat",["size(%1,2)","-1"],.. + "mat",["-1","size(%1,2)"],.. + "mat",[-1 -1],.. + "vec","size(%1,2)"),.. + exprs) + if ~ok then + break, + end + out=size(C,1); + if out==0 then + out=[], + end + in=size(B,2); + if in==0 then + in=[], + end + [ms,ns]=size(A) + if ms<>ns then + message("A matrix must be square") + else + [model,graphics,ok]=check_io(model,graphics,in,out,[],[]) + if ok then + graphics.exprs=exprs; + rpar=[A(:);B(:);C(:);D(:)]; + if D<>[] then + if norm(D,1)<>0 then + mmm=[%t %t]; + else + mmm=[%f %t]; + end + if or(model.dep_ut<>mmm) then + model.dep_ut=mmm, + end + else + model.dep_ut=[%f %t]; + end + model.state=x0(:); + model.rpar=rpar + x.graphics=graphics; + x.model=model + break + end + end + end + case "define" then + x0=0; + A=-1; + B=1; + C=1; + D=0; + in=1; + out=1 + + model=scicos_model() + model.sim=list("csslti",1) + model.in=in + model.out=out + model.state=x0 + model.rpar=[A(:);B(:);C(:);D(:)]; + model.blocktype="c" + model.dep_ut=[%f %t] + + exprs=[strcat(sci2exp(A)); + strcat(sci2exp(B)); + strcat(sci2exp(C)); + strcat(sci2exp(D)); + strcat(sci2exp(x0))] + gr_i=[] + x=standard_define([4 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/DELAYV_f.sci b/macros/Linear/DELAYV_f.sci new file mode 100644 index 00000000..444e4427 --- /dev/null +++ b/macros/Linear/DELAYV_f.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 +// + +function [x,y,typ]=DELAYV_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + nin=model.in(1) + z0=model.dstate; + zz0=z0(1:$-1); + told=z0($); + + while %t do + [ok,nin,zz0,T,exprs]=scicos_getvalue("Set delay parameters",.. + ["Number of inputs"; + "Register initial condition"; + "Max delay"],.. + list("vec",1,"vec",-1,"vec",1),.. + exprs); + if ~ok then + break, + end + if size(zz0,"*")<2 then + message("Register length must be at least 2") + ok=%f + end + if T<=0 then + message("Delay must be positive") + ok=%f + end + + if ok then + [model,graphics,ok]=check_io(model,graphics,[nin;1],nin,1,[1;1]) + end + if ok then + graphics.exprs=exprs; + model.dstate=[zz0(:);told]; + model.rpar=T/(size(zz0,"*")); + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + nin=1 + z0=zeros(11,1); + zz0=z0(1:$-1) + T=1 + + model=scicos_model() + model.sim=list("delayv",1) + model.in=[nin;1] + model.out=nin + model.evtin=1 + model.evtout=[1;1] + model.dstate=z0 + model.rpar=T/(size(zz0,"*")) + model.blocktype="d" + model.firing=[0 -1] + model.dep_ut=[%t %f] + + exprs=[string(nin);strcat(string(z0(1:$-1)),";");string(T)]; + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/DELAY_f.sci b/macros/Linear/DELAY_f.sci new file mode 100644 index 00000000..38f6c06f --- /dev/null +++ b/macros/Linear/DELAY_f.sci @@ -0,0 +1,173 @@ +// 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]=DELAY_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + // look for the children blocks + ppath = list(0,0); + for i=1:length(arg1.model.rpar.objs) do + o = arg1.model.rpar.objs(i); + if typeof(o) == "Block" & o.gui == "REGISTER_f" then + ppath(1) = i; + end + if typeof(o) == "Block" & o.gui == "EVTDLY_f" then + ppath(2) = i; + end + if and(ppath <> list(0,0)) then + break; + end + end + + // paths to updatable parameters or states + x=arg1 + + newpar=list(); + register=x.model.rpar.objs(ppath(1)) //data structure of register block + evtdly=x.model.rpar.objs(ppath(2)) //data structure of evtdly block + register_exprs=register.graphics.exprs + evtdly_exprs=evtdly.graphics.exprs + exprs=[evtdly_exprs(1);register_exprs] + while %t do + [ok,dt,z0,exprs]=scicos_getvalue(["This block implements as a discretized delay"; + "it is consist of a shift register and a clock"; + "value of the delay is given by;" + "the discretization time step multiplied by the"; + "number-1 of state of the register"],.. + ["Discretization time step"; + "Register initial state"],list("vec",1,"vec",-1),exprs) + if ~ok then + break, + end + mess=[] + if prod(size(z0))<1 then + mess=[mess;"Register length must be at least 1";" "] + ok=%f + end + if dt<=0 then + mess=[mess;"Discretization time step must be positive";" "] + ok=%f + end + if ~ok then + message(mess); + else + //Change the clock + evtdly.graphics.exprs(1)=exprs(1); + // evtdly.model.firing=0; //initial delay firing date + + if evtdly.model.rpar<>dt then //Discretization time step + evtdly.model.rpar=dt + newpar($+1)=ppath(2) // notify clock changes + end + x.model.rpar.objs(ppath(2))=evtdly + + //Change the register + register.graphics.exprs=exprs(2) + if or(register.model.dstate<>z0(:)) then //Register initial state + register.model.dstate=z0(:) + newpar($+1)=ppath(1) // notify register changes + end + x.model.rpar.objs(ppath(1))=register + break + end + end + needcompile=0 + y=needcompile + typ=newpar + case "define" then + evtdly=EVTDLY_f("define") + evtdly.graphics.orig=[243,296] + evtdly.graphics.sz=[40,40] + evtdly.graphics.flip=%t + evtdly.graphics.exprs=["0.1";"0"] + evtdly.graphics.pein=10 + evtdly.graphics.peout=7 + evtdly.model.rpar=0.1 + evtdly.model.firing=0 + + register=REGISTER_f("define") + register.graphics.orig=[238,195] + register.graphics.sz=[50,50] + register.graphics.flip=%t + register.graphics.exprs="0;0;0;0;0;0;0;0;0;0" + register.graphics.pin=6 + register.graphics.pout=5 + register.graphics.pein=9 + + input_port=IN_f("define") + input_port.graphics.orig=[92,210] + input_port.graphics.sz=[20,20] + input_port.graphics.flip=%t + input_port.graphics.exprs=["1";"1"] + input_port.graphics.pout=6 + input_port.model.ipar=1 + + output_port=OUT_f("define") + output_port.graphics.orig=[440,210] + output_port.graphics.sz=[20,20] + output_port.graphics.flip=%t + output_port.graphics.exprs=["1";"1"] + output_port.graphics.pin=5 + output_port.model.ipar=1 + + split=CLKSPLIT_f("define") + split.graphics.orig=[263;271.2] + split.graphics.pein=7, + split.graphics.peout=[9;10] + + diagram=scicos_diagram(); + diagram.objs(1)=input_port + diagram.objs(2)=output_port + diagram.objs(3)=register + diagram.objs(4)=evtdly + diagram.objs(5)=scicos_link(xx=[296.6;440],yy=[220;220],.. + from=[3,1],to=[2,1]) + diagram.objs(6)=scicos_link(xx=[112;229.4],yy=[220;220],.. + from=[1,1],to=[3,1]) + diagram.objs(7)=scicos_link(xx=[263;263],yy=[290.3;271.2],ct=[5,-1],.. + from=[4,1],to=[8,1]) + diagram.objs(8)=split + diagram.objs(9)=scicos_link(xx=[263;263],yy=[271.2;250.7],ct=[5,-1],.. + from=[8,1],to=[3,1]) + diagram.objs(10)=scicos_link(xx=[263;308.6;308.6;263;263],.. + yy=[271.2;271.2;367;367;341.7],.. + ct=[5,-1],from=[8,2],to=[4,1]) + x=scicos_block() + x.gui="DELAY_f" + x.graphics.sz=[2,2] + x.graphics.gr_i=[] + x.graphics.pin=0 + x.graphics.pout=0 + x.model.sim="csuper" + x.model.in=1 + x.model.out=1 + x.model.blocktype="h" + x.model.dep_ut=[%f %f] + x.model.rpar=diagram + x.graphics.in_implicit=["E"] + x.graphics.in_style="" + x.graphics.out_implicit=["E"] + x.graphics.out_style="" + end +endfunction diff --git a/macros/Linear/DERIV.sci b/macros/Linear/DERIV.sci new file mode 100644 index 00000000..67ef0657 --- /dev/null +++ b/macros/Linear/DERIV.sci @@ -0,0 +1,43 @@ +// 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] = DERIV(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + case "define" then + model=scicos_model() + model.sim=list("deriv",4) + model.in=-1 + model.out=-1 + model.blocktype="x" + model.dep_ut=[%t %f] + + exprs=[] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction + + diff --git a/macros/Linear/DIFF_c.sci b/macros/Linear/DIFF_c.sci new file mode 100644 index 00000000..298879bc --- /dev/null +++ b/macros/Linear/DIFF_c.sci @@ -0,0 +1,80 @@ +// Scicos +// +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA - METALAU Project <scicos@inria.fr> +// Copyright (C) 2009-2010 - DIGITEO - Clément DAVID +// +// 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_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,exprs]=scicos_getvalue("Set continuous linear system parameters",.. + ["Initial state";"Initial Derivative"],list("vec",-1,"vec",-1),exprs) + if ~ok then + break, + end + x0=x0(:); + N=size(x0,"*"); + xd0=xd0(:); + Nxd=size(xd0,"*"); + if (N~=Nxd) then + message("Incompatible sizes: states and their derivatives should have the same size ") + ask_again=%t + end + if (N<=0 & ~ask_again) then + x_message("number of states must be > 0 ") + ask_again=%t + end + + if ~ask_again then + graphics.exprs=exprs + model.state=[x0;xd0]; + model.out=[N] + model.in=N + x.graphics=graphics; + x.model=model + break + end + end + x.model.firing=[] //compatibility + case "define" then + x0=[0;0] + model=scicos_model() + model.sim=list("diffblk_c",10004) + 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/Linear/DLR.sci b/macros/Linear/DLR.sci new file mode 100644 index 00000000..78d350ff --- /dev/null +++ b/macros/Linear/DLR.sci @@ -0,0 +1,99 @@ +// 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]=DLR(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + x0=model.dstate; + ns=prod(size(x0)); + %scicos_context=%scicos_context; //copy the semi-global variable locally + %scicos_context.z=%z //add z definition to the context + while %t do + [ok,num,den,exprs]=scicos_getvalue("Set discrete SISO transfer parameters",.. + ["Numerator (z)"; + "Denominator (z)"],.. + list("pol",1,"pol",1),exprs) + if ~ok then + break, + end + if degree(num)>degree(den) then + message("Transfer function must be proper") + ok=%f + end + if ok then + H=cont_frm(num,den) + [A,B,C,D]=H(2:5); + graphics.exprs=exprs; + [ns1,ns1]=size(A) + if ns1<=ns then + x0=x0(1:ns1) + else + x0(ns1,1)=0 + end + rpar=[A(:); + B(:); + C(:); + D(:)] + model.dstate=x0 + model.rpar=rpar + if norm(D,1)<>0 then + mmm=[%t %f]; + else + mmm=[%f %f]; + end + if or(model.dep_ut<>mmm) then + model.dep_ut=mmm, + end + x.graphics=graphics; + x.model=model + break + end + end + x.model.firing=[] //compatibility + case "define" then + x0=0; + A=-1; + B=1; + C=1; + D=0; + exprs=["1";"1+z"] + + model=scicos_model() + model.sim=list("dsslti4",4) + model.in=1 + model.out=1 + model.evtin=1 + model.dstate=x0(:) + model.rpar=[A(:);B(:);C(:);D(:)] + model.blocktype="d" + model.dep_ut=[%f %f] + + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/DLR_f.sci b/macros/Linear/DLR_f.sci new file mode 100644 index 00000000..7a9c634c --- /dev/null +++ b/macros/Linear/DLR_f.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]=DLR_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + x0=model.dstate; + ns=prod(size(x0)); + %scicos_context=%scicos_context; //copy the semi-global variable locally + %scicos_context.z=%z //add z definition to the context + while %t do + [ok,num,den,exprs]=scicos_getvalue("Set discrete SISO transfer parameters",.. + ["Numerator (z)"; + "Denominator (z)"],.. + list("pol",1,"pol",1),exprs) + if ~ok then + break, + end + if degree(num)>degree(den) then + message("Transfer must be proper") + ok=%f + end + if ok then + H=cont_frm(num,den) + [A,B,C,D]=H(2:5); + graphics.exprs=exprs; + [ns1,ns1]=size(A) + if ns1<=ns then + x0=x0(1:ns1) + else + x0(ns1,1)=0 + end + rpar=[A(:); + B(:); + C(:); + D(:)] + model.dstate=x0 + model.rpar=rpar + if norm(D,1)<>0 then + mmm=[%t %f]; + else + mmm=[%f %f]; + end + if or(model.dep_ut<>mmm) then + model.dep_ut=mmm,end + x.graphics=graphics; + x.model=model + break + end + end + x.model.firing=[] //compatibility + case "define" then + x0=0; + A=-1; + B=1; + C=1; + D=0; + exprs=["1";"1+z"] + + model=scicos_model() + model.sim="dsslti" + model.in=1 + model.out=1 + model.evtin=1 + model.dstate=x0(:) + model.rpar=[A(:);B(:);C(:);D(:)] + model.blocktype="d" + model.dep_ut=[%f %f] + + gr_i=[] + x=standard_define([2.5 2.5],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/DLSS.sci b/macros/Linear/DLSS.sci new file mode 100644 index 00000000..ec3ee9e4 --- /dev/null +++ b/macros/Linear/DLSS.sci @@ -0,0 +1,120 @@ +// 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]=DLSS(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + graphics=arg1.graphics; + exprs=graphics.exprs + if size(exprs,"*")==7 then + exprs=exprs([1:4 7]), + end //compatibility + model=arg1.model; + while %t do + [ok,A,B,C,D,x0,exprs]=scicos_getvalue("Set discrete linear system parameters",.. + ["A matrix"; + "B matrix"; + "C matrix"; + "D matrix"; + "Initial state"],.. + list("mat",[-1,-1],.. + "mat",["size(%1,2)","-1"],.. + "mat",["-1","size(%1,2)"],.. + "mat",[-1 -1],.. + "vec","size(%1,2)"),.. + exprs) + if ~ok then + break, + end + out=size(C,1); + if out==0 then + out=[], + end + in=size(B,2); + if in==0 then + in=[], + end + [ms,ns]=size(A) + okD=%t + if size(D,"*")<>size(C,1)*size(B,2) then + if size(D,"*")==1 then + D = D*ones(C*B) ; + elseif size(D,"*")==0 then + D = zeros(C*B) ; + else + okD=%f + end + end + if ms<>ns|~okD then + message(_("Matrix A is not square or D has wrong dimension")) + else + [model,graphics,ok]=check_io(model,graphics,in,out,1,[]) + if ok then + graphics.exprs=exprs; + rpar=[A(:);B(:);C(:);D(:)]; + if D<>[] then + if norm(D,1)<>0 then + mmm=[%t %f]; + else + mmm=[%f %f]; + end + if or(model.dep_ut<>mmm) then + model.dep_ut=mmm,end + else + model.dep_ut=[%f %f]; + end + model.dstate=x0(:); + model.rpar=rpar + x.graphics=graphics; + x.model=model + break + end + end + end + case "define" then + x0=0; + A=-1; + B=1; + C=1; + D=0; + model=scicos_model() + model.sim=list("dsslti4",4) + model.in=1 + model.out=1 + model.evtin=1 + model.dstate=x0(:) + model.rpar=[A(:);B(:);C(:);D(:)] + model.blocktype="d" + model.dep_ut=[%f %f] + + exprs=[strcat(sci2exp(A)); + strcat(sci2exp(B)); + strcat(sci2exp(C)); + strcat(sci2exp(D)); + strcat(sci2exp(x0))] + gr_i=[] + x=standard_define([4 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/DLSS_f.sci b/macros/Linear/DLSS_f.sci new file mode 100644 index 00000000..da1e57b9 --- /dev/null +++ b/macros/Linear/DLSS_f.sci @@ -0,0 +1,107 @@ +// 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]=DLSS_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1 + graphics=arg1.graphics; + exprs=graphics.exprs + if size(exprs,"*")==7 then + exprs=exprs([1:4 7]), + end //compatibility + model=arg1.model; + while %t do + [ok,A,B,C,D,x0,exprs]=scicos_getvalue("Set discrete linear system parameters",.. + ["A matrix"; + "B matrix"; + "C matrix"; + "D matrix"; + "Initial state"],.. + list("mat",[-1,-1],.. + "mat",["size(%1,2)","-1"],.. + "mat",["-1","size(%1,2)"],.. + "mat",[-1 -1],.. + "vec","size(%1,2)"),.. + exprs) + if ~ok then + break, + end + out=size(C,1); + if out==0 then + out=[], + end + in=size(B,2); + if in==0 then + in=[], + end + [ms,ns]=size(A) + if ms<>ns then + message("A matrix must be square") + else + [model,graphics,ok]=check_io(model,graphics,in,out,1,[]) + if ok then + graphics.exprs=exprs; + rpar=[A(:);B(:);C(:);D(:)]; + if D<>[] then + if norm(D,1)<>0 then + mmm=[%t %f]; + else + mmm=[%f %f]; + end + if or(model.dep_ut<>mmm) then + model.dep_ut=mmm, + end + else + model.dep_ut=[%f %f]; + end + model.dstate=x0(:); + model.rpar=rpar + x.graphics=graphics; + x.model=model + break + end + end + end + case "define" then + x0=0;A=-1;B=1;C=1;D=0; + model=scicos_model() + model.sim=list("dsslti",1) + model.in=1 + model.out=1 + model.evtin=1 + model.dstate=x0(:) + model.rpar=[A(:);B(:);C(:);D(:)] + model.blocktype="d" + model.dep_ut=[%f %f] + + exprs=[strcat(sci2exp(A)); + strcat(sci2exp(B)); + strcat(sci2exp(C)); + strcat(sci2exp(D)); + strcat(sci2exp(x0))] + gr_i=[] + x=standard_define([4 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/DOLLAR.sci b/macros/Linear/DOLLAR.sci new file mode 100644 index 00000000..c9e48fde --- /dev/null +++ b/macros/Linear/DOLLAR.sci @@ -0,0 +1,115 @@ +// 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]=DOLLAR(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + //backward compatibility + if size(exprs,"*")<2 then + exprs(2)="0"; + end + while %t do + [ok,a,inh,exprs]=scicos_getvalue("Set 1/z block parameters",.. + ["initial condition";"Inherit (no:0, yes:1)"],... + list("mat",[-1 -2],"vec",-1),exprs) + if ~ok then + break, + end + out=[size(a,1) size(a,2)]; + if out==0 then + out=[], + end + in=out + model.sim=list("dollar4_m",4) + model.odstate=list(a); + model.dstate=[]; + if type ((a)==1) then + if isreal(a) then + it=1; + ot=1; + if (size(a,1)==1 | size(a,2)==1) then + model.sim=list("dollar4",4); + model.dstate=a(:); + model.odstate=list(); + end + else + it=2; + ot=2; + end + elseif (typeof(a)=="int32") then + it=3; + ot=3; + elseif (typeof(a)=="int16") then + it=4; + ot=4; + elseif (typeof(a)=="int8") then + it=5; + ot=5; + elseif (typeof(a)=="uint32") then + it=6; + ot=6; + elseif (typeof(a)=="uint16") then + it=7; + ot=7; + elseif (typeof(a)=="uint8") then + it=8; + ot=8; + else + message ("type is not recognized"); + ok=%f; + end + if ok then + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),ones(1-inh,1),[]) + end + if ok then + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model + break + end + end + + case "define" then + z=0 + inh=0 + in=1 + exprs=string([z;inh]) + model=scicos_model() + model.sim=list("dollar4",4) + model.in=in + model.out=in + model.evtin=1-inh + model.dstate=z + model.blocktype="d" + model.dep_ut=[%f %f] + + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction + diff --git a/macros/Linear/DOLLAR_f.sci b/macros/Linear/DOLLAR_f.sci new file mode 100644 index 00000000..0f6dc285 --- /dev/null +++ b/macros/Linear/DOLLAR_f.sci @@ -0,0 +1,80 @@ +// 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]=DOLLAR_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + //backward compatibility + if size(exprs,"*")<2 then + exprs(2)="0"; + end + while %t do + [ok,a,inh,exprs]=scicos_getvalue("Set 1/z block parameters",.. + ["initial condition";"Inherit (no:0, yes:1)"],... + list("vec",-1,"vec",-1),exprs) + if ~ok then + break, + end + out=size(a,"*"); + if out==0 then + out=[], + end + in=out + + if ok then + [model,graphics,ok]=check_io(model,graphics,-1,-1,ones(1-inh,1),[]) + end + + if ok then + graphics.exprs=exprs; + model.dstate=a; + model.in=in; + model.out=out + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + z=0 + inh=0 + in=1 + exprs=string([z;inh]) + model=scicos_model() + model.sim="dollar" + model.in=in + model.out=in + model.evtin=1-inh + model.dstate=z + model.blocktype="d" + model.dep_ut=[%f %f] + + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/DOLLAR_m.sci b/macros/Linear/DOLLAR_m.sci new file mode 100644 index 00000000..10db92dc --- /dev/null +++ b/macros/Linear/DOLLAR_m.sci @@ -0,0 +1,115 @@ +// 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]=DOLLAR_m(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + //backward compatibility + if size(exprs,"*")<2 then + exprs(2)="0"; + end + while %t do + [ok,a,inh,exprs]=scicos_getvalue("Set 1/z block parameters",.. + ["initial condition";"Inherit (no:0, yes:1)"],... + list("mat",[-1 -2],"vec",-1),exprs) + if ~ok then + break, + end + out=[size(a,1) size(a,2)]; + if out==0 then + out=[], + end + in=out + model.sim=list("dollar4_m",4) + model.odstate=list(a); + model.dstate=[]; + if (type(a)==1) then + if isreal(a) then + it=1; + ot=1; + if (size(a,1)==1 | size(a,2)==1) then + model.sim=list("dollar4",4); + model.dstate=a(:); + model.odstate=list(); + end + else + it=2; + ot=2; + end + elseif (typeof(a)=="int32") then + it=3; + ot=3; + elseif (typeof(a)=="int16") then + it=4; + ot=4; + elseif (typeof(a)=="int8") then + it=5; + ot=5; + elseif (typeof(a)=="uint32") then + it=6; + ot=6; + elseif (typeof(a)=="uint16") then + it=7; + ot=7; + elseif (typeof(a)=="uint8") then + it=8; + ot=8; + else + message ("type is not recognized"); + ok=%f; + end + if ok then + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),ones(1-inh,1),[]) + end + if ok then + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model + break + end + end + + case "define" then + z=0 + inh=0 + in=1 + exprs=string([z;inh]) + model=scicos_model() + model.sim=list("dollar4",4) + model.in=in + model.out=in + model.evtin=1-inh + model.dstate=z + model.blocktype="d" + model.dep_ut=[%f %f] + + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction + diff --git a/macros/Linear/GAINBLK.sci b/macros/Linear/GAINBLK.sci new file mode 100644 index 00000000..406e1b1f --- /dev/null +++ b/macros/Linear/GAINBLK.sci @@ -0,0 +1,175 @@ +// 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] = GAINBLK(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 then + exprs=[exprs;sci2exp(0)]; + end // compatibility + while %t do + [ok,gain,over,exprs]=scicos_getvalue("Set gain block parameters",.. + ["Gain";.. + "Do On Overflow(0=Nothing 1=Saturate 2=Error)"],.. + list("mat",[-1,-1],"vec",1),exprs) + if ~ok then + break, + end + if gain==[] then + message("Gain must have at least one element") + else + if typeof(gain)=="constant" then + if isreal(gain) then + it =1; + ot=1; + model.sim=list("gainblk",4); + model.rpar=gain(:); + model.opar=list(); + else + message("type is not supported"); + ok=%f; + end + else + if (over==0) then + if (typeof(gain)=="int32") then + ot=3 + model.sim=list("gainblk_i32n",4) + elseif (typeof(gain)=="int16") then + ot=4 + model.sim=list("gainblk_i16n",4) + elseif (typeof(gain)=="int8") then + ot=5 + model.sim=list("gainblk_i8n",4) + elseif (typeof(gain)=="uint32") then + ot=6 + model.sim=list("gainblk_ui32n",4) + elseif (typeof(gain)=="uint16") then + ot=7 + model.sim=list("gainblk_ui16n",4) + elseif (typeof(gain)=="uint8") then + ot=8 + model.sim=list("gainblk_ui8n",4) + else + message("type is not supported."); + ok=%f; + end + elseif (over==1) then + if (typeof(gain)=="int32") then + ot=3 + model.sim=list("gainblk_i32s",4) + elseif (typeof(gain)=="int16") then + ot=4 + model.sim=list("gainblk_i16s",4) + elseif (typeof(gain)=="int8") then + ot=5 + model.sim=list("gainblk_i8s",4) + elseif (typeof(gain)=="uint32") then + ot=6 + model.sim=list("gainblk_ui32s",4) + elseif (typeof(gain)=="uint16") then + ot=7 + model.sim=list("gainblk_ui16s",4) + elseif (typeof(gain)=="uint8") then + ot=8 + model.sim=list("gainblk_ui8s",4) + else + message("type is not supported."); + ok=%f; + end + elseif (over==2) then + if (typeof(gain)=="int32") then + ot=3 + model.sim=list("gainblk_i32e",4) + elseif (typeof(gain)=="int16") then + ot=4 + model.sim=list("gainblk_i16e",4) + elseif (typeof(gain)=="int8") then + ot=5 + model.sim=list("gainblk_i8e",4) + elseif (typeof(gain)=="uint32") then + ot=6 + model.sim=list("gainblk_ui32e",4) + elseif (typeof(gain)=="uint16") then + ot=7 + model.sim=list("gainblk_ui16e",4) + elseif (typeof(gain)=="uint8") then + ot=8 + model.sim=list("gainblk_ui8e",4) + else + message("type is not an integer."); + ok=%f; + end + else + message("Do on Overflow must be 0,1,2"); + ok=%f; + end + model.rpar=[]; + model.opar=list(gain(:)); + end + if ok then + [out,in]=size(gain) + if out*in<>1 then + [model,graphics,ok]=set_io(model,graphics,... + list([in,-1],ot),... + list([out,-1],ot),[],[]) + else + [model,graphics,ok]=set_io(model,graphics,... + list([-1,-2],ot),... + list([-1,-2],ot),[],[]) + end + end + if ok then + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + end + end + case "define" then + gain=1 + in=-1;out=-1 + in2=-2;out2=-2 + model=scicos_model() + model.sim=list("gainblk",4) + model.in=in + model.out=out + model.in2=in2 + model.out2=out2 + model.rpar=gain + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[strcat(sci2exp(gain))] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/GAINBLK_f.sci b/macros/Linear/GAINBLK_f.sci new file mode 100644 index 00000000..93d22dc2 --- /dev/null +++ b/macros/Linear/GAINBLK_f.sci @@ -0,0 +1,67 @@ +// 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]=GAINBLK_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,gain,exprs]=scicos_getvalue("Set gain block parameters",.. + ["Gain"],list("mat",[-1,-1]),exprs(1)) + if ~ok then + break, + end + if gain==[] then + message("Gain must have at least one element") + else + [out,in]=size(gain) + [model,graphics,ok]=check_io(model,graphics,in,out,[],[]) + if ok then + graphics.exprs=exprs + model.rpar=gain(:); + x.graphics=graphics; + x.model=model + break + end + end + end + case "define" then + gain=1 + in=1;out=1 + model=scicos_model() + model.sim="gain" + model.in=in + model.out=out + model.rpar=gain + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[strcat(sci2exp(gain))] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/GAIN_f.sci b/macros/Linear/GAIN_f.sci new file mode 100644 index 00000000..f44cc32a --- /dev/null +++ b/macros/Linear/GAIN_f.sci @@ -0,0 +1,67 @@ +// 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]=GAIN_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,gain,exprs]=scicos_getvalue("Set gain block parameters",.. + ["Gain"],list("mat",[-1,-1]),exprs(1)) + if ~ok then + break, + end + if gain==[] then + message("Gain must have at least one element") + else + [out,in]=size(gain) + [model,graphics,ok]=check_io(model,graphics,in,out,[],[]) + if ok then + graphics.exprs=exprs + model.rpar=gain(:); + x.graphics=graphics; + x.model=model + break + end + end + end + case "define" then + + gain=1;in=1;out=1; + model=scicos_model() + model.sim="gain" + model.in=1 + model.out=1 + model.rpar=gain + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[strcat(sci2exp(gain));strcat(sci2exp(in));strcat(sci2exp(out))] + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/INTEGRAL.sci b/macros/Linear/INTEGRAL.sci new file mode 100644 index 00000000..8bf1407a --- /dev/null +++ b/macros/Linear/INTEGRAL.sci @@ -0,0 +1,103 @@ +// 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]=INTEGRAL(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,reinit,satur,maxp,lowp,exprs]=scicos_getvalue("Set Integral block parameters",.. + ["Initial Condition"; + "With re-intialization (1:yes, 0:no)";"With saturation (1:yes, 0:no)"; + "Upper limit";"Lower limit"],.. + list("vec",-1,"vec",1,"vec",1,"vec",-1,"vec",-1),exprs) + if ~ok then + break, + end + x0=x0(:); + maxp=maxp(:), + lowp=lowp(:) + if reinit<>0 then + reinit=1; + end + if satur<>0 then + satur=1; + if size(maxp,"*")==1 then + maxp=maxp*ones(x0), + end + if size(lowp,"*")==1 then + lowp=lowp*ones(x0), + end + if (size(x0,1)<>size(maxp,1) | size(x0,1)<>size(lowp,1)) then + message("x0 and Upper limit and Lower limit must have same size") + ok=%f + elseif or(maxp<=lowp) then + message("Upper limits must be > Lower limits") + ok=%f + elseif or(x0>maxp)|or(x0<lowp) then + message("Initial condition x0 should be inside the limits") + ok=%f + else + rpar=[maxp;lowp] + model.nzcross=size(x0,1) + model.nmode=size(x0,1) + end + else + rpar=[] + model.nzcross=0 + model.nmode=0 + end + if ok then + model.rpar=rpar + model.state=x0 + [model,graphics,ok]=check_io(model,graphics,.. + size(x0,1)*[1;ones(reinit,1)],size(x0,1),ones(reinit,1),[]) + end + if ok then + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + maxp=1;minp=-1;rpar=[] + model=scicos_model() + model.state=0 + model.sim=list("integral_func",4) + model.in=1 + model.out=1 + model.rpar=rpar + model.blocktype="c" + model.dep_ut=[%f %t] + + exprs=string([0;0;0;maxp;minp]) + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + x.graphics.id="1/s" + end +endfunction diff --git a/macros/Linear/INTEGRAL_f.sci b/macros/Linear/INTEGRAL_f.sci new file mode 100644 index 00000000..16e1d950 --- /dev/null +++ b/macros/Linear/INTEGRAL_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]=INTEGRAL_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,exprs]=scicos_getvalue("Set continuous linear system parameters",.. + "Initial state",list("vec",1),exprs) + + + if ~ok then + break, + end + graphics.exprs=exprs; + model.state=x0; + x.graphics=graphics; + x.model=model + break + end + x.model.firing=[] //compatibility + case "define" then + x0=0 + model=scicos_model() + model.sim="integr" + model.in=1 + model.out=1 + model.state=x0 + model.blocktype="c" + model.dep_ut=[%f %t] + + exprs=strcat(sci2exp(x0)) + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/INTEGRAL_m.sci b/macros/Linear/INTEGRAL_m.sci new file mode 100644 index 00000000..6c70034c --- /dev/null +++ b/macros/Linear/INTEGRAL_m.sci @@ -0,0 +1,147 @@ +// 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] = INTEGRAL_m(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,reinit,satur,maxp,lowp,exprs]=scicos_getvalue("Set Integral block parameters",.. + ["Initial Condition"; + "With re-intialization (1:yes, 0:no)";"With saturation (1:yes, 0:no)"; + "Upper limit";"Lower limit"],.. + list("mat",[-1 -1],"vec",1,"vec",1,"mat",[-1 -1],"mat",[-1 -1]),exprs) + if ~ok then + break, + end + if isreal(x0) then + Datatype=1; + else + Datatype=2; + end; + if reinit<>0 then + reinit=1; + end + if satur<>0 then + satur=1; + if Datatype==1 then + if size(maxp,"*")==1 then + maxp=maxp*ones(x0), + end + if size(lowp,"*")==1 then + lowp=lowp*ones(x0), + end + if (size(x0)<>size(maxp) | size(x0)<>size(lowp)) then + message("x0 and Upper limit and Lower limit must have same size") + ok=%f + elseif or(maxp<=lowp) then + message("Upper limits must be > Lower limits") + ok=%f + elseif or(x0>maxp)|or(x0<lowp) then + message("Initial condition x0 should be inside the limits") + ok=%f + else + rpar=[real(maxp(:));real(lowp(:))] + model.nzcross=size(x0,"*") + model.nmode=size(x0,"*") + end + elseif (Datatype==2) then + if size(maxp,"*")==1 then + maxp=maxp*ones(x0)+%i*(maxp*ones(x0)), + end + if size(lowp,"*")==1 then + lowp=lowp*ones(x0)+%i*(lowp*ones(x0)), + end + if (size(x0)<>size(maxp) | size(x0)<>size(lowp)) then + message("x0 and Upper limit and Lower limit must have same size") + ok=%f + elseif or(real(maxp)<=real(lowp))| or(imag(maxp)<=imag(lowp)) then + message("Upper limits must be > Lower limits") + ok=%f + elseif or(real(x0)>real(maxp))|or(real(x0)<real(lowp))| or(imag(x0)>imag(maxp))|or(imag(x0)<imag(lowp)) then + message("Initial condition x0 should be inside the limits") + ok=%f + else + rpar=[real(maxp(:));real(lowp(:));imag(maxp(:));imag(lowp(:))] + model.nzcross=2*size(x0,"*") + model.nmode=2*size(x0,"*") + end + end + else + rpar=[] + model.nzcross=0 + model.nmode=0 + end + if ok then + model.rpar=rpar + if (Datatype==1) then + model.state=real(x0(:)) + model.sim=list("integral_func",4) + it=[1;ones(reinit,1)] + ot=1; + elseif (Datatype==2) then + model.state=[real(x0(:));imag(x0(:))]; + model.sim=list("integralz_func",4) + it=[2;2*ones(reinit,1)] + ot=2; + else + message("Datatype is not supported"); + ok=%f; + end + if ok then + in=[size(x0,1)*[1;ones(reinit,1)],size(x0,2)*[1;ones(reinit,1)]] + out=size(x0) + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),ones(reinit,1),[]) + end + end + if ok then + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + maxp=1; + minp=-1; + rpar=[] + model=scicos_model() + model.state=0 + model.sim=list("integral_func",4) + model.in=1 + model.out=1 + model.in2=1 + model.out2=1 + model.rpar=rpar + model.blocktype="c" + model.dep_ut=[%f %t] + + exprs=string([0;0;0;maxp;minp]) + gr_i=[] + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/PID.sci b/macros/Linear/PID.sci new file mode 100644 index 00000000..81f80100 --- /dev/null +++ b/macros/Linear/PID.sci @@ -0,0 +1,620 @@ +// 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]=PID(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + // look for the children blocks + ppath = list(0,0,0); + for i=1:length(arg1.model.rpar.objs) do + o = arg1.model.rpar.objs(i); + if typeof(o) == "Link" then + from = arg1.model.rpar.objs(o.from(1)); + to = arg1.model.rpar.objs(o.to(1)); + + if from.gui == "GAINBLK" then + select to.gui, + case "SUMMATION" then + ppath(1) = o.from(1), + case "INTEGRAL_m" then + ppath(2) = o.from(1), + case "DERIV" then + ppath(3) = o.from(1), + end + elseif to.gui == "GAINBLK" then + select from.gui, + case "SUMMATION" then + ppath(1) = o.to(1), + case "INTEGRAL_m" then + ppath(2) = o.to(1), + case "DERIV" then + ppath(3) = o.to(1), + end + end + + if and(ppath <> list(0,0,0)) then + break; + end + end + end + newpar=list(); + xx1=arg1.model.rpar.objs(ppath(1)) + exprs(1)=xx1.graphics.exprs(1) + p_old=xx1.model.rpar + xx2=arg1.model.rpar.objs(ppath(2)) + exprs(2)=xx2.graphics.exprs(1) + i_old=xx2.model.rpar + xx3=arg1.model.rpar.objs(ppath(3)) + exprs(3)=xx3.graphics.exprs(1) + d_old=xx3.model.rpar + y=0 + while %t do + [ok,p,i,d,exprs0]=scicos_getvalue("Set PID parameters",.. + ["Proportional";"Integral";"Derivation"],list("vec",-1,"vec",-1,"vec",-1),exprs) + if ~ok then + break, + end + if ok then + xx1.graphics.exprs=exprs0(1) + xx1.model.rpar=p + xx2.graphics.exprs=exprs0(2) + xx2.model.rpar=i + xx3.graphics.exprs=exprs0(3) + xx3.model.rpar=d + arg1.model.rpar.objs(ppath(1))=xx1 + arg1.model.rpar.objs(ppath(2))=xx2 + arg1.model.rpar.objs(ppath(3))=xx3 + break + end + end + needcompile=0 + if ~(p_old==p & i_old==i & d_old==d) then + newpar(size(newpar)+1)=ppath(1) + newpar(size(newpar)+1)=ppath(2) + newpar(size(newpar)+1)=ppath(3) + needcompile=2 + end + x=arg1 + y=max(y,needcompile) + typ=newpar + case "define" then + scs_m=scicos_diagram(.. + version="scicos4.2",.. + props=scicos_params(.. + wpar=[600,450,0,0,600,450],.. + Title=["PID"],.. + 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.objs(1)=scicos_block(.. + gui="INTEGRAL_m",.. + graphics=scicos_graphics(.. + orig=[318.304,183.11733],.. + sz=[40,40],.. + flip=%t,.. + theta=0,.. + exprs=["0";"0";"0";"1";"-1"],.. + pin=7,.. + pout=9,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="1/s",.. + in_implicit="E",.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("integral_func",4),.. + in=1,.. + in2=1,.. + intyp=1,.. + out=1,.. + out2=1,.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=0,.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%f,%t],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(2)=scicos_block(.. + gui="SUMMATION",.. + graphics=scicos_graphics(.. + orig=[387.97067,172.85067],.. + sz=[40,60],.. + flip=%t,.. + theta=0,.. + exprs=["1";"[1;1;1]"],.. + pin=[10;9;11],.. + pout=19,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit=["E";"E";"E"],.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("summation",4),.. + in=[-1;-1;-1],.. + in2=[-2;-2;-2],.. + intyp=[1;1;1],.. + out=-1,.. + out2=-2,.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[1;1;1],.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(3)=scicos_block(.. + gui="GAINBLK",.. + graphics=scicos_graphics(.. + orig=[321.23733,235.91733],.. + sz=[40,40],.. + flip=%t,.. + theta=0,.. + exprs="1",.. + pin=17,.. + pout=10,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("gainblk",4),.. + in=-1,.. + in2=-2,.. + intyp=1,.. + out=-1,.. + out2=-2,.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=1,.. + ipar=[],.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(4)=scicos_block(.. + gui="DERIV",.. + graphics=scicos_graphics(.. + orig=[319.03733,135.45067],.. + sz=[40,40],.. + flip=%t,.. + theta=0,.. + exprs=[],.. + pin=8,.. + pout=11,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="s",.. + in_implicit="E",.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("deriv",4),.. + in=-1,.. + in2=-2,.. + intyp=1,.. + out=-1,.. + out2=-2,.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(),.. + blocktype="x",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(5)=scicos_block(.. + gui="GAINBLK",.. + graphics=scicos_graphics(.. + orig=[255.23733,183.11733],.. + sz=[40,40],.. + flip=%t,.. + theta=0,.. + exprs="1",.. + pin=13,.. + pout=7,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("gainblk",4),.. + in=-1,.. + in2=-2,.. + intyp=1,.. + out=-1,.. + out2=-2,.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=1,.. + ipar=[],.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(6)=scicos_block(.. + gui="GAINBLK",.. + graphics=scicos_graphics(.. + orig=[255.23733,135.45067],.. + sz=[40,40],.. + flip=%t,.. + theta=0,.. + exprs="1",.. + pin=14,.. + pout=8,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit="E"),.. + model=scicos_model(.. + sim=list("gainblk",4),.. + in=-1,.. + in2=-2,.. + intyp=1,.. + out=-1,.. + out2=-2,.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=1,.. + ipar=[],.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(7)=scicos_link(.. + xx=[303.80876;309.73257],.. + yy=[203.11733;203.11733],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[5,1,0],.. + to=[1,1,1]) + scs_m.objs(8)=scicos_link(.. + xx=[303.80876;310.4659],.. + yy=[155.45067;155.45067],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[6,1,0],.. + to=[4,1,1]) + scs_m.objs(9)=scicos_link(.. + xx=[366.87543;379.39924],.. + yy=[203.11733;202.85067],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[1,1,0],.. + to=[2,2,1]) + scs_m.objs(10)=scicos_link(.. + xx=[369.80876;379.39924;379.39924],.. + yy=[255.91733;255.91733;217.85067],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[3,1,0],.. + to=[2,1,1]) + scs_m.objs(11)=scicos_link(.. + xx=[367.60876;379.39924;379.39924],.. + yy=[155.45067;155.45067;187.85067],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[4,1,0],.. + to=[2,3,1]) + scs_m.objs(12)=scicos_block(.. + gui="SPLIT_f",.. + graphics=scicos_graphics(.. + orig=[234.704;203.11733],.. + sz=[0.3333333,0.3333333],.. + flip=%t,.. + theta=0,.. + exprs=[],.. + pin=16,.. + pout=[13;14],.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit=["E";"E";"E"]),.. + model=scicos_model(.. + sim="lsplit",.. + in=-1,.. + in2=[],.. + intyp=1,.. + out=[-1;-1;-1],.. + out2=[],.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(13)=scicos_link(.. + xx=[234.704;246.6659],.. + yy=[203.11733;203.11733],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[12,1,0],.. + to=[5,1,1]) + scs_m.objs(14)=scicos_link(.. + xx=[234.704;234.704;246.6659],.. + yy=[203.11733;155.45067;155.45067],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[12,2,0],.. + to=[6,1,1]) + scs_m.objs(15)=scicos_block(.. + gui="SPLIT_f",.. + graphics=scicos_graphics(.. + orig=[233.97067;203.11733],.. + sz=[0.3333333,0.3333333],.. + flip=%t,.. + theta=0,.. + exprs=[],.. + pin=21,.. + pout=[16;17],.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit=["E";"E";"E"]),.. + model=scicos_model(.. + sim="lsplit",.. + in=-1,.. + in2=[],.. + intyp=1,.. + out=[-1;-1;-1],.. + out2=[],.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=[],.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%t,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(16)=scicos_link(.. + xx=[233.97067;234.704],.. + yy=[203.11733;203.11733],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[15,1,0],.. + to=[12,1,1]) + scs_m.objs(17)=scicos_link(.. + xx=[233.97067;233.97067;312.6659],.. + yy=[203.11733;255.91733;255.91733],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[15,2,0],.. + to=[3,1,1]) + scs_m.objs(18)=scicos_block(.. + gui="OUT_f",.. + graphics=scicos_graphics(.. + orig=[456.5421,192.85067],.. + sz=[20,20],.. + flip=%t,.. + theta=0,.. + exprs="1",.. + pin=19,.. + pout=[],.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit="E",.. + out_implicit=[]),.. + model=scicos_model(.. + sim="output",.. + in=-1,.. + in2=[],.. + intyp=-1,.. + out=[],.. + out2=[],.. + outtyp=1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=1,.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(19)=scicos_link(.. + xx=[436.5421;456.5421],.. + yy=[202.85067;202.85067],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[2,1,0],.. + to=[18,1,1]) + scs_m.objs(20)=scicos_block(.. + gui="IN_f",.. + graphics=scicos_graphics(.. + orig=[193.97067,193.11733],.. + sz=[20,20],.. + flip=%t,.. + theta=0,.. + exprs="1",.. + pin=[],.. + pout=21,.. + pein=[],.. + peout=[],.. + gr_i=[],.. + id="",.. + in_implicit=[],.. + out_implicit="E"),.. + model=scicos_model(.. + sim="input",.. + in=[],.. + in2=[],.. + intyp=1,.. + out=-1,.. + out2=[],.. + outtyp=-1,.. + evtin=[],.. + evtout=[],.. + state=[],.. + dstate=[],.. + odstate=list(),.. + rpar=[],.. + ipar=1,.. + opar=list(),.. + blocktype="c",.. + firing=[],.. + dep_ut=[%f,%f],.. + label="",.. + nzcross=0,.. + nmode=0,.. + equations=list()),.. + doc=list()) + scs_m.objs(21)=scicos_link(.. + xx=[213.97067;233.97067],.. + yy=[203.11733;203.11733],.. + id="drawlink",.. + thick=[0,0],.. + ct=[1,1],.. + from=[20,1,0],.. + to=[15,1,1]) + + model=scicos_model() + model.sim="csuper" + model.in=-1 + model.in2=-2 + model.out=-1 + model.out2=-2 + model.intyp=1 + model.outtyp=1 + model.blocktype="h" + model.firing=%f + model.dep_ut=[%f %f] + model.rpar=scs_m + + gr_i=[] + x=standard_define([2 2],model,[],gr_i) + end +endfunction diff --git a/macros/Linear/REGISTER.sci b/macros/Linear/REGISTER.sci new file mode 100644 index 00000000..1e637be3 --- /dev/null +++ b/macros/Linear/REGISTER.sci @@ -0,0 +1,105 @@ +// 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]=REGISTER(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)==1 then + exprs=[exprs;sci2exp(1)]; + end + while %t do + [ok,z0,it,exprs]=scicos_getvalue("Set delay parameters",.. + ["Register initial condition";.. + "Datatype (1=double 3=int32 ...)"],.. + list("vec",-1,"vec",1),exprs) + if ~ok then + break, + end + if prod(size(z0))<1 then + message("Register length must be at least 1") + ok=%f + end + if it==1 then + model.sim=list("delay4",4); + z0=double(z0); + model.dstate=z0; + model.odstate=list(); + else + if it==3 then + model.sim=list("delay4_i32",4) + z0=int32(z0) + elseif it==4 then + model.sim=list("delay4_i16",4) + z0=int16(z0) + elseif it==5 then + model.sim=list("delay4_i8",4) + z0=int8(z0) + elseif it==6 then + model.sim=list("delay4_ui32",4) + z0=uint32(z0) + elseif it==7 then + model.sim=list("delay4_ui16",4) + z0=uint16(z0) + elseif it==8 then + model.sim=list("delay4_ui8",4) + z0=uint8(z0) + else + message("Datatype is not supported"); + ok=%f + end + model.odstate=list(z0); + model.dstate=[] + end + if ok then + in=[1 1] + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(in,it),1,[]) + end + if ok then + graphics.exprs=exprs; + x.graphics=graphics; + x.model=model + break + end + end + + case "define" then + z0=zeros(10,1) + model=scicos_model() + model.sim=list("delay4",4) + model.in=1 + model.out=1 + model.evtin=1 + model.dstate=z0 + model.blocktype="d" + model.dep_ut=[%f %f] + + exprs=strcat(string(z0), ";") + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/REGISTER_f.sci b/macros/Linear/REGISTER_f.sci new file mode 100644 index 00000000..c615b7fc --- /dev/null +++ b/macros/Linear/REGISTER_f.sci @@ -0,0 +1,66 @@ +// 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]=REGISTER_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,z0,exprs]=scicos_getvalue("Set delay parameters",.. + "Register initial condition",list("vec",-1),exprs) + if ~ok then + break, + end + if prod(size(z0))<1 then + message("Register length must be at least 1") + ok=%f + end + if ok then + graphics.exprs=exprs; + model.dstate=z0 + x.graphics=graphics; + x.model=model + break + end + end + + case "define" then + z0=zeros(10,1) + model=scicos_model() + model.sim="delay" + model.in=1 + model.out=1 + model.evtin=1 + model.dstate=z0 + model.blocktype="d" + model.dep_ut=[%f %f] + + exprs=strcat(string(z0),";") + gr_i=[] + x=standard_define([2.5 2.5],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/SAMPHOLD.sci b/macros/Linear/SAMPHOLD.sci new file mode 100644 index 00000000..aa423a3a --- /dev/null +++ b/macros/Linear/SAMPHOLD.sci @@ -0,0 +1,43 @@ +// 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]=SAMPHOLD(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + x.model.firing=[] //compatibility + case "define" then + in=-1 + model=scicos_model() + model.sim=list("samphold4",4) + model.in=-1 + model.out=-1 + model.evtin=1 + model.blocktype="d" + model.dep_ut=[%t %f] + + gr_i=[] + x=standard_define([2 2],model," ",gr_i) + end +endfunction diff --git a/macros/Linear/SAMPHOLD_m.sci b/macros/Linear/SAMPHOLD_m.sci new file mode 100644 index 00000000..1bd37ae3 --- /dev/null +++ b/macros/Linear/SAMPHOLD_m.sci @@ -0,0 +1,71 @@ +// 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]=SAMPHOLD_m(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + x.model.firing=[] //compatibility + graphics=arg1.graphics; + label=graphics.exprs + model=arg1.model; + while %t do + [ok,it,exprs]=scicos_getvalue("Set parameters Block",.. + ["Datatype(1=real double 2=Complex 3=int32 ...)"],list("vec",1),label) + if ~ok then + break, + end + if ((it<1)|(it>8)) then + message ("Datatype is not supported"); + ok=%f; + end + if ok then + in=[model.in model.in2]; + [model,graphics,ok]=set_io(model,graphics,list(in,it),list(in,it),1,[]) + if ok then + graphics.exprs=exprs; + arg1.graphics=graphics; + arg1.model=model; + x=arg1 + break + end + end + end + case "define" then + model=scicos_model() + model.sim=list("samphold4_m",4) + model.in=-1 + model.in2=-2 + model.intyp=1 + model.outtyp=1 + model.out=-1 + model.out2=-2 + model.evtin=1 + model.blocktype="d" + model.dep_ut=[%t %f] + label=[sci2exp(1)]; + gr_i=[] + x=standard_define([2 2],model,label,gr_i) + end +endfunction diff --git a/macros/Linear/SAMPLEHOLD_f.sci b/macros/Linear/SAMPLEHOLD_f.sci new file mode 100644 index 00000000..10fd9bef --- /dev/null +++ b/macros/Linear/SAMPLEHOLD_f.sci @@ -0,0 +1,43 @@ +// 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]=SAMPLEHOLD_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + x.model.firing=[] //compatibility + case "define" then + in=-1 + model=scicos_model() + model.sim="samphold" + model.in=-1 + model.out=-1 + model.evtin=1 + model.blocktype="d" + model.dep_ut=[%t %f] + + gr_i=[] + x=standard_define([2 2],model," ",gr_i) + end +endfunction diff --git a/macros/Linear/SOM_f.sci b/macros/Linear/SOM_f.sci new file mode 100644 index 00000000..4b9004fe --- /dev/null +++ b/macros/Linear/SOM_f.sci @@ -0,0 +1,72 @@ +// 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]=SOM_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + p=1 //pixel sizes ratio + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + model=arg1.model; + exprs=graphics.exprs + if size(exprs,"*")==2 then + exprs=exprs(2), + end + if size(exprs,"*")<>3 then + exprs=string(model.rpar), + end + if graphics.flip then + labs=["down","left","up"] + else + labs=["down","right","up"] + end + + str = ["This sum block is obsolete" + "parameters cannot be modified. Please replace it with new sum block"; + "and gain blocks in the linear palette" + " " + "Input ports are located at up, side and down positions." + "Current gains are:"]; + + str = [str ; (part(labs(:),1:7)+exprs(:))]; + message(str); + + case "define" then + sgn=[1;1;1] + + model=scicos_model() + model.sim=list("sum",2) + model.in=[-1;-1;-1] + model.out=-1 + model.rpar=sgn + model.blocktype="c" + model.dep_ut=[%t %f] + + exprs=[sci2exp(1);sci2exp(sgn)] + + gr_i=[] + + x=standard_define([2 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/SUMMATION.sci b/macros/Linear/SUMMATION.sci new file mode 100644 index 00000000..f70c7882 --- /dev/null +++ b/macros/Linear/SUMMATION.sci @@ -0,0 +1,159 @@ +// 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]=SUMMATION(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics + model=arg1.model + exprs=graphics.exprs + if size(exprs,1)==1 then + exprs=[sci2exp(1);exprs;sci2exp(0)]; + elseif size(exprs,1)==2 then + exprs=[exprs;sci2exp(0)]; + end + while %t do + [ok,Datatype,sgn,satur,exprs]=scicos_getvalue("Set sum block parameters",.. + ["Datatype (1=real double 2=complex 3=int32 ...)";.. + "Number of inputs or sign vector (of +1, -1)";.. + "Do on Overflow(0=Nothing 1=Saturate 2=Error)"],.. + list("vec",1,"vec",-1,"vec",1),exprs) + if ~ok then + break, + end + sgn=sgn(:); + if (satur~=0&satur~=1&satur~=2) then + message("Do on overflow must be 0,1,2"); + ok=%f; + end + if size(sgn,1)==1 then + if sgn<1 then + message("Number of inputs must be > 0") + ok=%f + elseif sgn==1 then + in=-1;in2=-2 + sgn=[] + nout=1;nout2=1 + else + in=-ones(sgn,1); + in2=2*in + sgn=ones(sgn,1) + nout=-1;nout2=-2 + end + else + if ~and(abs(sgn)==1) then + message("Signs can only be +1 or -1") + ok=%f + else + in=-ones(size(sgn,1),1); + in2=2*in + nout=-1;nout2=-2 + end + end + it=Datatype*ones(1,size(in,1)); + ot=Datatype; + if Datatype==1 then + model.sim=list("summation",4) + elseif Datatype==2 then + model.sim=list("summation_z",4) + elseif ((Datatype<1) |(Datatype>8)) then + message("Datatype is not supported");ok=%f; + else + if satur==0 then + if Datatype==3 then + model.sim=list("summation_i32n",4) + elseif Datatype==4 then + model.sim=list("summation_i16n",4) + elseif Datatype==5 then + model.sim=list("summation_i8n",4) + elseif Datatype==6 then + model.sim=list("summation_ui32n",4) + elseif Datatype==7 then + model.sim=list("summation_ui16n",4) + elseif Datatype==8 then + model.sim=list("summation_ui8n",4) + end + elseif satur==1 then + if Datatype==3 then + model.sim=list("summation_i32s",4) + elseif Datatype==4 then + model.sim=list("summation_i16s",4) + elseif Datatype==5 then + model.sim=list("summation_i8s",4) + elseif Datatype==6 then + model.sim=list("summation_ui32s",4) + elseif Datatype==7 then + model.sim=list("summation_ui16s",4) + elseif Datatype==8 then + model.sim=list("summation_ui8s",4) + end + elseif satur==2 then + if Datatype==3 then + model.sim=list("summation_i32e",4) + elseif Datatype==4 then + model.sim=list("summation_i16e",4) + elseif Datatype==5 then + model.sim=list("summation_i8e",4) + elseif Datatype==6 then + model.sim=list("summation_ui32e",4) + elseif Datatype==7 then + model.sim=list("summation_ui16e",4) + elseif Datatype==8 then + model.sim=list("summation_ui8e",4) + end + end + end + if ok then + [model,graphics,ok]=set_io(model,graphics,... + list([in,in2],it),... + list([nout,nout2],ot),[],[]) + end + if ok then + model.rpar=satur; + model.ipar=sgn + graphics.exprs=exprs + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + sgn=[1;-1] + model=scicos_model() + model.sim=list("summation",4) + model.in=[-1;-1] + model.out=-1 + model.in2=[-2;-2] + model.out2=-2 + model.ipar=sgn + model.blocktype="c" + model.dep_ut=[%t %f] + + + exprs=sci2exp(sgn) + gr_i=[] + x=standard_define([2 3],model, exprs,gr_i) + end +endfunction diff --git a/macros/Linear/SUM_f.sci b/macros/Linear/SUM_f.sci new file mode 100644 index 00000000..40868bc9 --- /dev/null +++ b/macros/Linear/SUM_f.sci @@ -0,0 +1,42 @@ +// 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]=SUM_f(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + p=1 //pixel sizes ratio + select job + case "set" then + x=arg1; + case "define" then + model=scicos_model() + model.sim=list("plusblk",2) + model.in=[-1;-1;-1] + model.out=-1 + model.blocktype="c" + model.dep_ut=[%t %f] + + gr_i=[] + exprs=[] + x=standard_define([1 1],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/TCLSS.sci b/macros/Linear/TCLSS.sci new file mode 100644 index 00000000..7040b6ed --- /dev/null +++ b/macros/Linear/TCLSS.sci @@ -0,0 +1,115 @@ +// 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]=TCLSS(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,"*")==7 then + exprs=exprs([1:4,7]), + end //compatibility + while %t do + [ok,A,B,C,D,x0,exprs]=scicos_getvalue("Set continuous linear system parameters",.. + ["A matrix"; + "B matrix"; + "C matrix"; + "D matrix"; + "Initial state"],.. + list("mat",[-1,-1],.. + "mat",["size(%1,2)","-1"],.. + "mat",["-1","size(%1,2)"],.. + "mat",[-1 -1],.. + "vec","size(%1,2)"),.. + exprs) + if ~ok then + break, + end + out=size(C,1); + if out==0 then + out=[], + end + in=size(B,2); + if in==0 then + in=[], + end + [ms,ns]=size(A) + if ms<>ns then + message("A matrix must be square") + else + [model,graphics,ok]=check_io(model,graphics,[in;ms],out,1,[]) + if ok then + graphics.exprs=exprs; + rpar=[A(:);B(:);C(:);D(:)]; + if D<>[] then + if norm(D,1)<>0 then + mmm=[%t %t]; + else + mmm=[%f %t]; + end + if or(model.dep_ut<>mmm) then + model.dep_ut=mmm, + end + else + model.dep_ut=[%f %t]; + end + model.state=x0(:);model.rpar=rpar; + if D<>[] then + model.sim=list("tcslti4",4) + else + model.sim=list("tcsltj4",4); + end + x.graphics=graphics; + x.model=model + break + end + end + end + case "define" then + x0=0;A=0;B=1;C=1;D=0; + in=1; + nx=size(x0,"*") + out=1 + + model=scicos_model() + model.sim=list("tcslti4",4) + model.in=[in;nx] + model.out=out + model.evtin=1 + model.state=x0 + model.rpar=[A(:);B(:);C(:);D(:)] + model.blocktype="c" + model.dep_ut=[%f %t] + + exprs=[strcat(sci2exp(A)); + strcat(sci2exp(B)); + strcat(sci2exp(C)); + strcat(sci2exp(D)); + strcat(sci2exp(x0))] + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/TCLSS_f.sci b/macros/Linear/TCLSS_f.sci new file mode 100644 index 00000000..8804969c --- /dev/null +++ b/macros/Linear/TCLSS_f.sci @@ -0,0 +1,115 @@ +// 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]=TCLSS_f(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,"*")==7 then + exprs=exprs([1:4,7]), + end //compatibility + while %t do + [ok,A,B,C,D,x0,exprs]=scicos_getvalue("Set continuous linear system parameters",.. + ["A matrix"; + "B matrix"; + "C matrix"; + "D matrix"; + "Initial state"],.. + list("mat",[-1,-1],.. + "mat",["size(%1,2)","-1"],.. + "mat",["-1","size(%1,2)"],.. + "mat",[-1 -1],.. + "vec","size(%1,2)"),.. + exprs) + if ~ok then + break, + end + out=size(C,1); + if out==0 then + out=[], + end + in=size(B,2); + if in==0 then + in=[], + end + [ms,ns]=size(A) + if ms<>ns then + message("A matrix must be square") + else + [model,graphics,ok]=check_io(model,graphics,[in;ms],out,1,[]) + if ok then + graphics.exprs=exprs; + rpar=[A(:);B(:);C(:);D(:)]; + if D<>[] then + if norm(D,1)<>0 then + mmm=[%t %t]; + else + mmm=[%f %t]; + end + if or(model.dep_ut<>mmm) then + model.dep_ut=mmm, + end + else + model.dep_ut=[%f %t]; + end + model.state=x0(:);model.rpar=rpar; + if D<>[] then + model.sim=list("tcslti",1) + else + model.sim=list("tcsltj",1); + end + x.graphics=graphics; + x.model=model + break + end + end + end + case "define" then + x0=0;A=0;B=1;C=1;D=0; + in=1; + nx=size(x0,"*") + out=1 + + model=scicos_model() + model.sim=list("tcslti",1) + model.in=[in;nx] + model.out=out + model.evtin=1 + model.state=x0 + model.rpar=[A(:);B(:);C(:);D(:)] + model.blocktype="c" + model.dep_ut=[%f %t] + + exprs=[strcat(sci2exp(A)); + strcat(sci2exp(B)); + strcat(sci2exp(C)); + strcat(sci2exp(D)); + strcat(sci2exp(x0))] + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/TIME_DELAY.sci b/macros/Linear/TIME_DELAY.sci new file mode 100644 index 00000000..4ef254b9 --- /dev/null +++ b/macros/Linear/TIME_DELAY.sci @@ -0,0 +1,86 @@ +// 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]=TIME_DELAY(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model; + nin=model.in(1) + + while %t do + [ok,T,init,N,exprs]=scicos_getvalue("Set delay parameters",.. + ["Delay";"initial input";"Buffer size"],.. + list("vec",1,"vec",1,"vec",1),.. + exprs); + if ~ok then + break, + end + if N<2 then + message("Buffer must be larger than 2") + ok=%f + end + if T<=0 then + message("Delay must be positive") + ok=%f + end + + if ok then + [model,graphics,ok]=check_io(model,graphics,[-1],-1,[],[]) + end + if ok then + graphics.exprs=exprs; + model.rpar=[T;init]; + model.ipar=N + + model.dep_ut=[%f %t]; + // dp_t = %t + // updated for Scilab 5.5.1 + // see http://bugzilla.scilab.org/show_bug.cgi?id=13436 + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + nin=1 + T=1 + init=0 + N=1024 + model=scicos_model() + model.sim=list("time_delay",4) + model.in=[nin] + model.out=nin + model.rpar=[T,init]; + model.ipar=N + model.blocktype="x" + model.dep_ut=[%f %t] + + exprs=[string(T);string(init);string(N)]; + gr_i=[] + x=standard_define([3.5 2],model,exprs,gr_i) + end +endfunction diff --git a/macros/Linear/VARIABLE_DELAY.sci b/macros/Linear/VARIABLE_DELAY.sci new file mode 100644 index 00000000..c8055352 --- /dev/null +++ b/macros/Linear/VARIABLE_DELAY.sci @@ -0,0 +1,80 @@ +// 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]=VARIABLE_DELAY(job,arg1,arg2) + x=[]; + y=[]; + typ=[]; + select job + case "set" then + x=arg1; + graphics=arg1.graphics; + exprs=graphics.exprs + model=arg1.model;nin=model.in(1) + + while %t do + [ok,T,init,N,exprs]=scicos_getvalue("Set delay parameters",.. + ["Max delay";"initial input";"Buffer size"],.. + list("vec",1,"vec",1,"vec",1),.. + exprs); + if ~ok then + break, + end + if N<2 then + message("Buffer must be larger than 2") + ok=%f + end + if T<=0 then + message("Delay must be positive") + ok=%f + end + + if ok then + [model,graphics,ok]=check_io(model,graphics,[-1;1],-1,[],[]) + end + if ok then + graphics.exprs=exprs; + model.rpar=[T;init]; + model.ipar=N + x.graphics=graphics; + x.model=model + break + end + end + case "define" then + nin=1 + T=1 + init=0 + N=1024 + model=scicos_model() + model.sim=list("variable_delay",4) + model.in=[nin;1] + model.out=nin + model.rpar=[T,init]; + model.ipar=N + model.blocktype="d" + model.dep_ut=[%f %f] + + exprs=[string(T);string(init);string(N)]; + gr_i=[] + x=standard_define([3 2],model,exprs,gr_i) + end +endfunction |